Files
SnowLuma/packages/bridge/tests/oidb-services/interaction/send-like.test.ts
T
DrSmoothl ff2b902cbd refactor(oidb): migrate interaction.ts remaining 3 cmds to namespaces
Completes the InteractionApi facade — every method is now a one-line
forwarder. New namespaces:
  - SendPoke   (0xED3_1)  — group + friend variants discriminated by
                            which of groupUin/friendUin is set
  - SendLike   (0x7E5_104) — thumbs-up to a target user
  - SetEssence (0xEAC_1/_2) — set/unset essence message, dynamic subcmd

Facade methods reduced to thin forwarders, mirror-fixed comment block
removed (the namespaces now own the wire-shape commentary).

Tests: 28 new in @snowluma/bridge covering each namespace's serialize
edge cases + dynamic subcmd resolution + e2e wire name + envelope body
shape. Cleaned the legacy `vi.mock('bridge-oidb')` setup out of
interaction.test.ts — the post-migration path doesn't route through
the mocked symbols anymore.

Wire behavior unchanged: every cmd produces the same bytes as before,
verified by encode round-trip in the unit tests.
2026-05-22 23:22:26 +08:00

44 lines
1.7 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 { OidbLike } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SendLike } from '../../../src/oidb-services/interaction/send-like';
function makeSender() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('SendLike namespace', () => {
it('declares 0x7E5_104', () => {
expect(SendLike.command).toBe(0x7E5);
expect(SendLike.subCommand).toBe(104);
});
describe('serialize', () => {
it('passes userId / count through verbatim', () => {
expect(SendLike.serialize({ userId: 10001, count: 3 })).toEqual({ targetUin: 10001, count: 3 });
});
});
describe('invoke (e2e)', () => {
it('routes to OidbSvcTrpcTcp.0x7e5_104', async () => {
const sender = makeSender();
await SendLike.invoke(sender, { userId: 10001, count: 3 });
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x7e5_104');
});
it('encodes targetUin + count into envelope body', async () => {
const sender = makeSender();
await SendLike.invoke(sender, { userId: 10001, count: 3 });
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbLike>>(bytes);
expect(env.command).toBe(0x7E5);
expect(env.subCommand).toBe(104);
expect(env.body).toMatchObject({ targetUin: 10001, count: 3 });
});
});
});