/* eslint-env jest */ import { loadHomeWeek } from '../load-week'; import { getWeeklyReport, listArticles, listBrands, listScans, } from '../../../../service/visibility/visibility.service'; jest.mock('../../../../service/visibility/visibility.service', () => ({ getWeeklyReport: jest.fn(), listArticles: jest.fn(), listBrands: jest.fn(), listScans: jest.fn(), })); const point = (week_iso: string, visibility_score: number) => ({ week_iso, visibility_score, }); describe('loadHomeWeek', () => { beforeEach(() => { (listBrands as jest.Mock).mockResolvedValue({ brands: [{ brand_id: 'b1' }], }); (listScans as jest.Mock).mockResolvedValue({ history: [point('2026-W37', 18), point('2026-W38', 23)], }); (listArticles as jest.Mock).mockResolvedValue({ articles: [{ article_id: 'a1' }], }); }); it('keeps the scans and the content when this week has no report yet', async () => { (getWeeklyReport as jest.Mock).mockRejectedValue( new Error('Weekly report not found') ); const week = await loadHomeWeek('client', 'token'); expect(week?.report).toBeNull(); expect(week?.scans.map(scan => scan.week_iso)).toEqual([ '2026-W38', '2026-W37', ]); expect(week?.articles).toHaveLength(1); }); it('reads nothing without a brand', async () => { (listBrands as jest.Mock).mockResolvedValue({ brands: [] }); expect(await loadHomeWeek('client', 'token')).toBeNull(); }); });