Implement stores and refills, improve testing
This commit is contained in:
parent
9f416903ef
commit
5536acd67d
137 changed files with 21218 additions and 221 deletions
56
packages/web/src/services/__tests__/stores.test.ts
Normal file
56
packages/web/src/services/__tests__/stores.test.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { mockGet, mockPost, mockPatch, mockDelete } = vi.hoisted(() => ({
|
||||
mockGet: vi.fn(),
|
||||
mockPost: vi.fn(),
|
||||
mockPatch: vi.fn(),
|
||||
mockDelete: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../api-client', () => ({
|
||||
apiClient: { get: mockGet, post: mockPost, patch: mockPatch, delete: mockDelete },
|
||||
}));
|
||||
|
||||
import { listStores, getStore, createStore, updateStore, deactivateStore } from '../stores';
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
describe('stores service', () => {
|
||||
it('listStores calls GET with no query', async () => {
|
||||
mockGet.mockResolvedValue({ data: [] });
|
||||
await listStores('hh1');
|
||||
expect(mockGet).toHaveBeenCalledWith('/households/hh1/stores');
|
||||
});
|
||||
|
||||
it('listStores builds query string', async () => {
|
||||
mockGet.mockResolvedValue({ data: [] });
|
||||
await listStores('hh1', { tags: 'pharmacy', search: 'cvs', cursor: 'c1', limit: 5 });
|
||||
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('tags=pharmacy'));
|
||||
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('search=cvs'));
|
||||
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('limit=5'));
|
||||
});
|
||||
|
||||
it('getStore calls GET with id', async () => {
|
||||
mockGet.mockResolvedValue({ _id: 'st-1' });
|
||||
await getStore('hh1', 'st-1');
|
||||
expect(mockGet).toHaveBeenCalledWith('/households/hh1/stores/st-1');
|
||||
});
|
||||
|
||||
it('createStore calls POST', async () => {
|
||||
mockPost.mockResolvedValue({ _id: 'st-1' });
|
||||
await createStore('hh1', { name: 'CVS' } as never);
|
||||
expect(mockPost).toHaveBeenCalledWith('/households/hh1/stores', { name: 'CVS' });
|
||||
});
|
||||
|
||||
it('updateStore calls PATCH', async () => {
|
||||
mockPatch.mockResolvedValue({ _id: 'st-1' });
|
||||
await updateStore('hh1', 'st-1', { name: 'Updated' } as never);
|
||||
expect(mockPatch).toHaveBeenCalledWith('/households/hh1/stores/st-1', { name: 'Updated' });
|
||||
});
|
||||
|
||||
it('deactivateStore calls DELETE', async () => {
|
||||
mockDelete.mockResolvedValue({ _id: 'st-1' });
|
||||
await deactivateStore('hh1', 'st-1');
|
||||
expect(mockDelete).toHaveBeenCalledWith('/households/hh1/stores/st-1');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue