10 files changed
+305
-1
No files matched your search
@@ -20,6 +20,7 @@ interface GroupDetailResultsFixture {
|
||||
name?: pb<15, string>;
|
||||
shutUpAllTimestamp?: pb<59, uint_32>;
|
||||
privilegeFlag?: pb<99, uint_32>;
|
||||
groupFlagExt4?: pb<101, uint_32>;
|
||||
}
|
||||
|
||||
interface GroupDetailInfoFixture {
|
||||
@@ -57,6 +58,7 @@ describe('FetchGroupDetail namespace', () => {
|
||||
expect((out.config?.flags as { shutUpAllTimestamp?: boolean })?.shutUpAllTimestamp)
|
||||
.toBe(true);
|
||||
expect(out.config?.flags?.privilegeFlag).toBe(true);
|
||||
expect(out.config?.flags?.groupFlagExt4).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -135,5 +137,27 @@ describe('FetchGroupDetail namespace', () => {
|
||||
const out = await FetchGroupDetail.invoke(sender, { groupUin: 601692726 });
|
||||
expect(out.groupInfo?.results?.privilegeFlag).toBe(0x82100001);
|
||||
});
|
||||
|
||||
it('decodes the complete extended group flag used by history visibility', async () => {
|
||||
const responseData = Buffer.from(protobuf_encode<OidbBase<GroupDetailResponseFixture>>({
|
||||
body: {
|
||||
groupInfo: {
|
||||
uin: 601692726n,
|
||||
results: { groupFlagExt4: 0x80000005 },
|
||||
},
|
||||
},
|
||||
}));
|
||||
const sender = makeSender();
|
||||
sender.sendRawPacket.mockResolvedValue({
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData,
|
||||
});
|
||||
|
||||
const out = await FetchGroupDetail.invoke(sender, { groupUin: 601692726 });
|
||||
expect(out.groupInfo?.results?.groupFlagExt4).toBe(0x80000005);
|
||||
});
|
||||
});
|
||||
});
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x89a_0HistoryVisibility } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
|
||||
import {
|
||||
GROUP_HISTORY_VISIBILITY_MASK,
|
||||
mergeGroupHistoryVisibility,
|
||||
SetNewMemberHistoryVisibility,
|
||||
} from '../../../src/oidb-services/group-admin/set-new-member-history-visibility';
|
||||
|
||||
function makeSender() {
|
||||
const result: SendPacketResult = {
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData: Buffer.alloc(0),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => result) };
|
||||
}
|
||||
|
||||
describe('SetNewMemberHistoryVisibility namespace', () => {
|
||||
it.each([
|
||||
[true, 0x80000001, 0x80000005],
|
||||
[false, 0x80000005, 0x80000001],
|
||||
])('writes visible=%s without changing unrelated bits', async (visible, current, expected) => {
|
||||
const sender = makeSender();
|
||||
|
||||
await SetNewMemberHistoryVisibility.invoke(sender, {
|
||||
groupId: 12345,
|
||||
currentGroupFlagExt4: current,
|
||||
visible,
|
||||
});
|
||||
|
||||
const [command, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(command).toBe('OidbSvcTrpcTcp.0x89a_0');
|
||||
const envelope = protobuf_decode<OidbBase<Oidb0x89a_0HistoryVisibility>>(bytes);
|
||||
expect(envelope.command).toBe(0x89A);
|
||||
expect(envelope.body).toMatchObject({
|
||||
groupUin: 12345n,
|
||||
settings: {
|
||||
groupFlagExt4: expected,
|
||||
groupFlagExt4Mask: GROUP_HISTORY_VISIBILITY_MASK,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('merges only the verified history-visibility bit', () => {
|
||||
expect(mergeGroupHistoryVisibility(0xF0000001, true)).toBe(0xF0000005);
|
||||
expect(mergeGroupHistoryVisibility(0xF0000005, false)).toBe(0xF0000001);
|
||||
});
|
||||
|
||||
it('keeps an explicit zero value on the wire', async () => {
|
||||
const sender = makeSender();
|
||||
await SetNewMemberHistoryVisibility.invoke(sender, {
|
||||
groupId: 1,
|
||||
currentGroupFlagExt4: GROUP_HISTORY_VISIBILITY_MASK,
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const envelope = protobuf_decode<OidbBase<Oidb0x89a_0HistoryVisibility>>(
|
||||
sender.sendRawPacket.mock.calls[0]![1],
|
||||
);
|
||||
expect(envelope.body?.settings?.groupFlagExt4).toBe(0);
|
||||
expect(envelope.body?.settings?.groupFlagExt4Mask).toBe(GROUP_HISTORY_VISIBILITY_MASK);
|
||||
});
|
||||
|
||||
it('rejects an invalid current flag before sending', async () => {
|
||||
const sender = makeSender();
|
||||
await expect(SetNewMemberHistoryVisibility.invoke(sender, {
|
||||
groupId: 1,
|
||||
currentGroupFlagExt4: -1,
|
||||
visible: true,
|
||||
})).rejects.toThrow(/unsigned 32-bit/);
|
||||
expect(sender.sendRawPacket).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user