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 NutritionTargetsService from '../../src/services/nutrition-targets';
|
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(),
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
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' });
|
|
|
|
|
});
|
|
|
|
|
});
|