52 lines
1.9 KiB
TypeScript
52 lines
1.9 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 when both local and gateway loading fail', async () => {
|
|
rpcMock.mockRejectedValueOnce(new Error('gateway unavailable'));
|
|
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(hostApiFetchMock).toHaveBeenCalledWith('/api/skills/marketplace/search', expect.objectContaining({ method: 'POST' }));
|
|
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');
|
|
expect(hostApiFetchMock).toHaveBeenCalledWith('/api/skills/marketplace/install', expect.objectContaining({ method: 'POST' }));
|
|
});
|
|
});
|