bridge-oidb.ts used to expose three thin functions —
makeOidbRequest / sendOidbAndCheck / sendOidbAndDecode — and every
action file repeated the same five-step envelope assembly with long
positional argument lists. Collapse them into one `runOidb(bridge,
call)` taking an OidbCall object: cmd / oidbCmd / subCmd / request
{ schema, value, isUid? } / response? { schema }.
Behavioural contract is preserved:
- No `response`: verify success + gotResponse, peek envelope retCode
iff response data is present (fire-and-check semantics).
- With `response`: require responseData, decode through the base
schema, validate retCode, return the inner body typed as TResp.
Migration touches 51 call sites across 9 source files (bridge-contacts,
actions/{group-file, group-admin, profile, group-message, friend,
interaction, misc}, web-actions/cookies) plus 9 test files that used
to assert on positional `.mock.calls[0]![4]` indices and now read
through `.mock.calls[0]![1].request.value` / `.cmd` / `.oidbCmd`.
Net effect: callers now name what each piece is for, and adding
cross-cutting OIDB behaviour (retry / timeout / per-cmd logging) is a
single-site change inside runOidb instead of a sweep across 9 files.
66 lines
2.5 KiB
TypeScript
66 lines
2.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
|
runOidb: vi.fn(async () => ({})),
|
|
}));
|
|
|
|
import * as oidb from '../../src/bridge/bridge-oidb';
|
|
import * as msg from '../../src/bridge/actions/group-message';
|
|
import { mockBridge } from './_helpers';
|
|
|
|
describe('actions/group-message', () => {
|
|
beforeEach(() => {
|
|
vi.mocked(oidb.runOidb).mockClear();
|
|
});
|
|
|
|
it('recallGroupMessage sends to SsoGroupRecallMsg with the group sequence', async () => {
|
|
const bridge = mockBridge();
|
|
await msg.recallGroupMessage(bridge as any, 12345, 999);
|
|
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
|
|
const [serviceCmd] = bridge.sendRawPacket.mock.calls[0]!;
|
|
expect(serviceCmd).toBe('trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg');
|
|
});
|
|
|
|
it('recallGroupMessage throws when sendRawPacket reports failure', async () => {
|
|
const bridge = mockBridge({
|
|
sendRawPacket: vi.fn(async () => ({
|
|
success: false,
|
|
gotResponse: false,
|
|
errorCode: -1,
|
|
errorMessage: 'network down',
|
|
responseData: null,
|
|
})) as any,
|
|
});
|
|
await expect(msg.recallGroupMessage(bridge as any, 12345, 999))
|
|
.rejects.toThrow(/network down/);
|
|
});
|
|
|
|
it('recallPrivateMessage resolves the target UID before dispatch', async () => {
|
|
const bridge = mockBridge();
|
|
await msg.recallPrivateMessage(bridge as any, 10001, 100, 200, 123, 1700000000);
|
|
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
|
const [serviceCmd] = bridge.sendRawPacket.mock.calls[0]!;
|
|
expect(serviceCmd).toBe('trpc.msg.msg_svc.MsgService.SsoC2CRecallMsg');
|
|
});
|
|
|
|
it('markGroupMessageRead and markPrivateMessageRead both hit SsoReadedReport', async () => {
|
|
const bridge = mockBridge();
|
|
await msg.markGroupMessageRead(bridge as any, 12345, 50);
|
|
await msg.markPrivateMessageRead(bridge as any, 10001, 60);
|
|
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
|
|
const cmds = bridge.sendRawPacket.mock.calls.map((c: any) => c[0]);
|
|
expect(cmds).toEqual([
|
|
'trpc.msg.msg_svc.MsgService.SsoReadedReport',
|
|
'trpc.msg.msg_svc.MsgService.SsoReadedReport',
|
|
]);
|
|
});
|
|
|
|
it('setGroupEssence picks _1 for enable and _2 for disable', async () => {
|
|
const bridge = mockBridge();
|
|
await msg.setGroupEssence(bridge as any, 12345, 5, 7, true);
|
|
await msg.setGroupEssence(bridge as any, 12345, 5, 7, false);
|
|
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1].cmd);
|
|
expect(cmds).toEqual(['OidbSvcTrpcTcp.0xeac_1', 'OidbSvcTrpcTcp.0xeac_2']);
|
|
});
|
|
});
|