MeshiTrack/packages/web/src/services/prices.test.ts

55 lines
1.7 KiB
TypeScript
Raw Normal View History

2026-05-19 10:13:40 +09:00
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { apiClient } from './api-client';
import * as PricesService from './prices';
vi.mock('./api-client', () => ({
apiClient: {
get: vi.fn(),
post: vi.fn(),
},
}));
describe('prices service', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('recordPrice', async () => {
const data = { productId: 'p1', price: 10 } as any;
await PricesService.recordPrice('hh1', data);
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/prices', data);
});
it('recordBulkPrices', async () => {
const data = { storeId: 's1', items: [] } as any;
await PricesService.recordBulkPrices('hh1', data);
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/prices/bulk', data);
});
it('getPriceHistory with and without query', async () => {
await PricesService.getPriceHistory('hh1', 'p1');
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/prices/history/p1');
await PricesService.getPriceHistory('hh1', 'p1', {
storeId: 's1',
startDate: '2026-05-01',
endDate: '2026-05-10',
cursor: 'cur',
limit: 10,
});
expect(apiClient.get).toHaveBeenCalledWith(
'/households/hh1/prices/history/p1?storeId=s1&startDate=2026-05-01&endDate=2026-05-10&cursor=cur&limit=10'
);
});
it('compareStores', async () => {
await PricesService.compareStores('hh1', 'p1');
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/prices/compare/p1');
});
it('getPriceAnalytics', async () => {
await PricesService.getPriceAnalytics('hh1');
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/prices/analytics');
});
});