refactor(new merge) (#369)

Co-authored-by: paisley <8197966+su8su@users.noreply.github.com>
Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
This commit is contained in:
Lingxuan Zuo
2026-03-09 20:18:25 +08:00
committed by GitHub
Unverified
parent e28eba01e1
commit 3d664c017a
18 changed files with 514 additions and 390 deletions

View File

@@ -0,0 +1,49 @@
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');
});
});