This commit is contained in:
DrSmoothl committed 2026-10-12 15:43:34 +08:00
1 parent effeb66554
commit 7c0519f75f
977 files changed
+198426 -158324

No files matched your search

@@ -7,68 +7,89 @@ import { ModifyGroupExtInfo } from '../../../src/oidb-services/group-admin/modif
import { env, v, m } from '../_pb-oracle';
function makeSender(result = 0) {
const respEnv: OidbBase<OidbModifyGroupExtResp> = { command: 0xF00, subCommand: 3, body: { groupCode: 12345, result } };
const r: SendPacketResult = {
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbModifyGroupExtResp>>(respEnv)),
};
return { sendRawPacket: vi.fn(async () => r) };
const respEnv: OidbBase<OidbModifyGroupExtResp> = {
command: 0xf00,
subCommand: 3,
body: { groupCode: 12345, result },
};
const r: SendPacketResult = {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbModifyGroupExtResp>>(respEnv)),
};
return { sendRawPacket: vi.fn(async () => r) };
}
describe('ModifyGroupExtInfo namespace', () => {
it('declares command 0xF00 sub 3, uin form', () => {
expect(ModifyGroupExtInfo.command).toBe(0xF00);
expect(ModifyGroupExtInfo.subCommand).toBe(3);
expect(ModifyGroupExtInfo.uinForm).toBe(true);
});
it('declares command 0xF00 sub 3, uin form', () => {
expect(ModifyGroupExtInfo.command).toBe(0xf00);
expect(ModifyGroupExtInfo.subCommand).toBe(3);
expect(ModifyGroupExtInfo.uinForm).toBe(true);
});
it('only includes the fields the caller provides', () => {
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1, robotMemberSwitch: 1 }))
.toEqual({ groupCode: 1, info: { groupCode: 1, ext: { inviteRobotMemberSwitch: 1 } } });
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1 }))
.toEqual({ groupCode: 1, info: { groupCode: 1, ext: {} } });
});
it('only includes the fields the caller provides', () => {
expect(
ModifyGroupExtInfo.serialize({} as any, { groupId: 1, robotMemberSwitch: 1 }),
).toEqual({
groupCode: 1,
info: { groupCode: 1, ext: { inviteRobotMemberSwitch: 1 } },
});
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1 })).toEqual({
groupCode: 1,
info: { groupCode: 1, ext: {} },
});
});
it('byte-oracle: routes to 0xf00_3 and locks nested tags {1:gc,2:{1:gc,2:{29:switch,30:examine}}}', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 1, robotMemberExamine: 2 });
it('byte-oracle: routes to 0xf00_3 and locks nested tags {1:gc,2:{1:gc,2:{29:switch,30:examine}}}', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, {
groupId: 12345,
robotMemberSwitch: 1,
robotMemberExamine: 2,
});
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0xf00_3');
const ext = [...v(29, 1), ...v(30, 2)];
const info = [...v(1, 12345), ...m(2, ext)];
const body = [...v(1, 12345), ...m(2, info)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xF00, 3, body, true));
});
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0xf00_3');
const ext = [...v(29, 1), ...v(30, 2)];
const info = [...v(1, 12345), ...m(2, ext)];
const body = [...v(1, 12345), ...m(2, info)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xf00, 3, body, true));
});
it('emits switch=0 on the wire (explicit presence; omit would look like "unchanged")', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 0 });
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
const ext = [...v(29, 0)];
const info = [...v(1, 12345), ...m(2, ext)];
const body = [...v(1, 12345), ...m(2, info)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xF00, 3, body, true));
});
it('emits switch=0 on the wire (explicit presence; omit would look like "unchanged")', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 0 });
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
const ext = [...v(29, 0)];
const info = [...v(1, 12345), ...m(2, ext)];
const body = [...v(1, 12345), ...m(2, info)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xf00, 3, body, true));
});
it('emits both zeros when the caller sets switch and examine to 0', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 0, robotMemberExamine: 0 });
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
const ext = [...v(29, 0), ...v(30, 0)];
const info = [...v(1, 12345), ...m(2, ext)];
const body = [...v(1, 12345), ...m(2, info)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xF00, 3, body, true));
});
it('emits both zeros when the caller sets switch and examine to 0', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, {
groupId: 12345,
robotMemberSwitch: 0,
robotMemberExamine: 0,
});
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
const ext = [...v(29, 0), ...v(30, 0)];
const info = [...v(1, 12345), ...m(2, ext)];
const body = [...v(1, 12345), ...m(2, info)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xf00, 3, body, true));
});
it('does not send when neither field is provided', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345 });
expect(sender.sendRawPacket).not.toHaveBeenCalled();
});
it('does not send when neither field is provided', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345 });
expect(sender.sendRawPacket).not.toHaveBeenCalled();
});
it('deserialize throws on a non-zero body result', () => {
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 5 })).toThrow(/result=5/);
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 0 })).not.toThrow();
});
it('deserialize throws on a non-zero body result', () => {
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 5 })).toThrow(/result=5/);
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 0 })).not.toThrow();
});
});