Cleanup after initial plan
This commit is contained in:
parent
d2a7e652b3
commit
245520fb50
53 changed files with 6733 additions and 621 deletions
68
packages/web/src/services/meal-plans.test.ts
Normal file
68
packages/web/src/services/meal-plans.test.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { apiClient } from './api-client';
|
||||
import * as MealPlansService from './meal-plans';
|
||||
|
||||
vi.mock('./api-client', () => ({
|
||||
apiClient: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
patch: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('meal-plans service', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('listMealPlans with and without query', async () => {
|
||||
await MealPlansService.listMealPlans('hh1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/meal-plans');
|
||||
|
||||
await MealPlansService.listMealPlans('hh1', { cursor: 'cur', limit: 10 });
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/meal-plans?cursor=cur&limit=10');
|
||||
});
|
||||
|
||||
it('getMealPlanByWeek', async () => {
|
||||
await MealPlansService.getMealPlanByWeek('hh1', '2026-05-10');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/meal-plans/week/2026-05-10');
|
||||
});
|
||||
|
||||
it('getMealPlan', async () => {
|
||||
await MealPlansService.getMealPlan('hh1', 'mp1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/meal-plans/mp1');
|
||||
});
|
||||
|
||||
it('createMealPlan', async () => {
|
||||
const data = { weekStartDate: '2026-05-10' } as any;
|
||||
await MealPlansService.createMealPlan('hh1', data);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/meal-plans', data);
|
||||
});
|
||||
|
||||
it('updateMealPlan', async () => {
|
||||
const data = { days: [] } as any;
|
||||
await MealPlansService.updateMealPlan('hh1', 'mp1', data);
|
||||
expect(apiClient.patch).toHaveBeenCalledWith('/households/hh1/meal-plans/mp1', data);
|
||||
});
|
||||
|
||||
it('updateMealPlanStatus', async () => {
|
||||
await MealPlansService.updateMealPlanStatus('hh1', 'mp1', 'active' as any);
|
||||
expect(apiClient.patch).toHaveBeenCalledWith('/households/hh1/meal-plans/mp1/status', { status: 'active' });
|
||||
});
|
||||
|
||||
it('deleteMealPlan', async () => {
|
||||
await MealPlansService.deleteMealPlan('hh1', 'mp1');
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/households/hh1/meal-plans/mp1');
|
||||
});
|
||||
|
||||
it('getSuggestions', async () => {
|
||||
await MealPlansService.getSuggestions('hh1', 3);
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/meal-plans/suggestions?limit=3');
|
||||
});
|
||||
|
||||
it('getShoppingGap', async () => {
|
||||
await MealPlansService.getShoppingGap('hh1', 'mp1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/meal-plans/mp1/gap');
|
||||
});
|
||||
});
|
||||
37
packages/web/src/services/nutrition-targets.test.ts
Normal file
37
packages/web/src/services/nutrition-targets.test.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { apiClient } from './api-client';
|
||||
import * as NutritionTargetsService from './nutrition-targets';
|
||||
|
||||
vi.mock('./api-client', () => ({
|
||||
apiClient: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('nutrition-targets service', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('getActiveNutritionTarget', async () => {
|
||||
await NutritionTargetsService.getActiveNutritionTarget('hh1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/nutrition-targets');
|
||||
});
|
||||
|
||||
it('getNutritionTargetHistory', async () => {
|
||||
await NutritionTargetsService.getNutritionTargetHistory('hh1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/nutrition-targets/history');
|
||||
});
|
||||
|
||||
it('setNutritionTarget', async () => {
|
||||
const data = { calories: 2000 } as any;
|
||||
await NutritionTargetsService.setNutritionTarget('hh1', data);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/nutrition-targets', data);
|
||||
});
|
||||
|
||||
it('calculateTargetPreset', async () => {
|
||||
await NutritionTargetsService.calculateTargetPreset('hh1', 2500, 'gain');
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/nutrition-targets/presets', { calories: 2500, strategy: 'gain' });
|
||||
});
|
||||
});
|
||||
54
packages/web/src/services/prices.test.ts
Normal file
54
packages/web/src/services/prices.test.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { apiClient } from './api-client';
|
||||
import * as PricesService from './prices';
|
||||
|
||||
vi.mock('./api-client', () => ({
|
||||
apiClient: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('prices service', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('recordPrice', async () => {
|
||||
const data = { productId: 'p1', price: 10 } as any;
|
||||
await PricesService.recordPrice('hh1', data);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/prices', data);
|
||||
});
|
||||
|
||||
it('recordBulkPrices', async () => {
|
||||
const data = { storeId: 's1', items: [] } as any;
|
||||
await PricesService.recordBulkPrices('hh1', data);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/households/hh1/prices/bulk', data);
|
||||
});
|
||||
|
||||
it('getPriceHistory with and without query', async () => {
|
||||
await PricesService.getPriceHistory('hh1', 'p1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/prices/history/p1');
|
||||
|
||||
await PricesService.getPriceHistory('hh1', 'p1', {
|
||||
storeId: 's1',
|
||||
startDate: '2026-05-01',
|
||||
endDate: '2026-05-10',
|
||||
cursor: 'cur',
|
||||
limit: 10,
|
||||
});
|
||||
expect(apiClient.get).toHaveBeenCalledWith(
|
||||
'/households/hh1/prices/history/p1?storeId=s1&startDate=2026-05-01&endDate=2026-05-10&cursor=cur&limit=10'
|
||||
);
|
||||
});
|
||||
|
||||
it('compareStores', async () => {
|
||||
await PricesService.compareStores('hh1', 'p1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/prices/compare/p1');
|
||||
});
|
||||
|
||||
it('getPriceAnalytics', async () => {
|
||||
await PricesService.getPriceAnalytics('hh1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/households/hh1/prices/analytics');
|
||||
});
|
||||
});
|
||||
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