/** * @file Tests for spendPace — the 7-day burn rate, month to date and the * month-end forecast built from the daily cost series. * @author Nguyễn Ngọc Trí Vĩ */ import { describe, expect, it } from "vitest"; import { spendPace } from "../burnRate"; describe("spendPace", () => { it("averages the last 7 days and carries the pace to month end", () => { const daily = [ { date: "2026-09-28", cost: 70 }, // before the 7-day window (09-29..10-05) { date: "2026-09-30", cost: 7 }, // inside the window, last month { date: "2026-10-01", cost: 7 }, { date: "2026-10-05", cost: 14 }, { date: "2026-10-06", cost: 99 }, // after today: ignored ]; const p = spendPace(daily, "2026-10-05"); expect(p.perDay7).toBe(4); // (7 + 7 + 14) / 7 expect(p.monthToDate).toBe(21); expect(p.forecastMonth).toBe(21 + 4 * 26); // 26 days left in October }); it("is all zero with no spend", () => { expect(spendPace([], "2026-02-28")).toEqual({ perDay7: 0, monthToDate: 0, forecastMonth: 0 }); }); });