3 OIDB cmds moved to self-contained namespaces:
- HandleFriendRequest (0xB5D_44) — digit-only flag still
auto-resolves via resolveUserUid
- DeleteFriend (0x126B_0) — verbatim magic constants in the
nested field2 sub-message
(130/109/8/8/50 — server-side
discriminator, MUST stay byte-
equal to NTQQ wire)
- SetFriendRemark (0xB6E_2)
Cache invalidation (fetchFriendList after deletion) stays in the
facade — that side-effect needs `ctx.apis.contacts`, which namespaces
deliberately can't reach.
Tests migrated to assert against bridge.sendRawPacket. 15 new
namespace-level tests covering each invoke branch + serialize edge
cases.
Verification:
- typecheck green
- @snowluma/bridge: 15 files / 133 tests
- friend.test.ts: 5/5
Wire bytes unchanged.
45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { protobuf_decode } from '@snowluma/proton';
|
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
import type { OidbSetFriendRemark } from '@snowluma/proto-defs/oidb-actions/base';
|
|
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
|
|
|
import { SetFriendRemark } from '../../../src/oidb-services/friend/set-friend-remark';
|
|
|
|
function makeDeps() {
|
|
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
|
|
return {
|
|
sendRawPacket: vi.fn(async () => r),
|
|
resolveUserUid: vi.fn(async () => 'resolved-uid'),
|
|
};
|
|
}
|
|
|
|
describe('SetFriendRemark namespace', () => {
|
|
it('declares 0xB6E_2', () => {
|
|
expect(SetFriendRemark.command).toBe(0xB6E);
|
|
expect(SetFriendRemark.subCommand).toBe(2);
|
|
});
|
|
|
|
describe('invoke', () => {
|
|
it('routes to OidbSvcTrpcTcp.0xb6e_2', async () => {
|
|
const deps = makeDeps();
|
|
await SetFriendRemark.invoke(deps, { userId: 10001, remark: 'x' });
|
|
expect(deps.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0xb6e_2');
|
|
});
|
|
|
|
it('resolves the target uid before encoding', async () => {
|
|
const deps = makeDeps();
|
|
await SetFriendRemark.invoke(deps, { userId: 10001, remark: 'best-friend' });
|
|
expect(deps.resolveUserUid).toHaveBeenCalledWith(10001);
|
|
});
|
|
|
|
it('packages uid + remark in body', async () => {
|
|
const deps = makeDeps();
|
|
await SetFriendRemark.invoke(deps, { userId: 10001, remark: 'best-friend' });
|
|
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
|
const env = protobuf_decode<OidbBase<OidbSetFriendRemark>>(bytes);
|
|
expect(env.body).toMatchObject({ targetUid: 'resolved-uid', remark: 'best-friend' });
|
|
});
|
|
});
|
|
});
|