Implement stores and refills, improve testing
This commit is contained in:
parent
9f416903ef
commit
5536acd67d
137 changed files with 21218 additions and 221 deletions
47
packages/web/src/services/__tests__/households.test.ts
Normal file
47
packages/web/src/services/__tests__/households.test.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { mockGet, mockPost, mockPatch } = vi.hoisted(() => ({
|
||||
mockGet: vi.fn(),
|
||||
mockPost: vi.fn(),
|
||||
mockPatch: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../api-client', () => ({
|
||||
apiClient: { get: mockGet, post: mockPost, patch: mockPatch },
|
||||
}));
|
||||
|
||||
import { createHousehold, getHousehold, updateHousehold, generateInviteCode, joinHousehold } from '../households';
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
describe('households service', () => {
|
||||
it('createHousehold calls POST', async () => {
|
||||
mockPost.mockResolvedValue({ _id: 'hh1' });
|
||||
await createHousehold('My Home');
|
||||
expect(mockPost).toHaveBeenCalledWith('/households', { name: 'My Home' });
|
||||
});
|
||||
|
||||
it('getHousehold calls GET', async () => {
|
||||
mockGet.mockResolvedValue({ _id: 'hh1' });
|
||||
await getHousehold('hh1');
|
||||
expect(mockGet).toHaveBeenCalledWith('/households/hh1');
|
||||
});
|
||||
|
||||
it('updateHousehold calls PATCH', async () => {
|
||||
mockPatch.mockResolvedValue({ _id: 'hh1' });
|
||||
await updateHousehold('hh1', { name: 'Updated' });
|
||||
expect(mockPatch).toHaveBeenCalledWith('/households/hh1', { name: 'Updated' });
|
||||
});
|
||||
|
||||
it('generateInviteCode calls POST', async () => {
|
||||
mockPost.mockResolvedValue({ _id: 'hh1' });
|
||||
await generateInviteCode('hh1');
|
||||
expect(mockPost).toHaveBeenCalledWith('/households/hh1/invite');
|
||||
});
|
||||
|
||||
it('joinHousehold calls POST with invite code', async () => {
|
||||
mockPost.mockResolvedValue({ _id: 'hh1' });
|
||||
await joinHousehold('ABC123');
|
||||
expect(mockPost).toHaveBeenCalledWith('/households/join', { inviteCode: 'ABC123' });
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue