2026-04-18 12:36:29 +09:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
|
|
|
|
|
const { mockGet } = vi.hoisted(() => ({
|
|
|
|
|
mockGet: vi.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
2026-05-19 11:06:03 +09:00
|
|
|
vi.mock('../../src/services/api-client', () => ({
|
2026-04-18 12:36:29 +09:00
|
|
|
apiClient: { get: mockGet },
|
|
|
|
|
}));
|
|
|
|
|
|
2026-05-19 11:06:03 +09:00
|
|
|
import { listCabinetEvents, getEventsByItem, getSpendingSummary } from '../../src/services/cabinet-events';
|
2026-04-18 12:36:29 +09:00
|
|
|
|
|
|
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
|
|
|
|
|
|
describe('cabinet-events service', () => {
|
|
|
|
|
it('listCabinetEvents with no query', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ data: [] });
|
|
|
|
|
await listCabinetEvents('hh1');
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith('/households/hh1/cabinet-events');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('listCabinetEvents builds query string', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ data: [] });
|
2026-04-26 18:44:59 +09:00
|
|
|
await listCabinetEvents('hh1', {
|
|
|
|
|
medicineId: 'med-1',
|
|
|
|
|
eventType: 'dispense',
|
|
|
|
|
startDate: '2026-01-01',
|
|
|
|
|
endDate: '2026-02-01',
|
|
|
|
|
});
|
2026-04-18 12:36:29 +09:00
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('medicineId=med-1'));
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('eventType=dispense'));
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('startDate=2026-01-01'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('getEventsByItem builds URL with cabinetItemId', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ data: [] });
|
|
|
|
|
await getEventsByItem('hh1', 'ci-1', { limit: 5 });
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('/cabinet-events/by-item/ci-1'));
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('limit=5'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('listCabinetEvents with cursor and limit', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ data: [] });
|
|
|
|
|
await listCabinetEvents('hh1', { cursor: 'cur1', limit: 10 });
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('cursor=cur1'));
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('limit=10'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('getEventsByItem with cursor', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ data: [] });
|
|
|
|
|
await getEventsByItem('hh1', 'ci-1', { cursor: 'cur2' });
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('cursor=cur2'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('getSpendingSummary with no query', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({});
|
|
|
|
|
await getSpendingSummary('hh1');
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith('/households/hh1/cabinet-events/spending-summary');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('getSpendingSummary builds query string', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({});
|
|
|
|
|
await getSpendingSummary('hh1', { period: 'month', medicineId: 'med-1' });
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('period=month'));
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('medicineId=med-1'));
|
|
|
|
|
});
|
|
|
|
|
});
|