Cleanup after initial plan
This commit is contained in:
parent
d2a7e652b3
commit
245520fb50
53 changed files with 6733 additions and 621 deletions
87
packages/web/src/services/shopping-lists.test.ts
Normal file
87
packages/web/src/services/shopping-lists.test.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { apiClient } from './api-client';
|
||||
import * as ShoppingListsService from './shopping-lists';
|
||||
|
||||
vi.mock('./api-client', () => ({
|
||||
apiClient: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
patch: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
baseUrl: 'http://localhost:3001',
|
||||
},
|
||||
}));
|
||||
|
||||
describe('shopping-lists service', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('getShoppingLists', async () => {
|
||||
await ShoppingListsService.getShoppingLists('hh1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/shopping-lists');
|
||||
});
|
||||
|
||||
it('getShoppingList', async () => {
|
||||
await ShoppingListsService.getShoppingList('hh1', 'list1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/shopping-lists/list1');
|
||||
});
|
||||
|
||||
it('createShoppingList', async () => {
|
||||
const data = { name: 'Test' } as any;
|
||||
await ShoppingListsService.createShoppingList('hh1', data);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/shopping-lists', data);
|
||||
});
|
||||
|
||||
it('updateShoppingList', async () => {
|
||||
const data = { name: 'Updated' } as any;
|
||||
await ShoppingListsService.updateShoppingList('hh1', 'list1', data);
|
||||
expect(apiClient.patch).toHaveBeenCalledWith('/households/hh1/shopping-lists/list1', data);
|
||||
});
|
||||
|
||||
it('deleteShoppingList', async () => {
|
||||
await ShoppingListsService.deleteShoppingList('hh1', 'list1');
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/households/hh1/shopping-lists/list1');
|
||||
});
|
||||
|
||||
it('addShoppingItem', async () => {
|
||||
const data = { productId: 'p1' } as any;
|
||||
await ShoppingListsService.addShoppingItem('hh1', 'list1', data);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/shopping-lists/list1/items', data);
|
||||
});
|
||||
|
||||
it('updateShoppingItem', async () => {
|
||||
const data = { checked: true } as any;
|
||||
await ShoppingListsService.updateShoppingItem('hh1', 'list1', 'item1', data);
|
||||
expect(apiClient.patch).toHaveBeenCalledWith('/households/hh1/shopping-lists/list1/items/item1', data);
|
||||
});
|
||||
|
||||
it('removeShoppingItem', async () => {
|
||||
await ShoppingListsService.removeShoppingItem('hh1', 'list1', 'item1');
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/households/hh1/shopping-lists/list1/items/item1');
|
||||
});
|
||||
|
||||
it('generateFromMealPlan', async () => {
|
||||
await ShoppingListsService.generateFromMealPlan('hh1', 'mp1');
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/shopping-lists/from-meal-plan/mp1');
|
||||
});
|
||||
|
||||
it('syncToPantry', async () => {
|
||||
await ShoppingListsService.syncToPantry('hh1', 'list1');
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/shopping-lists/list1/sync-to-pantry');
|
||||
});
|
||||
|
||||
it('getBasketStoreComparison', async () => {
|
||||
await ShoppingListsService.getBasketStoreComparison('hh1', 'list1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/shopping-lists/list1/stores');
|
||||
});
|
||||
|
||||
it('getShoppingListSyncSocketUrl handles insecure and secure contexts', () => {
|
||||
const urlInsecure = ShoppingListsService.getShoppingListSyncSocketUrl('hh1', 'list1');
|
||||
expect(urlInsecure).toBe('ws://localhost:3001/households/hh1/shopping-lists/list1/sync');
|
||||
|
||||
apiClient.baseUrl = 'https://api.meshitrack.com';
|
||||
const urlSecure = ShoppingListsService.getShoppingListSyncSocketUrl('hh1', 'list1');
|
||||
expect(urlSecure).toBe('wss://api.meshitrack.com/households/hh1/shopping-lists/list1/sync');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue