34 files changed
+2427
-211
No files matched your search
@@ -180,6 +180,69 @@ function makeGroupRequest(overrides: Partial<GroupRequestInfo> = {}): GroupReque
|
||||
};
|
||||
}
|
||||
|
||||
describe('public contact profile output', () => {
|
||||
const profile = {
|
||||
sign: '',
|
||||
age: 0,
|
||||
level: 0,
|
||||
sex: 'unknown' as const,
|
||||
vipFlag: false,
|
||||
svipFlag: false,
|
||||
country: 'CN',
|
||||
city: 'City',
|
||||
email: '',
|
||||
birthdayMonth: 2,
|
||||
birthdayDay: 29,
|
||||
privilegeIcons: {
|
||||
open: [{ type: 1, iconUrl: 'normal', deluxeIconUrl: 'deluxe' }],
|
||||
closed: [],
|
||||
},
|
||||
};
|
||||
const expected = {
|
||||
long_nick: '',
|
||||
age: 0,
|
||||
level: 0,
|
||||
sex: 'unknown',
|
||||
is_qq_vip: false,
|
||||
is_vip: false,
|
||||
country: 'CN',
|
||||
city: 'City',
|
||||
email: '',
|
||||
birthday_month: 2,
|
||||
birthday_day: 29,
|
||||
privilege_icons: {
|
||||
open: [{ type: 1, icon_url: 'normal', deluxe_icon_url: 'deluxe' }],
|
||||
closed: [],
|
||||
},
|
||||
};
|
||||
|
||||
it('returns the same public fields for friends and stranger profiles without invented values', async () => {
|
||||
const fetchFriendList = vi.fn(async () => [
|
||||
{ ...makeFriend(123, 'Name'), categoryId: 0, profile },
|
||||
]);
|
||||
const bridge = fakeBridge({
|
||||
fetchFriendList,
|
||||
fetchUserProfile: vi.fn(async () => ({ ...makeProfile(123, 'Name'), profile })),
|
||||
});
|
||||
const friends = await getFriendList(bridge, true);
|
||||
expect(friends[0]).toMatchObject({ user_id: 123, category_id: 0, ...expected });
|
||||
expect(friends[0]).not.toHaveProperty('phone_num');
|
||||
expect(friends[0]).not.toHaveProperty('birthday_year');
|
||||
expect(fetchFriendList).toHaveBeenCalledWith({ withProfile: true });
|
||||
expect(await getStrangerInfo(bridge, 123)).toMatchObject(expected);
|
||||
});
|
||||
|
||||
it('does not mask explicit enrichment failures with cached friends', async () => {
|
||||
const bridge = fakeBridge({
|
||||
fetchFriendList: vi.fn().mockRejectedValue(new Error('profile failed')),
|
||||
identity: fakeIdentity({ friends: [makeFriend(123, 'Cached')] }),
|
||||
});
|
||||
await expect(getFriendList(bridge, true)).rejects.toThrow('profile failed');
|
||||
// The legacy ordinary-list cache behavior remains available.
|
||||
expect((await getFriendList(bridge))[0]?.nickname).toBe('Cached');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Tests ───
|
||||
|
||||
describe('onebot/contact-actions / getLoginInfo', () => {
|
||||
|
||||
@@ -828,6 +828,56 @@ describe('extended-actions / get_essence_msg_list', () => {
|
||||
});
|
||||
|
||||
describe('extended-actions / get_friends_with_category', () => {
|
||||
it('forwards explicit enrichment and uses the same public field names', async () => {
|
||||
const fetchFriendCategories = vi.fn(async () => [
|
||||
{
|
||||
categoryId: 0,
|
||||
categoryName: 'Friends',
|
||||
memberCount: 1,
|
||||
sortId: 0,
|
||||
friends: [
|
||||
{
|
||||
uin: 10001,
|
||||
uid: 'u1',
|
||||
nickname: 'Name',
|
||||
remark: '',
|
||||
profile: {
|
||||
sign: '',
|
||||
age: 0,
|
||||
vipFlag: false,
|
||||
privilegeIcons: { open: [], closed: [] },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
const handler = makeHandler(fakeCtx(fakeBridge({ fetchFriendCategories })));
|
||||
expect(
|
||||
await handler.handle('get_friends_with_category', { with_profile: true }),
|
||||
).toMatchObject({
|
||||
status: 'ok',
|
||||
data: [
|
||||
{
|
||||
buddyList: [
|
||||
{
|
||||
user_id: 10001,
|
||||
category_id: 0,
|
||||
long_nick: '',
|
||||
age: 0,
|
||||
is_qq_vip: false,
|
||||
privilege_icons: { open: [], closed: [] },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(fetchFriendCategories).toHaveBeenCalledWith({ withProfile: true });
|
||||
expect(
|
||||
await handler.handle('get_friends_with_category', { with_profile: 'invalid' }),
|
||||
).toMatchObject({ status: 'failed' });
|
||||
expect(fetchFriendCategories).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('returns the exact categorized friend contract', async () => {
|
||||
const fetchFriendCategories = vi.fn(async () => [
|
||||
{
|
||||
@@ -848,7 +898,7 @@ describe('extended-actions / get_friends_with_category', () => {
|
||||
categoryId: 7,
|
||||
categoryName: 'Work',
|
||||
categoryMbCount: 1,
|
||||
buddyList: [{ user_id: 10001, nickname: 'Alice', remark: 'A' }],
|
||||
buddyList: [{ user_id: 10001, nickname: 'Alice', remark: 'A', category_id: 7 }],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { ApiActionContext } from '../src/api-handler';
|
||||
import { actions } from '../src/actions/friend';
|
||||
|
||||
const getStrangerInfo = actions.find((action) => action.names[0] === 'get_stranger_info');
|
||||
|
||||
describe('get_friend_list profile option', () => {
|
||||
it('defaults off, validates the option and forwards explicit enrichment', async () => {
|
||||
const action = actions.find((entry) => entry.names[0] === 'get_friend_list')!;
|
||||
const getFriendList = vi.fn(async () => []);
|
||||
const handler = action.toHandler({ getFriendList } as unknown as ApiActionContext);
|
||||
await handler({});
|
||||
expect(getFriendList).toHaveBeenLastCalledWith(false);
|
||||
await handler({ with_profile: true });
|
||||
expect(getFriendList).toHaveBeenLastCalledWith(true);
|
||||
expect(await handler({ with_profile: 'invalid' })).toMatchObject({ status: 'failed' });
|
||||
expect(getFriendList).toHaveBeenCalledTimes(2);
|
||||
expect(
|
||||
await action.toHandler({} as ApiActionContext)({ with_profile: true }),
|
||||
).toMatchObject({ status: 'failed', wording: 'friend profile provider unavailable' });
|
||||
});
|
||||
});
|
||||
|
||||
if (!getStrangerInfo) {
|
||||
throw new Error('get_stranger_info action missing');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { actionParams } from '../../sdk/tests/fixtures/action-contracts';
|
||||
import { actions as extended } from '../src/actions/extended';
|
||||
import { actions as friend } from '../src/actions/friend';
|
||||
import { actions as albums } from '../src/actions/group-album';
|
||||
import { actions as groupAdmin } from '../src/actions/group-admin';
|
||||
import { actions as qzone } from '../src/actions/qzone';
|
||||
@@ -9,6 +10,7 @@ import { actions as streamDownload } from '../src/actions/stream-download';
|
||||
import { actions as streamFile } from '../src/actions/stream-file';
|
||||
|
||||
const actions = [
|
||||
...friend,
|
||||
...extended,
|
||||
...albums,
|
||||
...groupAdmin,
|
||||
|
||||
Reference in new issue
Block a user