MeshiTrack/packages/web/tests/services/meal-plans.test.ts

69 lines
2.4 KiB
TypeScript
Raw Normal View History

2026-05-19 10:13:40 +09:00
import { describe, it, expect, vi, beforeEach } from 'vitest';
2026-05-19 11:06:03 +09:00
import { apiClient } from '../../src/services/api-client';
import * as MealPlansService from '../../src/services/meal-plans';
2026-05-19 10:13:40 +09:00
2026-05-19 11:06:03 +09:00
vi.mock('../../src/services/api-client', () => ({
2026-05-19 10:13:40 +09:00
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');
});
});