Files
SnowLuma/packages/core/tests/actions/group-album.test.ts
T
DrSmoothl 6492500158 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
2026-07-15 17:30:29 +08:00

42 lines
1.2 KiB
TypeScript

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',
});
});
});