Files
SnowLuma/packages/protocol/tests/oidb-services/profile/set-self-long-nick.test.ts
T
TanTan fa9c73363d
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
SnowLuma v2.4.2 source snapshot
2026-11-13 09:02:00 +08:00

62 lines
2.5 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 { Oidb0x112aReq } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetSelfLongNick } from '../../../src/oidb-services/profile/set-self-long-nick';
function makeDeps() {
const r: SendPacketResult = {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: Buffer.alloc(0),
};
return {
sendRawPacket: vi.fn(async () => r),
identity: { uin: '10001' } as any,
};
}
describe('SetSelfLongNick namespace', () => {
it('declares 0x112A_2', () => {
expect(SetSelfLongNick.command).toBe(0x112a);
expect(SetSelfLongNick.subCommand).toBe(2);
});
describe('invoke', () => {
it('routes to OidbSvcTrpcTcp.0x112a_2', async () => {
const deps = makeDeps();
await SetSelfLongNick.invoke(deps, { longNick: 'hello world' });
expect(deps.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x112a_2');
});
it('wraps the long nick in profile { tag: 102, value }', async () => {
const deps = makeDeps();
await SetSelfLongNick.invoke(deps, { longNick: 'hello world' });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<Oidb0x112aReq>>(bytes);
expect(env.body?.uin).toBe(10001n);
expect(env.body?.profile).toEqual({ tag: 102, value: 'hello world' });
});
it('omits the value field when clearing the signature', async () => {
const deps = makeDeps();
await SetSelfLongNick.invoke(deps, { longNick: '' });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(Buffer.from(bytes).toString('hex')).toBe('08aa221002220708914e12020866');
});
it('coerces non-string longNick into a string (defensive)', async () => {
const deps = makeDeps();
// simulate a misbehaving caller passing a number
await SetSelfLongNick.invoke(deps, { longNick: 12345 as any });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<Oidb0x112aReq>>(bytes);
expect(env.body?.profile?.value).toBe('12345');
});
});
});