Tests refactor
This commit is contained in:
parent
245520fb50
commit
99134d8556
165 changed files with 911 additions and 531 deletions
62
packages/web/tests/services/organizer.test.ts
Normal file
62
packages/web/tests/services/organizer.test.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { mockGet, mockPost } = vi.hoisted(() => ({
|
||||
mockGet: vi.fn(),
|
||||
mockPost: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/services/api-client', () => ({
|
||||
apiClient: { get: mockGet, post: mockPost },
|
||||
}));
|
||||
|
||||
import { listFills, getFill, previewFill, executeFill, undoFill } from '../../src/services/organizer';
|
||||
|
||||
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', {});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue