import { describe, expect, it } from 'vitest'; import { calculateDailyWeightGain, processDailyWeightData } from '../utils/scaleDataProcessor.ts'; import { ScalePredictionRangeResponse } from '../types.ts'; describe('scaleDataProcessor', () => { it('derives day labels from the cycle date and skips points beyond totalDays', () => { const cycleStartDate = new Date('2026-05-22T00:00:00'); const scaleData: ScalePredictionRangeResponse = { success: true, data: [ { date: '2026-05-22', items: [ { id: 'p1', cage_name: 'Kandang A', age: 1, total_weight_prediction: 0, total_weight_actual: 500, avg_weight_prediction: 0, avg_weight_actual: 50, chicken_count: 10, captured_at: '2026-05-22T00:00:00Z', image_url: '', device: 'dev-1', }, ], }, { date: '2026-05-23', items: [ { id: 'p2', cage_name: 'Kandang A', age: 99, total_weight_prediction: 0, total_weight_actual: 600, avg_weight_prediction: 0, avg_weight_actual: 60, chicken_count: 10, captured_at: '2026-05-23T00:00:00Z', image_url: '', device: 'dev-1', }, ], }, { date: '2026-07-11', items: [ { id: 'p3', cage_name: 'Kandang A', age: 51, total_weight_prediction: 0, total_weight_actual: 1200, avg_weight_prediction: 0, avg_weight_actual: 120, chicken_count: 10, captured_at: '2026-07-11T00:00:00Z', image_url: '', device: 'dev-1', }, ], }, ], }; const dailyWeight = processDailyWeightData(scaleData, cycleStartDate, 42); expect(dailyWeight).toHaveLength(2); expect(dailyWeight.map((point) => point.day)).toEqual([1, 2]); expect(dailyWeight.find((point) => point.day === 2)?.date).toBe('2026-05-23'); const dailyGain = calculateDailyWeightGain(dailyWeight); expect(dailyGain).toHaveLength(1); expect(dailyGain[0]).toMatchObject({ day: 2, gain: 10, date: '2026-05-23', }); }); });