Add centralized API client with axios interceptors, remove vue-axios
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,18 +5,19 @@ vi.mock('@/module/apiError.js', () => ({
|
||||
default: vi.fn(),
|
||||
}));
|
||||
|
||||
const { mockGet } = vi.hoisted(() => ({ mockGet: vi.fn() }));
|
||||
vi.mock('@/api/client.js', () => ({
|
||||
default: { get: mockGet },
|
||||
}));
|
||||
|
||||
import usePerformanceStore from '@/stores/performance.js';
|
||||
|
||||
describe('performanceStore', () => {
|
||||
let store;
|
||||
const mockAxios = {
|
||||
get: vi.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
store = usePerformanceStore();
|
||||
store.$axios = mockAxios;
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
@@ -33,28 +34,28 @@ describe('performanceStore', () => {
|
||||
describe('getPerformance', () => {
|
||||
it('fetches log performance data', async () => {
|
||||
const mockData = { time: { charts: [] }, freq: { charts: [] } };
|
||||
mockAxios.get.mockResolvedValue({ data: mockData });
|
||||
mockGet.mockResolvedValue({ data: mockData });
|
||||
|
||||
await store.getPerformance('log', 1);
|
||||
|
||||
expect(mockAxios.get).toHaveBeenCalledWith(
|
||||
expect(mockGet).toHaveBeenCalledWith(
|
||||
'/api/logs/1/performance',
|
||||
);
|
||||
expect(store.allPerformanceData).toEqual(mockData);
|
||||
});
|
||||
|
||||
it('fetches filter performance data', async () => {
|
||||
mockAxios.get.mockResolvedValue({ data: { time: {} } });
|
||||
mockGet.mockResolvedValue({ data: { time: {} } });
|
||||
|
||||
await store.getPerformance('filter', 5);
|
||||
|
||||
expect(mockAxios.get).toHaveBeenCalledWith(
|
||||
expect(mockGet).toHaveBeenCalledWith(
|
||||
'/api/filters/5/performance',
|
||||
);
|
||||
});
|
||||
|
||||
it('does not throw on API failure', async () => {
|
||||
mockAxios.get.mockRejectedValue(new Error('Network error'));
|
||||
mockGet.mockRejectedValue(new Error('Network error'));
|
||||
|
||||
// Should not throw - apiError handles it
|
||||
await expect(store.getPerformance('log', 1))
|
||||
|
||||
Reference in New Issue
Block a user