refactor(protocol): send leftover OIDB envelopes through the shared caller
Moving a friend who is already in the target category still succeeds. Media upload preflight now uses the same envelope success and error rules as other OIDB calls.
This commit is contained in:
12 files changed
+251
-175
No files matched your search
@@ -231,6 +231,33 @@ describe('invokeOidb', () => {
|
||||
const env = protobuf_decode<OidbBase<OidbGroupReaction>>(bytes);
|
||||
expect(env.reserved ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('treats registered envelope codes as success on the packet and body', async () => {
|
||||
const spec = { ...staticSubSpec, acceptedEnvelopeCodes: [2_001_002] };
|
||||
const bodyBytes = protobuf_encode<OidbBase<OidbEmpty>>({
|
||||
command: 0xEAC, subCommand: 1, errorCode: 2_001_002, errorMsg: 'already applied',
|
||||
});
|
||||
await expect(invokeOidb(makeSender({ responseData: Buffer.from(bodyBytes) }), spec, { groupId: 1 }))
|
||||
.resolves.toBeUndefined();
|
||||
await expect(invokeOidb(makeSender({
|
||||
success: false,
|
||||
errorCode: 2_001_002,
|
||||
errorMessage: 'already applied',
|
||||
responseData: null,
|
||||
}), spec, { groupId: 1 })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('uses resolveCommand for the wire name and envelope command', async () => {
|
||||
const spec = {
|
||||
...staticSubSpec,
|
||||
command: 0,
|
||||
resolveCommand: () => 0x11C5,
|
||||
subCommand: 100,
|
||||
};
|
||||
const sender = makeSender();
|
||||
await invokeOidb(sender, spec, { groupId: 1 });
|
||||
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x11c5_100');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildOidbRequest', () => {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
|
||||
import { OidbError } from '../../../src/oidb-service';
|
||||
import { Ntv2UploadRequest } from '../../../src/oidb-services/highway/ntv2-upload-request';
|
||||
|
||||
function packet(body: NTV2UploadRichMediaResp, errorCode = 0): SendPacketResult {
|
||||
return {
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<NTV2UploadRichMediaResp>>({
|
||||
command: 0x11C5,
|
||||
subCommand: 100,
|
||||
errorCode,
|
||||
errorMsg: errorCode ? 'denied' : '',
|
||||
body,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
const params: Ntv2UploadRequest.Params = {
|
||||
oidbCmd: 0x11C5,
|
||||
isGroup: false,
|
||||
targetIdOrUid: 'u_peer',
|
||||
requestId: 1,
|
||||
businessType: 1,
|
||||
uploadInfo: [],
|
||||
compatQmsgSceneType: 1,
|
||||
extBizInfo: {},
|
||||
tryFast: true,
|
||||
clientRandomId: 1n,
|
||||
};
|
||||
|
||||
describe('Ntv2UploadRequest', () => {
|
||||
it('sends the resolved command on the default OIDB wire name', async () => {
|
||||
const sendRawPacket = vi.fn(async () => packet({
|
||||
upload: { msgInfo: { msgInfoBody: [] } },
|
||||
}));
|
||||
await Ntv2UploadRequest.invoke({ sendRawPacket }, params);
|
||||
expect(sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x11c5_100');
|
||||
});
|
||||
|
||||
it('raises OidbError when the envelope is rejected', async () => {
|
||||
const sendRawPacket = vi.fn(async () => packet({ upload: { msgInfo: {} } }, 42));
|
||||
await expect(Ntv2UploadRequest.invoke({ sendRawPacket }, params)).rejects.toBeInstanceOf(OidbError);
|
||||
});
|
||||
|
||||
it('fails in deserialize when msgInfo is missing', async () => {
|
||||
const sendRawPacket = vi.fn(async () => packet({ upload: { uKey: 'k' } }));
|
||||
await expect(Ntv2UploadRequest.invoke({ sendRawPacket }, params))
|
||||
.rejects.toThrow('upload response missing msgInfo');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user