mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
The per-metric status note quoted glucose in mg/dL, body composition in kg, temperatures in °C and walking distance in metres, whatever the reader had chosen; the deterministic floor without a provider did the same. The generator now converts the series, the reference band and the signal into the reader's units before they reach the prompt or the floor, and prints the guideline band table in that unit while still classifying on the canonical value. A changed glucose unit or metric/imperial preference (own account or a managed record) now re-warms the stored notes and narratives through the hash-gated refill, so today's text does not keep the old unit. Refs #1067
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("@/lib/db", () => ({
|
|
prisma: {
|
|
user: { findUnique: vi.fn() },
|
|
insightNarrative: { findMany: vi.fn() },
|
|
},
|
|
}));
|
|
vi.mock("@/lib/insights/status-invalidation", () => ({
|
|
enqueueStatusRefillForUser: vi.fn(),
|
|
}));
|
|
vi.mock("@/lib/jobs/period-narrative-shared", () => ({
|
|
enqueueNarrativeWarm: vi.fn(),
|
|
}));
|
|
|
|
import { prisma } from "@/lib/db";
|
|
import { enqueueStatusRefillForUser } from "@/lib/insights/status-invalidation";
|
|
import { enqueueNarrativeWarm } from "@/lib/jobs/period-narrative-shared";
|
|
import { refreshTextsAfterUnitChange } from "../unit-change-refresh";
|
|
|
|
beforeEach(() => {
|
|
vi.resetAllMocks();
|
|
});
|
|
|
|
describe("refreshTextsAfterUnitChange", () => {
|
|
it("refills the status cards in the reader's locale and re-warms each stored narrative", async () => {
|
|
vi.mocked(prisma.user.findUnique).mockResolvedValue({
|
|
locale: "de",
|
|
} as never);
|
|
vi.mocked(enqueueStatusRefillForUser).mockResolvedValue(12);
|
|
vi.mocked(prisma.insightNarrative.findMany).mockResolvedValue([
|
|
{ period: "week", locale: "de" },
|
|
{ period: "month", locale: "en" },
|
|
{ period: "year", locale: "de" },
|
|
{ period: "week", locale: "xx" },
|
|
] as never);
|
|
|
|
await refreshTextsAfterUnitChange("user-1");
|
|
|
|
expect(enqueueStatusRefillForUser).toHaveBeenCalledWith("user-1", "de");
|
|
expect(enqueueNarrativeWarm).toHaveBeenCalledTimes(2);
|
|
expect(enqueueNarrativeWarm).toHaveBeenCalledWith({
|
|
userId: "user-1",
|
|
period: "week",
|
|
locale: "de",
|
|
});
|
|
expect(enqueueNarrativeWarm).toHaveBeenCalledWith({
|
|
userId: "user-1",
|
|
period: "month",
|
|
locale: "en",
|
|
});
|
|
});
|
|
|
|
it("never throws into the preference write", async () => {
|
|
vi.mocked(prisma.user.findUnique).mockRejectedValue(new Error("db down"));
|
|
await expect(refreshTextsAfterUnitChange("user-1")).resolves.toBe(
|
|
undefined,
|
|
);
|
|
});
|
|
});
|