Files
DeskClaw/tests/unit/skills-errors.test.ts
Lingxuan Zuo 3d664c017a refactor(new merge) (#369)
Co-authored-by: paisley <8197966+su8su@users.noreply.github.com>
Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
2026-03-09 20:18:25 +08:00

50 lines
1.6 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
const hostApiFetchMock = vi.fn();
const rpcMock = vi.fn();
vi.mock('@/lib/host-api', () => ({
hostApiFetch: (...args: unknown[]) => hostApiFetchMock(...args),
}));
vi.mock('@/stores/gateway', () => ({
useGatewayStore: {
getState: () => ({
rpc: (...args: unknown[]) => rpcMock(...args),
}),
},
}));
describe('skills store error mapping', () => {
beforeEach(() => {
vi.resetModules();
vi.clearAllMocks();
});
it('maps fetchSkills rate-limit error by AppError code', async () => {
rpcMock.mockResolvedValueOnce({ skills: [] });
hostApiFetchMock.mockRejectedValueOnce(new Error('rate limit exceeded'));
const { useSkillsStore } = await import('@/stores/skills');
await useSkillsStore.getState().fetchSkills();
expect(useSkillsStore.getState().error).toBe('fetchRateLimitError');
});
it('maps searchSkills timeout error by AppError code', async () => {
hostApiFetchMock.mockRejectedValueOnce(new Error('request timeout'));
const { useSkillsStore } = await import('@/stores/skills');
await useSkillsStore.getState().searchSkills('git');
expect(useSkillsStore.getState().searchError).toBe('searchTimeoutError');
});
it('maps installSkill timeout result into installTimeoutError', async () => {
hostApiFetchMock.mockResolvedValueOnce({ success: false, error: 'request timeout' });
const { useSkillsStore } = await import('@/stores/skills');
await expect(useSkillsStore.getState().installSkill('demo-skill')).rejects.toThrow('installTimeoutError');
});
});