mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
The check that keeps an earlier day's briefing off the Today surfaces read the cache row's insightsCachedAt. Every warm moves that column, including the unchanged-hash short-circuit that keeps yesterday's text and only refreshes the stamp, so text written the day before passed as today's after the nightly warm. The cached payload now carries briefingGeneratedAt, written only where new text is written: a full generation in the warm and in the on-demand route, and the daily paragraph re-roll. The stamp refresh leaves it untouched. briefingForToday reads that moment, and a payload without it counts as not from today, so the hero falls back to its own lead until the next generation.
28 lines
907 B
TypeScript
28 lines
907 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
readBriefingGeneratedAt,
|
|
withBriefingGeneratedAt,
|
|
} from "@/lib/insights/briefing-generated-at";
|
|
|
|
describe("briefing generation moment", () => {
|
|
it("round-trips through the stored JSON text", () => {
|
|
const at = new Date("2026-10-05T04:30:00.000Z");
|
|
const text = JSON.stringify(
|
|
withBriefingGeneratedAt({ dailyBriefing: { paragraph: "x" } }, at),
|
|
);
|
|
expect(readBriefingGeneratedAt(text)).toBe(at.toISOString());
|
|
});
|
|
|
|
it("is unknown for a payload that predates it, or does not parse", () => {
|
|
expect(readBriefingGeneratedAt(JSON.stringify({ dailyBriefing: {} }))).toBe(
|
|
null,
|
|
);
|
|
expect(readBriefingGeneratedAt("not json")).toBeNull();
|
|
expect(readBriefingGeneratedAt(null)).toBeNull();
|
|
expect(
|
|
readBriefingGeneratedAt({ briefingGeneratedAt: "yesterday-ish" }),
|
|
).toBeNull();
|
|
});
|
|
});
|