Third of 13 commits. Folds the previous `actions/group-admin.ts`
plus the matching Bridge facade methods into a typed `apis.groupAdmin`
hub.
Methods (14, all renamed to drop the redundant `Group` prefix once
the `apis.groupAdmin` namespace makes it implicit):
muteGroupMember → apis.groupAdmin.muteMember
muteGroupAll → apis.groupAdmin.muteAll
setGroupAddOption → apis.groupAdmin.setAddOption
setGroupSearch → apis.groupAdmin.setSearch
setGroupAddRequest → apis.groupAdmin.setAddRequest
kickGroupMember → apis.groupAdmin.kickMember
kickGroupMembers → apis.groupAdmin.kickMembers
leaveGroup → apis.groupAdmin.leave
setGroupAdmin → apis.groupAdmin.setAdmin
setGroupCard → apis.groupAdmin.setCard
setGroupName → apis.groupAdmin.setName
setGroupSpecialTitle→ apis.groupAdmin.setSpecialTitle
setGroupRemark → apis.groupAdmin.setRemark
getGroupAtAllRemain → apis.groupAdmin.getAtAllRemain
actions/group-admin.ts deleted. The corresponding `*_` alias imports
and `async xxx() { return xxx_(this, …); }` delegate methods on
Bridge are gone.
Caller updates
--------------
* onebot/instance-context.ts — 6 sites (the multi-method binding for
the OneBot action layer).
* onebot/actions/extended.ts — 8 sites including `getAtAllRemain`.
* onebot/actions/group-admin.ts — all 6 onebot action handlers.
* onebot/modules/request-actions.ts — `setGroupAddRequest`.
Test updates
------------
* tests/actions/group-admin.test.ts — was importing the deleted
`* as admin` module and calling `admin.muteGroupMember(bridge, ...)`.
Switched to `new GroupAdminApi(bridge as any).muteMember(...)` —
same wire validation, just constructs the real Api class once per
call (the Api is stateless so it's effectively free).
* tests/onebot/request-actions.test.ts — was stubbing
`setGroupAddRequest` flat on bridge. Updated to
`apis: { groupAdmin: { setAddRequest } } as any`.
Tests: 587/587 pass (network-manager native-addon failure unchanged).
84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { handleGroupAddRequest } from '../../src/onebot/modules/request-actions';
|
|
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
|
|
import type { GroupRequestInfo } from '../../src/bridge/qq-info';
|
|
|
|
// See `contact-actions.test.ts` for the auto-promotion rationale.
|
|
const APIS_ROUTING: Record<string, string> = {
|
|
fetchFriendList: 'contacts', fetchGroupList: 'contacts',
|
|
fetchGroupMemberList: 'contacts', fetchUserProfile: 'contacts',
|
|
fetchGroupRequests: 'contacts', fetchDownloadRKeys: 'contacts',
|
|
};
|
|
|
|
function fakeBridge(overrides: Record<string, any> = {}): BridgeInterface {
|
|
const apisSynth: Record<string, Record<string, any>> = {};
|
|
for (const [k, v] of Object.entries(overrides)) {
|
|
const area = APIS_ROUTING[k];
|
|
if (area) {
|
|
if (!apisSynth[area]) apisSynth[area] = {};
|
|
apisSynth[area][k] = v;
|
|
}
|
|
}
|
|
const merged = { ...overrides, apis: { ...apisSynth, ...(overrides.apis ?? {}) } };
|
|
return new Proxy(merged as BridgeInterface, {
|
|
get(target, prop) {
|
|
if (prop in target) return (target as any)[prop];
|
|
throw new Error(`fakeBridge: '${String(prop)}' was not stubbed`);
|
|
},
|
|
});
|
|
}
|
|
|
|
function fakeRequest(overrides: Partial<GroupRequestInfo> = {}): GroupRequestInfo {
|
|
return {
|
|
groupId: 999,
|
|
groupName: 'g',
|
|
targetUid: 'u_t',
|
|
targetUin: 5555,
|
|
targetName: 'target',
|
|
invitorUid: 'u_i',
|
|
invitorUin: 7777,
|
|
invitorName: 'inviter',
|
|
operatorUid: 'u_o',
|
|
operatorUin: 8888,
|
|
operatorName: 'op',
|
|
sequence: 42,
|
|
state: 1,
|
|
eventType: 7,
|
|
comment: 'pls',
|
|
filtered: false,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('onebot/modules/request-actions / handleGroupAddRequest', () => {
|
|
it('matches add requests by groupId and targetUid', async () => {
|
|
const setAddRequest = vi.fn(async () => {});
|
|
const bridge = fakeBridge({
|
|
fetchGroupRequests: vi.fn(async () => [
|
|
fakeRequest({ groupId: 999, targetUid: 'u_t', sequence: 42, eventType: 7, filtered: false }),
|
|
]),
|
|
apis: { groupAdmin: { setAddRequest } } as any,
|
|
});
|
|
|
|
await handleGroupAddRequest(bridge, 'add:999:u_t', true, 'ok');
|
|
|
|
expect(setAddRequest).toHaveBeenCalledOnce();
|
|
expect(setAddRequest).toHaveBeenCalledWith(999, 42, 7, true, 'ok', false);
|
|
});
|
|
|
|
it('matches invite requests by groupId and invitorUid', async () => {
|
|
const setAddRequest = vi.fn(async () => {});
|
|
const bridge = fakeBridge({
|
|
fetchGroupRequests: vi.fn(async () => [
|
|
fakeRequest({ groupId: 999, invitorUid: 'u_i', sequence: 97, eventType: 8, filtered: false }),
|
|
]),
|
|
apis: { groupAdmin: { setAddRequest } } as any,
|
|
});
|
|
|
|
await handleGroupAddRequest(bridge, 'invite:999:u_i', false, 'no');
|
|
|
|
expect(setAddRequest).toHaveBeenCalledOnce();
|
|
expect(setAddRequest).toHaveBeenCalledWith(999, 97, 8, false, 'no', false);
|
|
});
|
|
});
|