refactor(packages): rename @snowluma/bridge → @snowluma/protocol
The package previously named "bridge" houses the protocol-byte layer (OIDB cmds, msg-push decoders, highway uploaders, element-builder, event bus). The name "bridge" suggested transport/lifecycle, which it isn't — that role lives in core/hook and core/bridge/manager. Rename to match what's actually inside. This is a pure rename: zero logic changes, all 73 import sites updated mechanically and TS-verified. core/onebot dependencies key updated. ESLint override path adjusted for the moved oidb-services directory. Rename detection threshold: git log --find-renames=20% recommended when following history across this commit — content-replacement (@snowluma/bridge → @snowluma/protocol) dropped per-file similarity below git's default 50% on import-heavy files.
This commit is contained in:
238 files changed
+247
-284
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchDownloadRkeys } from '../../../src/oidb-services/contacts/fetch-download-rkeys';
|
||||
|
||||
function makeSender(body?: NTV2RichMediaResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<NTV2RichMediaResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('FetchDownloadRkeys namespace', () => {
|
||||
it('declares 0x9067_202 with uinForm=true', () => {
|
||||
expect(FetchDownloadRkeys.command).toBe(0x9067);
|
||||
expect(FetchDownloadRkeys.subCommand).toBe(202);
|
||||
expect(FetchDownloadRkeys.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
describe('serialize', () => {
|
||||
it('requests the (private=10, group=20, fallback=2) image scopes', () => {
|
||||
const out = FetchDownloadRkeys.serialize({} as any, {});
|
||||
expect(out.downloadRkey?.types).toEqual([10, 20, 2]);
|
||||
});
|
||||
|
||||
it('packages the fixed reqHead { common, scene, client }', () => {
|
||||
const out = FetchDownloadRkeys.serialize({} as any, {});
|
||||
expect(out.reqHead).toEqual({
|
||||
common: { requestId: 1, command: 202 },
|
||||
scene: { requestType: 2, businessType: 1, sceneType: 0 },
|
||||
client: { agentType: 2 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('throws when respHead.retCode is non-zero', () => {
|
||||
expect(() => FetchDownloadRkeys.deserialize({} as any, {
|
||||
respHead: { retCode: 42, message: 'bad' },
|
||||
} as any)).toThrow('bad');
|
||||
});
|
||||
|
||||
it('passes through on retCode = 0', () => {
|
||||
const body = { respHead: { retCode: 0 }, downloadRkey: { rkeys: [] } };
|
||||
expect(FetchDownloadRkeys.deserialize({} as any, body as any)).toBe(body);
|
||||
});
|
||||
|
||||
it('falls back to a generic message when none is provided', () => {
|
||||
expect(() => FetchDownloadRkeys.deserialize({} as any, {
|
||||
respHead: { retCode: 1 },
|
||||
} as any)).toThrow('fetch download rkey failed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('invoke (e2e)', () => {
|
||||
it('routes to OidbSvcTrpcTcp.0x9067_202 with reserved=1', async () => {
|
||||
const sender = makeSender({ respHead: { retCode: 0 }, downloadRkey: { rkeys: [] } } as any);
|
||||
await FetchDownloadRkeys.invoke(sender);
|
||||
const [wireName, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(wireName).toBe('OidbSvcTrpcTcp.0x9067_202');
|
||||
const env = protobuf_decode<OidbBase<NTV2RichMediaReq>>(bytes);
|
||||
expect(env.reserved).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbSvcTrpcTcp0xFD4_1Response } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbFriendListRequest } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchFriendListPage } from '../../../src/oidb-services/contacts/fetch-friend-list-page';
|
||||
|
||||
function makeSender(body?: OidbSvcTrpcTcp0xFD4_1Response) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbSvcTrpcTcp0xFD4_1Response>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('FetchFriendListPage namespace', () => {
|
||||
it('declares 0xFD4_1', () => {
|
||||
expect(FetchFriendListPage.command).toBe(0xFD4);
|
||||
expect(FetchFriendListPage.subCommand).toBe(1);
|
||||
});
|
||||
|
||||
describe('serialize', () => {
|
||||
it('omits nextUin on the first page', () => {
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: null }) as any;
|
||||
expect(out.nextUin).toBeUndefined();
|
||||
expect(out.friendCount).toBe(300);
|
||||
expect(out.field4).toBe(0);
|
||||
});
|
||||
|
||||
it('includes nextUin sub-message on follow-up pages', () => {
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: 10001 }) as any;
|
||||
expect(out.nextUin).toEqual({ uin: 10001 });
|
||||
});
|
||||
|
||||
it('emits the verbatim property request list (codes 100/101/102/103/20002/27394)', () => {
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: null }) as any;
|
||||
expect(out.body).toEqual([
|
||||
{ type: 1, number: { numbers: [103, 102, 20002, 27394] } },
|
||||
{ type: 4, number: { numbers: [100, 101, 102] } },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('invoke (e2e)', () => {
|
||||
it('routes to OidbSvcTrpcTcp.0xfd4_1', async () => {
|
||||
const sender = makeSender({ friends: [] });
|
||||
await FetchFriendListPage.invoke(sender, { nextUin: null });
|
||||
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0xfd4_1');
|
||||
});
|
||||
|
||||
it('returns the wire body verbatim (facade does the FriendInfo mapping)', async () => {
|
||||
const body = { friends: [{ uin: 10001, uid: 'u', additional: [] }], next: { uin: 0 } };
|
||||
const sender = makeSender(body as any);
|
||||
const out = await FetchFriendListPage.invoke(sender, { nextUin: null });
|
||||
expect(out.friends).toBeDefined();
|
||||
expect(out.next?.uin ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('encodes envelope body correctly', async () => {
|
||||
const sender = makeSender({ friends: [] });
|
||||
await FetchFriendListPage.invoke(sender, { nextUin: 10001 });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbFriendListRequest>>(bytes);
|
||||
expect(env.body?.nextUin).toEqual({ uin: 10001 });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupListRequest } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchGroupList } from '../../../src/oidb-services/contacts/fetch-group-list';
|
||||
|
||||
function makeSender() {
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('FetchGroupList namespace', () => {
|
||||
it('declares 0xFE5_2 with uinForm=true', () => {
|
||||
expect(FetchGroupList.command).toBe(0xFE5);
|
||||
expect(FetchGroupList.subCommand).toBe(2);
|
||||
expect(FetchGroupList.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
describe('invoke (e2e)', () => {
|
||||
it('routes to OidbSvcTrpcTcp.0xfe5_2 with envelope reserved=1', async () => {
|
||||
const sender = makeSender();
|
||||
await FetchGroupList.invoke(sender);
|
||||
const [wireName, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(wireName).toBe('OidbSvcTrpcTcp.0xfe5_2');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupListRequest>>(bytes);
|
||||
expect(env.reserved).toBe(1);
|
||||
});
|
||||
|
||||
it('sends the verbatim config blob (field5002/5003 OFF to avoid EPIPE on big rosters)', async () => {
|
||||
const sender = makeSender();
|
||||
await FetchGroupList.invoke(sender);
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbGroupListRequest>>(bytes);
|
||||
expect(env.body?.config?.config1?.groupName).toBe(true);
|
||||
expect(env.body?.config?.config1?.memberCount).toBe(true);
|
||||
// proto3 default false — omitted on wire, decoded as null.
|
||||
expect(env.body?.config?.config1?.field5002 ?? false).toBe(false);
|
||||
expect(env.body?.config?.config1?.field5003 ?? false).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupMemberListRequest } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchGroupMemberListPage } from '../../../src/oidb-services/contacts/fetch-group-member-list-page';
|
||||
|
||||
function makeSender() {
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('FetchGroupMemberListPage namespace', () => {
|
||||
it('declares 0xFE7_3', () => {
|
||||
expect(FetchGroupMemberListPage.command).toBe(0xFE7);
|
||||
expect(FetchGroupMemberListPage.subCommand).toBe(3);
|
||||
});
|
||||
|
||||
describe('serialize', () => {
|
||||
it('omits the token on the first page', () => {
|
||||
const out = FetchGroupMemberListPage.serialize({} as any, { groupId: 12345, token: '' }) as any;
|
||||
expect(out.token).toBeUndefined();
|
||||
expect(out.groupUin).toBe(12345);
|
||||
});
|
||||
|
||||
it('threads the server-issued token into follow-up pages', () => {
|
||||
const out = FetchGroupMemberListPage.serialize({} as any, { groupId: 12345, token: 'next-cursor' }) as any;
|
||||
expect(out.token).toBe('next-cursor');
|
||||
});
|
||||
|
||||
it('always requests the full member-field projection', () => {
|
||||
const out = FetchGroupMemberListPage.serialize({} as any, { groupId: 1, token: '' }) as any;
|
||||
expect(out.body).toMatchObject({
|
||||
memberName: true, memberCard: true, level: true,
|
||||
joinTimestamp: true, lastMsgTimestamp: true, shutUpTimestamp: true,
|
||||
permission: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('invoke (e2e)', () => {
|
||||
it('routes to OidbSvcTrpcTcp.0xfe7_3', async () => {
|
||||
const sender = makeSender();
|
||||
await FetchGroupMemberListPage.invoke(sender, { groupId: 1, token: '' });
|
||||
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0xfe7_3');
|
||||
});
|
||||
|
||||
it('encodes envelope body with the groupId', async () => {
|
||||
const sender = makeSender();
|
||||
await FetchGroupMemberListPage.invoke(sender, { groupId: 12345, token: '' });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbGroupMemberListRequest>>(bytes);
|
||||
expect(env.body?.groupUin).toBe(12345);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupRequestList } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchGroupRequests } from '../../../src/oidb-services/contacts/fetch-group-requests';
|
||||
|
||||
function makeSender() {
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('FetchGroupRequests namespace', () => {
|
||||
it('declares 0x10C0', () => {
|
||||
expect(FetchGroupRequests.command).toBe(0x10C0);
|
||||
});
|
||||
|
||||
describe('resolveSubCommand', () => {
|
||||
it('returns 1 when filtered=false (main inbox)', () => {
|
||||
expect(FetchGroupRequests.resolveSubCommand({ filtered: false })).toBe(1);
|
||||
});
|
||||
it('returns 2 when filtered=true (low-priority inbox)', () => {
|
||||
expect(FetchGroupRequests.resolveSubCommand({ filtered: true })).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('serialize', () => {
|
||||
it('always sends count=20 / field2=0', () => {
|
||||
expect(FetchGroupRequests.serialize({} as any, { filtered: false })).toEqual({ count: 20, field2: 0 });
|
||||
expect(FetchGroupRequests.serialize({} as any, { filtered: true })).toEqual({ count: 20, field2: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('invoke (e2e)', () => {
|
||||
it('routes to 0x10c0_1 for the main inbox', async () => {
|
||||
const sender = makeSender();
|
||||
await FetchGroupRequests.invoke(sender, { filtered: false });
|
||||
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x10c0_1');
|
||||
});
|
||||
|
||||
it('routes to 0x10c0_2 for the filtered inbox', async () => {
|
||||
const sender = makeSender();
|
||||
await FetchGroupRequests.invoke(sender, { filtered: true });
|
||||
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x10c0_2');
|
||||
});
|
||||
|
||||
it('encodes envelope body with count=20', async () => {
|
||||
const sender = makeSender();
|
||||
await FetchGroupRequests.invoke(sender, { filtered: false });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbGroupRequestList>>(bytes);
|
||||
expect(env.body?.count).toBe(20);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbUserInfoByUidRequest, OidbUserInfoResponse,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchUserProfileByUid } from '../../../src/oidb-services/contacts/fetch-user-profile-by-uid';
|
||||
|
||||
function makeSender(body?: OidbUserInfoResponse) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbUserInfoResponse>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('FetchUserProfileByUid namespace (UID form)', () => {
|
||||
it('declares 0xFE1_2 WITHOUT uinForm (reserved stays 0)', () => {
|
||||
expect(FetchUserProfileByUid.command).toBe(0xFE1);
|
||||
expect(FetchUserProfileByUid.subCommand).toBe(2);
|
||||
// No `uinForm` exposed — matches Lagrange's isUid=false path on
|
||||
// the UID variant. Important because the server distinguishes
|
||||
// UIN vs UID requests via the envelope's `reserved` field.
|
||||
expect((FetchUserProfileByUid as any).uinForm).toBeUndefined();
|
||||
});
|
||||
|
||||
it('packages the uid as field 1 (string), routes to OidbSvcTrpcTcp.0xfe1_2', async () => {
|
||||
const sender = makeSender({ body: { uin: 950929451, uid: 'u_abc' } as any });
|
||||
await FetchUserProfileByUid.invoke(sender, { uid: 'u_abc' });
|
||||
const [wireName, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(wireName).toBe('OidbSvcTrpcTcp.0xfe1_2');
|
||||
const env = protobuf_decode<OidbBase<OidbUserInfoByUidRequest>>(bytes);
|
||||
expect(env.body?.uid).toBe('u_abc');
|
||||
// reserved=0 (default, omitted on wire) because this is the UID
|
||||
// variant — Lagrange's `OidbSvcTrpcTcp0xFE1_2.cs:9` does the same.
|
||||
expect(env.reserved ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('requests the same property key catalogue as the UIN variant', async () => {
|
||||
const sender = makeSender({ body: { uin: 1, uid: 'u' } as any });
|
||||
await FetchUserProfileByUid.invoke(sender, { uid: 'u' });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbUserInfoByUidRequest>>(bytes);
|
||||
const keys = env.body?.keys?.map(k => k.key);
|
||||
expect(keys).toContain(20002); // nickname — the whole point
|
||||
expect(keys).toContain(105); // QQ level
|
||||
});
|
||||
|
||||
it('decodes nickname + uin from the response so the pipeline can fill them into the event', async () => {
|
||||
// This is the actual point of the namespace — the stranger's
|
||||
// nickname + uin lands here so the pipeline can patch them onto
|
||||
// the in-flight group_invite event.
|
||||
const enc = (s: string) => new TextEncoder().encode(s);
|
||||
const sender = makeSender({
|
||||
body: {
|
||||
uin: 950929451, uid: 'u_abc',
|
||||
properties: {
|
||||
bytesProperties: [{ code: 20002, value: enc('小明') }],
|
||||
numberProperties: [],
|
||||
},
|
||||
} as any,
|
||||
});
|
||||
const out = await FetchUserProfileByUid.invoke(sender, { uid: 'u_abc' });
|
||||
expect(out.uin).toBe(950929451);
|
||||
expect(out.nickname).toBe('小明');
|
||||
});
|
||||
|
||||
it('throws when the response body is missing entirely', async () => {
|
||||
const sender = makeSender({});
|
||||
await expect(FetchUserProfileByUid.invoke(sender, { uid: 'u_abc' }))
|
||||
.rejects.toThrow('user info response body missing');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,124 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
AvatarInfo, OidbUserInfoRequest, OidbUserInfoResponse,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchUserProfile } from '../../../src/oidb-services/contacts/fetch-user-profile';
|
||||
|
||||
function makeSender(body?: OidbUserInfoResponse) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbUserInfoResponse>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('FetchUserProfile namespace', () => {
|
||||
it('declares 0xFE1_2 with uinForm=true', () => {
|
||||
expect(FetchUserProfile.command).toBe(0xFE1);
|
||||
expect(FetchUserProfile.subCommand).toBe(2);
|
||||
expect(FetchUserProfile.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
describe('invoke (e2e)', () => {
|
||||
it('routes to OidbSvcTrpcTcp.0xfe1_2 with reserved=1', async () => {
|
||||
const sender = makeSender({ body: { uin: 10001, uid: 'u' } as any });
|
||||
await FetchUserProfile.invoke(sender, { uin: 10001 });
|
||||
const [wireName, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(wireName).toBe('OidbSvcTrpcTcp.0xfe1_2');
|
||||
const env = protobuf_decode<OidbBase<OidbUserInfoRequest>>(bytes);
|
||||
expect(env.reserved).toBe(1);
|
||||
});
|
||||
|
||||
it('requests every property key in the catalogue (nickname, level, …)', async () => {
|
||||
const sender = makeSender({ body: { uin: 10001, uid: 'u' } as any });
|
||||
await FetchUserProfile.invoke(sender, { uin: 10001 });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbUserInfoRequest>>(bytes);
|
||||
const keys = env.body?.keys?.map(k => k.key);
|
||||
expect(keys).toContain(20002); // nickname
|
||||
expect(keys).toContain(105); // level
|
||||
expect(keys).toContain(101); // avatar
|
||||
expect(keys).toContain(102); // sign
|
||||
expect(keys).toContain(103); // remark
|
||||
});
|
||||
|
||||
it('decodes nickname / remark / qid / sign from bytes-properties', async () => {
|
||||
const enc = (s: string) => new TextEncoder().encode(s);
|
||||
const sender = makeSender({
|
||||
body: {
|
||||
uin: 10001, uid: 'u',
|
||||
properties: {
|
||||
bytesProperties: [
|
||||
{ code: 20002, value: enc('Nick') },
|
||||
{ code: 103, value: enc('Bestie') },
|
||||
{ code: 27394, value: enc('myqid') },
|
||||
{ code: 102, value: enc('Hello') },
|
||||
],
|
||||
numberProperties: [],
|
||||
},
|
||||
} as any,
|
||||
});
|
||||
const out = await FetchUserProfile.invoke(sender, { uin: 10001 });
|
||||
expect(out.nickname).toBe('Nick');
|
||||
expect(out.remark).toBe('Bestie');
|
||||
expect(out.qid).toBe('myqid');
|
||||
expect(out.sign).toBe('Hello');
|
||||
});
|
||||
|
||||
it('decodes sex / age / level from number-properties (sex enum)', async () => {
|
||||
const cases: Array<[number, string]> = [
|
||||
[1, 'male'], [2, 'female'], [255, 'unknown'], [0, 'unknown'],
|
||||
];
|
||||
for (const [sexNum, expected] of cases) {
|
||||
const sender = makeSender({
|
||||
body: {
|
||||
uin: 1, uid: 'u',
|
||||
properties: {
|
||||
bytesProperties: [],
|
||||
numberProperties: [
|
||||
{ number1: 20009, number2: sexNum },
|
||||
{ number1: 20037, number2: 25 },
|
||||
{ number1: 105, number2: 7 },
|
||||
],
|
||||
},
|
||||
} as any,
|
||||
});
|
||||
const out = await FetchUserProfile.invoke(sender, { uin: 1 });
|
||||
expect(out.sex).toBe(expected);
|
||||
expect(out.age).toBe(25);
|
||||
expect(out.level).toBe(7);
|
||||
}
|
||||
});
|
||||
|
||||
it('decodes the avatar URL with the "640" size suffix appended', async () => {
|
||||
const avatarBytes = protobuf_encode<AvatarInfo>({ url: 'https://q.qlogo.cn/abc/' });
|
||||
const sender = makeSender({
|
||||
body: {
|
||||
uin: 10001, uid: 'u',
|
||||
properties: {
|
||||
bytesProperties: [{ code: 101, value: avatarBytes }],
|
||||
numberProperties: [],
|
||||
},
|
||||
} as any,
|
||||
});
|
||||
const out = await FetchUserProfile.invoke(sender, { uin: 10001 });
|
||||
expect(out.avatar).toBe('https://q.qlogo.cn/abc/640');
|
||||
});
|
||||
|
||||
it('defaults uin to the requested value when the server omits its echo', async () => {
|
||||
const sender = makeSender({ body: { uid: 'u' } as any });
|
||||
const out = await FetchUserProfile.invoke(sender, { uin: 99999 });
|
||||
expect(out.uin).toBe(99999);
|
||||
});
|
||||
|
||||
it('throws when body is entirely missing from the envelope', async () => {
|
||||
const sender = makeSender({});
|
||||
await expect(FetchUserProfile.invoke(sender, { uin: 1 }))
|
||||
.rejects.toThrow('user info response body missing');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user