refactor(api): move interaction methods to InteractionApi (#6 commit 6/13)
Folds the entire `actions/interaction.ts` (sendPoke / sendLike / setGroupReaction / getEmojiLikes) plus the lone-survivor `setGroupEssence` from `actions/group-message.ts` into `apis/interaction.ts::InteractionApi`. Both action files deleted — the recall + markRead halves of group-message were already absorbed into MessageApi back in commit 1. Skipping the planned standalone GroupMessageApi commit: with only one method left (`setGroupEssence`), giving it its own Api class would be pure overhead. Essence is conceptually an "interaction" anyway (mark a message as essence is parallel to "react with an emoji"). Method renaming (Api namespace already says "interaction"): sendPoke → sendPoke (no rename — already minimal) sendLike → sendLike setGroupReaction → setReaction setGroupEssence → setEssence getEmojiLikes → getEmojiLikes (no rename — read-side, fine) Callers updated: `instance-context.ts`, `modules/message-actions.ts`, `actions/extended.ts`. Tests `interaction.test.ts` rewritten to use `new InteractionApi(bridge as any).method(...)` and gained a `setEssence` test. `group-message.test.ts` rewritten to target MessageApi.recall* / markRead* methods that were already moved. 587/587 tests pass.
This commit is contained in:
1 parent
c92daa56df
commit
73f1cd3c80
11 files changed
+155
-221
No files matched your search
@@ -1,3 +1,9 @@
|
||||
// MessageApi recall + markRead coverage. (The send* paths live in their
|
||||
// own test file because they need element-builder fixtures the recall
|
||||
// paths don't.) Renamed from the legacy `actions/group-message` shape
|
||||
// after #6 commit 1 moved the recall + markRead helpers onto MessageApi
|
||||
// and #6 commit 6 absorbed setEssence into InteractionApi.
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
@@ -7,25 +13,23 @@ vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
decodeOidbEnv: vi.fn(() => ({ body: {} })),
|
||||
}));
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as msg from '../../src/bridge/actions/group-message';
|
||||
import { MessageApi } from '../../src/bridge/apis/message';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
describe('actions/group-message', () => {
|
||||
describe('apis/message — recall + markRead', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(oidb.runOidb).mockClear();
|
||||
vi.mocked(oidb.makeOidbEnvelope).mockClear();
|
||||
// No global mock state to reset — sendRawPacket is per-bridge.
|
||||
});
|
||||
|
||||
it('recallGroupMessage sends to SsoGroupRecallMsg with the group sequence', async () => {
|
||||
it('recallGroup sends to SsoGroupRecallMsg with the group sequence', async () => {
|
||||
const bridge = mockBridge();
|
||||
await msg.recallGroupMessage(bridge as any, 12345, 999);
|
||||
await new MessageApi(bridge as any).recallGroup(12345, 999);
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
|
||||
const [serviceCmd] = bridge.sendRawPacket.mock.calls[0]!;
|
||||
expect(serviceCmd).toBe('trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg');
|
||||
});
|
||||
|
||||
it('recallGroupMessage throws when sendRawPacket reports failure', async () => {
|
||||
it('recallGroup throws when sendRawPacket reports failure', async () => {
|
||||
const bridge = mockBridge({
|
||||
sendRawPacket: vi.fn(async () => ({
|
||||
success: false,
|
||||
@@ -35,22 +39,23 @@ describe('actions/group-message', () => {
|
||||
responseData: null,
|
||||
})) as any,
|
||||
});
|
||||
await expect(msg.recallGroupMessage(bridge as any, 12345, 999))
|
||||
await expect(new MessageApi(bridge as any).recallGroup(12345, 999))
|
||||
.rejects.toThrow(/network down/);
|
||||
});
|
||||
|
||||
it('recallPrivateMessage resolves the target UID before dispatch', async () => {
|
||||
it('recallPrivate resolves the target UID before dispatch', async () => {
|
||||
const bridge = mockBridge();
|
||||
await msg.recallPrivateMessage(bridge as any, 10001, 100, 200, 123, 1700000000);
|
||||
await new MessageApi(bridge as any).recallPrivate(10001, 100, 200, 123, 1700000000);
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
||||
const [serviceCmd] = bridge.sendRawPacket.mock.calls[0]!;
|
||||
expect(serviceCmd).toBe('trpc.msg.msg_svc.MsgService.SsoC2CRecallMsg');
|
||||
});
|
||||
|
||||
it('markGroupMessageRead and markPrivateMessageRead both hit SsoReadedReport', async () => {
|
||||
it('markGroupRead and markPrivateRead both hit SsoReadedReport', async () => {
|
||||
const bridge = mockBridge();
|
||||
await msg.markGroupMessageRead(bridge as any, 12345, 50);
|
||||
await msg.markPrivateMessageRead(bridge as any, 10001, 60);
|
||||
const api = new MessageApi(bridge as any);
|
||||
await api.markGroupRead(12345, 50);
|
||||
await api.markPrivateRead(10001, 60);
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
|
||||
const cmds = bridge.sendRawPacket.mock.calls.map((c: any) => c[0]);
|
||||
expect(cmds).toEqual([
|
||||
@@ -58,12 +63,4 @@ describe('actions/group-message', () => {
|
||||
'trpc.msg.msg_svc.MsgService.SsoReadedReport',
|
||||
]);
|
||||
});
|
||||
|
||||
it('setGroupEssence picks _1 for enable and _2 for disable', async () => {
|
||||
const bridge = mockBridge();
|
||||
await msg.setGroupEssence(bridge as any, 12345, 5, 7, true);
|
||||
await msg.setGroupEssence(bridge as any, 12345, 5, 7, false);
|
||||
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
|
||||
expect(cmds).toEqual(['OidbSvcTrpcTcp.0xeac_1', 'OidbSvcTrpcTcp.0xeac_2']);
|
||||
});
|
||||
});
|
||||
@@ -22,10 +22,10 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as inter from '../../src/bridge/actions/interaction';
|
||||
import { InteractionApi } from '../../src/bridge/apis/interaction';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
describe('actions/interaction', () => {
|
||||
describe('apis/interaction', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(oidb.runOidb).mockReset();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValue(new Uint8Array());
|
||||
@@ -34,35 +34,45 @@ describe('actions/interaction', () => {
|
||||
|
||||
it('sendPoke group: groupUin set, friendUin=0', async () => {
|
||||
const bridge = mockBridge();
|
||||
await inter.sendPoke(bridge as any, true, 12345, 67890);
|
||||
await new InteractionApi(bridge as any).sendPoke(true, 12345, 67890);
|
||||
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||
expect(body).toMatchObject({ uin: 67890, groupUin: 12345, friendUin: 0 });
|
||||
});
|
||||
|
||||
it('sendPoke friend: friendUin set, groupUin=0, targetUin defaults to peer', async () => {
|
||||
const bridge = mockBridge();
|
||||
await inter.sendPoke(bridge as any, false, 67890);
|
||||
await new InteractionApi(bridge as any).sendPoke(false, 67890);
|
||||
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||
expect(body).toMatchObject({ uin: 67890, groupUin: 0, friendUin: 67890 });
|
||||
});
|
||||
|
||||
it('sendLike forwards target + count to 0x7e5_104', async () => {
|
||||
const bridge = mockBridge();
|
||||
await inter.sendLike(bridge as any, 10001, 3);
|
||||
await new InteractionApi(bridge as any).sendLike(10001, 3);
|
||||
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x7e5_104');
|
||||
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||
expect(body).toMatchObject({ targetUin: 10001, count: 3 });
|
||||
});
|
||||
|
||||
it('setGroupReaction picks _1 for set and _2 for unset', async () => {
|
||||
it('setReaction picks _1 for set and _2 for unset', async () => {
|
||||
const bridge = mockBridge();
|
||||
await inter.setGroupReaction(bridge as any, 12345, 99, '128516', true);
|
||||
await inter.setGroupReaction(bridge as any, 12345, 99, '128516', false);
|
||||
const api = new InteractionApi(bridge as any);
|
||||
await api.setReaction(12345, 99, '128516', true);
|
||||
await api.setReaction(12345, 99, '128516', false);
|
||||
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
|
||||
expect(cmds).toEqual(['OidbSvcTrpcTcp.0x9082_1', 'OidbSvcTrpcTcp.0x9082_2']);
|
||||
});
|
||||
|
||||
it('setEssence picks _1 for enable and _2 for disable', async () => {
|
||||
const bridge = mockBridge();
|
||||
const api = new InteractionApi(bridge as any);
|
||||
await api.setEssence(12345, 99, 0, true);
|
||||
await api.setEssence(12345, 99, 0, false);
|
||||
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
|
||||
expect(cmds).toEqual(['OidbSvcTrpcTcp.0xeac_1', 'OidbSvcTrpcTcp.0xeac_2']);
|
||||
});
|
||||
|
||||
it('getEmojiLikes decodes user list, base64-encodes cookie, and reports isLast', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
@@ -73,7 +83,7 @@ describe('actions/interaction', () => {
|
||||
} as any,
|
||||
}),
|
||||
);
|
||||
const out = await inter.getEmojiLikes(bridge as any, 12345, 99, '128516');
|
||||
const out = await new InteractionApi(bridge as any).getEmojiLikes(12345, 99, '128516');
|
||||
expect(out.users).toEqual([{ uin: 10001 }]);
|
||||
expect(out.cookie).toBe(Buffer.from([0xCA, 0xFE]).toString('base64'));
|
||||
expect(out.isLast).toBe(false);
|
||||
@@ -84,7 +94,7 @@ describe('actions/interaction', () => {
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
protobuf_encode<OidbBase<Oidb0x9083Resp>>({ body: {} }),
|
||||
);
|
||||
const out = await inter.getEmojiLikes(bridge as any, 12345, 99, '128516');
|
||||
const out = await new InteractionApi(bridge as any).getEmojiLikes(12345, 99, '128516');
|
||||
expect(out.users).toEqual([]);
|
||||
expect(out.isLast).toBe(true);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user