68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { apiClient } from '../../src/services/api-client';
|
|
import * as MealPlansService from '../../src/services/meal-plans';
|
|
|
|
vi.mock('../../src/services/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');
|
|
});
|
|
});
|