Translate group essence responses into the established OneBot shape instead of exposing the upstream digest payload. Return validated sender, operator, timestamp, message identifier, and message segment fields for text, face, image, and video entries. Retain the authoritative message metadata in one transaction so returned identifiers can be used by later essence actions without partial cache state. Reject malformed, cross-group, incomplete, or unknown digest entries, and surface pagination or upstream failures instead of returning truncated success results. Fixes #300.
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import {
|
|
getGroupEssenceMsgAll,
|
|
type GroupEssenceMsgRet,
|
|
} from '@snowluma/protocol/web/group-essence';
|
|
import { RequestUtil } from '@snowluma/protocol/web/request-util';
|
|
|
|
const cookie = { skey: 'test-skey' };
|
|
|
|
function page(isEnd: boolean): GroupEssenceMsgRet {
|
|
return {
|
|
retcode: 0,
|
|
data: {
|
|
is_end: isEnd,
|
|
msg_list: [],
|
|
},
|
|
};
|
|
}
|
|
|
|
describe('group essence pagination', () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it('rejects instead of returning a partial list when a later page fails', async () => {
|
|
vi.spyOn(RequestUtil, 'HttpGetJson')
|
|
.mockResolvedValueOnce(page(false) as never)
|
|
.mockRejectedValueOnce(new Error('socket closed'));
|
|
|
|
await expect(getGroupEssenceMsgAll(cookie, '123456789'))
|
|
.rejects.toThrow('socket closed');
|
|
});
|
|
|
|
it('surfaces a non-zero QQ response code', async () => {
|
|
vi.spyOn(RequestUtil, 'HttpGetJson').mockResolvedValue({
|
|
retcode: 100,
|
|
retmsg: 'permission denied',
|
|
data: {
|
|
is_end: true,
|
|
msg_list: [],
|
|
},
|
|
} satisfies GroupEssenceMsgRet as never);
|
|
|
|
await expect(getGroupEssenceMsgAll(cookie, '123456789'))
|
|
.rejects.toThrow(/retcode 100.*permission denied/);
|
|
});
|
|
|
|
it('rejects a success response without a message list', async () => {
|
|
vi.spyOn(RequestUtil, 'HttpGetJson').mockResolvedValue({
|
|
retcode: 0,
|
|
data: { is_end: true },
|
|
} as never);
|
|
|
|
await expect(getGroupEssenceMsgAll(cookie, '123456789'))
|
|
.rejects.toThrow(/invalid group essence response.*msg_list/);
|
|
});
|
|
|
|
it('fails when the configured page limit cannot reach the end', async () => {
|
|
vi.spyOn(RequestUtil, 'HttpGetJson').mockResolvedValue(page(false) as never);
|
|
|
|
await expect(getGroupEssenceMsgAll(cookie, '123456789'))
|
|
.rejects.toThrow(/pagination exceeded 20 pages/);
|
|
});
|
|
});
|