Files
SnowLuma/packages/onebot/tests/friend-dress-action.test.ts
TanTan fa9c73363d
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
SnowLuma v2.4.2 source snapshot
2026-11-13 09:02:00 +08:00

44 lines
1.6 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { FriendDressError } from '@snowluma/protocol/web/friend-dress';
import { ApiHandler, type ApiActionContext } from '../src/api-handler';
function makeHandler(getFriendDress: ReturnType<typeof vi.fn>): ApiHandler {
const bridge = { apis: { web: { getFriendDress } } };
return new ApiHandler({ bridge } as unknown as ApiActionContext);
}
describe('_get_friend_dress action', () => {
it('validates the target and returns the queried dress data', async () => {
const dress = {
target_uin: '10000',
is_svip: false,
avatar_url: '',
items: [],
};
const getFriendDress = vi.fn().mockResolvedValue(dress);
const response = await makeHandler(getFriendDress).handle('_get_friend_dress', {
user_id: '10000',
});
expect(response).toMatchObject({ status: 'ok', retcode: 0, data: dress });
expect(getFriendDress).toHaveBeenCalledWith(10000);
});
it('preserves the structured failure kind in the Action response', async () => {
const getFriendDress = vi
.fn()
.mockRejectedValue(
new FriendDressError('uin_mismatch', 'returned account does not match'),
);
const response = await makeHandler(getFriendDress).handle('_get_friend_dress', {
user_id: 10000,
});
expect(response).toMatchObject({ status: 'failed', retcode: 100 });
expect(response.wording).toContain('(uin_mismatch)');
expect(response.wording).toContain('returned account does not match');
});
});