feat(onebot): support moving friends between categories
Add the set_friends_category action with either an existing category ID or an exact unique category name. Validate the current friend and category roster before applying a change, reject missing or ambiguous targets, and surface failed updates instead of reporting false success. Expose the action through the SDK types and cover validation, successful updates, repeat requests, service rejection, and registry completeness. Closes #297
This commit is contained in:
10 files changed
+429
-3
No files matched your search
@@ -90,9 +90,9 @@ describe('compileActionRegistry namespace conflicts', () => {
|
||||
});
|
||||
|
||||
describe('compiled production Action registry', () => {
|
||||
it('preserves all 180 canonical Action docs', () => {
|
||||
expect(ACTION_REGISTRY.actions).toHaveLength(180);
|
||||
expect(collectActionDocs()).toHaveLength(180);
|
||||
it('preserves all 181 canonical Action docs', () => {
|
||||
expect(ACTION_REGISTRY.actions).toHaveLength(181);
|
||||
expect(collectActionDocs()).toHaveLength(181);
|
||||
});
|
||||
|
||||
it('resolves every executable name to exactly one canonical doc', () => {
|
||||
|
||||
@@ -38,6 +38,7 @@ function fakeMeta(overrides: Partial<MessageMeta> = {}): MessageMeta {
|
||||
const APIS_ROUTING: Record<string, [string, string]> = {
|
||||
fetchFriendList: ['contacts', 'fetchFriendList'],
|
||||
fetchFriendCategories: ['contacts', 'fetchFriendCategories'],
|
||||
setFriendCategory: ['contacts', 'setFriendCategory'],
|
||||
fetchGroupList: ['contacts', 'fetchGroupList'],
|
||||
fetchGroupMemberList: ['contacts', 'fetchGroupMemberList'],
|
||||
fetchUserProfile: ['contacts', 'fetchUserProfile'],
|
||||
@@ -265,6 +266,72 @@ describe('extended-actions / get_friends_with_category', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('extended-actions / set_friends_category', () => {
|
||||
it('moves a friend by category ID', async () => {
|
||||
const setFriendCategory = vi.fn(async () => undefined);
|
||||
const bridge = fakeBridge({ setFriendCategory });
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge))
|
||||
.handle('set_friends_category', { uin: 10001, categoryId: 7 });
|
||||
|
||||
expect(response).toMatchObject({ status: 'ok', retcode: 0, data: null });
|
||||
expect(setFriendCategory).toHaveBeenCalledWith({
|
||||
uin: 10001,
|
||||
categoryId: 7,
|
||||
categoryName: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('moves a friend by an exact category name', async () => {
|
||||
const setFriendCategory = vi.fn(async () => undefined);
|
||||
const bridge = fakeBridge({ setFriendCategory });
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge))
|
||||
.handle('set_friends_category', { uin: 10001, categoryName: 'Work' });
|
||||
|
||||
expect(response).toMatchObject({ status: 'ok', retcode: 0, data: null });
|
||||
expect(setFriendCategory).toHaveBeenCalledWith({
|
||||
uin: 10001,
|
||||
categoryId: undefined,
|
||||
categoryName: 'Work',
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects missing or conflicting category selectors before calling QQ', async () => {
|
||||
const setFriendCategory = vi.fn(async () => undefined);
|
||||
const bridge = fakeBridge({ setFriendCategory });
|
||||
const handler = makeHandler(fakeCtx(bridge));
|
||||
|
||||
const missing = await handler.handle('set_friends_category', { uin: 10001 });
|
||||
const conflicting = await handler.handle('set_friends_category', {
|
||||
uin: 10001,
|
||||
categoryId: 7,
|
||||
categoryName: 'Work',
|
||||
});
|
||||
|
||||
expect(missing).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
expect(conflicting).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
expect(setFriendCategory).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('surfaces roster or server failures instead of reporting success', async () => {
|
||||
const bridge = fakeBridge({
|
||||
setFriendCategory: vi.fn(async () => {
|
||||
throw new Error('friend 10001 is not in the live roster');
|
||||
}),
|
||||
});
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge))
|
||||
.handle('set_friends_category', { uin: 10001, categoryId: 7 });
|
||||
|
||||
expect(response).toMatchObject({
|
||||
status: 'failed',
|
||||
retcode: 100,
|
||||
wording: 'friend 10001 is not in the live roster',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Tier 1: send_packet / .send_packet ───
|
||||
|
||||
describe('extended-actions / send_packet', () => {
|
||||
|
||||
Reference in new issue
Block a user