fix(core): handle omitted group album success codes
Treat an absent media-list return code as the protobuf zero default while preserving failures for explicit non-zero codes. Add a regression test that exercises the encoded response path with media data and no status field. Refs #234
This commit is contained in:
2 files changed
+44
-2
No files matched your search
@@ -80,8 +80,9 @@ export class GroupAlbumApi {
|
|||||||
|
|
||||||
const resp = protobuf_decode<GetMediaListResponse>(result.responseData);
|
const resp = protobuf_decode<GetMediaListResponse>(result.responseData);
|
||||||
|
|
||||||
if (resp.field1 !== 0) {
|
const retCode = resp.field1 ?? 0;
|
||||||
throw new Error(`fetch album media list error: retCode ${resp.field1 ?? 'unknown'}`);
|
if (retCode !== 0) {
|
||||||
|
throw new Error(`fetch album media list error: retCode ${retCode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = resp.data ?? {};
|
const data = resp.data ?? {};
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import type { GetMediaListResponse } from '@snowluma/proto-defs/oidb-actions/group-album';
|
||||||
|
import { protobuf_encode } from '@snowluma/proton';
|
||||||
|
import { GroupAlbumApi } from '../../src/bridge/apis/group-album';
|
||||||
|
import { mockBridge } from './_helpers';
|
||||||
|
|
||||||
|
describe('apis/group-album', () => {
|
||||||
|
it('accepts a successful media-list response with an omitted zero retCode', async () => {
|
||||||
|
const bridge = mockBridge();
|
||||||
|
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||||
|
success: true,
|
||||||
|
gotResponse: true,
|
||||||
|
errorCode: 0,
|
||||||
|
errorMessage: '',
|
||||||
|
responseData: Buffer.from(protobuf_encode<GetMediaListResponse>({
|
||||||
|
data: {
|
||||||
|
mediaList: [{
|
||||||
|
type: 1,
|
||||||
|
uploader: '10001',
|
||||||
|
batchId: 123n,
|
||||||
|
uploadTime: 456n,
|
||||||
|
}],
|
||||||
|
nextAttachInfo: 'next-page',
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await new GroupAlbumApi(bridge as never).getMediaList(12345, 'album-id');
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
mediaList: [{
|
||||||
|
type: 1,
|
||||||
|
image: null,
|
||||||
|
uploader: '10001',
|
||||||
|
batchId: '123',
|
||||||
|
uploadTime: '456',
|
||||||
|
}],
|
||||||
|
nextAttachInfo: 'next-page',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user