fix(protocol): handle empty group essence lists

Return an empty result when a successful, completed group essence response omits its message list instead of reporting a malformed response.

Keep upstream errors and incomplete pagination responses explicit, and cover omitted and null list variants with regression tests.

Fixes #320.
This commit is contained in:
DrSmoothl committed 2026-08-06 22:36:05 +08:00
1 parent 27c527976b
commit c0e73cd738
2 files changed
+53 -4

No files matched your search

@@ -45,10 +45,26 @@ describe('group essence pagination', () => {
.rejects.toThrow(/retcode 100.*permission denied/);
});
it('rejects a success response without a message list', async () => {
it.each([
['an omitted list', { is_end: true }],
['a null list', { is_end: true, msg_list: null }],
])('normalizes an ended success response with %s to an empty page', async (_case, data) => {
const request = vi.spyOn(RequestUtil, 'HttpGetJson').mockResolvedValue({
retcode: 0,
data,
} as never);
await expect(getGroupEssenceMsgAll(cookie, '123456789')).resolves.toEqual([{
retcode: 0,
data: { is_end: true, msg_list: [] },
}]);
expect(request).toHaveBeenCalledOnce();
});
it('rejects a missing message list before the response explicitly ends', async () => {
vi.spyOn(RequestUtil, 'HttpGetJson').mockResolvedValue({
retcode: 0,
data: { is_end: true },
data: { is_end: false },
} as never);
await expect(getGroupEssenceMsgAll(cookie, '123456789'))