Splits the 16 OIDB cmds from GroupFileApi into self-contained
namespaces under @snowluma/bridge/oidb-services/group-file/. Adds
@snowluma/bridge/oidb-services/shared with `toInt` / `ensureRetCodeZero`
helpers so namespaces can validate sub-responses without an
@snowluma/core dependency.
Boundaries:
- Single-OIDB methods (publish / getCount / list-page / *url /
delete / move / *folder) become one-line forwarders.
- 3-stage methods (`upload` / `uploadPrivate`) keep their
orchestration on the facade — OIDB preflight goes through the
new namespace, but highway PUT + publish/sendC2cFile + upload-
cache bookkeeping stay where they are.
- `list` keeps its pagination loop on the facade; the page-fetch
namespace is one call.
- The NTV2-rich-media URL fetchers (group/private × ptt/video)
share a deserialize helper (`parseNtv2DownloadUrl`) so all four
namespaces only differ in their scene block.
Wire-byte equivalence preserved. The 0x6D6 family shares one
OidbGroupFileReq envelope; each namespace populates a different
slot (file / download / delete / move) and proton monomorphizes
per call site as before.
46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
import type {
|
|
OidbGroupFileCountViewReq, OidbGroupFileCountViewResp,
|
|
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
|
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
|
|
|
import { GetGroupFileCount } from '../../../src/oidb-services/group-file/get-group-file-count';
|
|
|
|
function makeDeps(body?: OidbGroupFileCountViewResp) {
|
|
const responseData = body !== undefined
|
|
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileCountViewResp>>({ body }))
|
|
: Buffer.alloc(0);
|
|
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
|
return { sendRawPacket: vi.fn(async () => r) };
|
|
}
|
|
|
|
describe('GetGroupFileCount namespace', () => {
|
|
it('declares 0x6D8_3', () => {
|
|
expect(GetGroupFileCount.command).toBe(0x6D8);
|
|
expect(GetGroupFileCount.subCommand).toBe(3);
|
|
});
|
|
|
|
it('routes to 0x6d8_3 with groupUin + appId=7 + busId=0', async () => {
|
|
const deps = makeDeps({ count: { fileCount: 1, maxCount: 100 } });
|
|
await GetGroupFileCount.invoke(deps, { groupId: 12345 });
|
|
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
|
expect(wire).toBe('OidbSvcTrpcTcp.0x6d8_3');
|
|
const env = protobuf_decode<OidbBase<OidbGroupFileCountViewReq>>(bytes);
|
|
expect(env.body?.count).toMatchObject({ groupUin: 12345, appId: 7 });
|
|
});
|
|
|
|
it('decodes both counters as plain numbers', async () => {
|
|
const deps = makeDeps({ count: { fileCount: 42, maxCount: 1000 } });
|
|
const out = await GetGroupFileCount.invoke(deps, { groupId: 1 });
|
|
expect(out).toEqual({ fileCount: 42, maxCount: 1000 });
|
|
});
|
|
|
|
it('falls back to maxCount=10000 when the server elides it', async () => {
|
|
const deps = makeDeps({ count: {} });
|
|
const out = await GetGroupFileCount.invoke(deps, { groupId: 1 });
|
|
expect(out).toEqual({ fileCount: 0, maxCount: 10000 });
|
|
});
|
|
});
|