2026-04-18 12:36:29 +09:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
|
|
|
|
|
const { mockGet, mockPost } = vi.hoisted(() => ({
|
|
|
|
|
mockGet: vi.fn(),
|
|
|
|
|
mockPost: 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, post: mockPost },
|
|
|
|
|
}));
|
|
|
|
|
|
2026-05-19 11:06:03 +09:00
|
|
|
import { listFills, getFill, previewFill, executeFill, undoFill } from '../../src/services/organizer';
|
2026-04-18 12:36:29 +09:00
|
|
|
|
|
|
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
|
|
|
|
|
|
describe('organizer service', () => {
|
|
|
|
|
it('listFills with no query', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ data: [] });
|
|
|
|
|
await listFills('hh1');
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith('/households/hh1/organizer/fills');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('listFills builds query string', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ data: [] });
|
|
|
|
|
await listFills('hh1', { regimenId: 'reg-1', status: 'active' });
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('regimenId=reg-1'));
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('status=active'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('listFills with cursor and limit', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ data: [] });
|
|
|
|
|
await listFills('hh1', { cursor: 'cur1', limit: 5 });
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('cursor=cur1'));
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('limit=5'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('getFill calls GET', async () => {
|
|
|
|
|
mockGet.mockResolvedValue({ _id: 'f-1' });
|
|
|
|
|
await getFill('hh1', 'f-1');
|
|
|
|
|
expect(mockGet).toHaveBeenCalledWith('/households/hh1/organizer/fills/f-1');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('previewFill calls POST', async () => {
|
|
|
|
|
mockPost.mockResolvedValue({});
|
|
|
|
|
const data = { regimenId: 'reg-1' } as never;
|
|
|
|
|
await previewFill('hh1', data);
|
|
|
|
|
expect(mockPost).toHaveBeenCalledWith('/households/hh1/organizer/preview', data);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('executeFill calls POST', async () => {
|
|
|
|
|
mockPost.mockResolvedValue({ _id: 'f-1' });
|
|
|
|
|
const data = { regimenId: 'reg-1' } as never;
|
|
|
|
|
await executeFill('hh1', data);
|
|
|
|
|
expect(mockPost).toHaveBeenCalledWith('/households/hh1/organizer/fill', data);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('undoFill calls POST with empty body', async () => {
|
|
|
|
|
mockPost.mockResolvedValue({ _id: 'f-1' });
|
|
|
|
|
await undoFill('hh1', 'f-1');
|
|
|
|
|
expect(mockPost).toHaveBeenCalledWith('/households/hh1/organizer/fills/f-1/undo', {});
|
|
|
|
|
});
|
|
|
|
|
});
|