mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
test: derive the glucose import assertions from the shared factor
Two integration assertions carried the import path's own copy of the mmol/L conversion, so unifying the two conversions left them asserting numbers the code no longer produces. They now multiply by the exported factor, which is what the unit tests already do. The reason these were missed before the merge is worth writing down: `pnpm test` does not run tests/integration, and neither the change that unified the factor nor the gate on the integrated branch ran the suite that covers the import path. A literal here re-pins whichever copy of a conversion the caller happened to use when the test was written, so the assertion is derived rather than pinned.
This commit is contained in:
1 parent
6c43514596
commit
2dc3f8984e
1 file changed
+10
-2
@@ -18,6 +18,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { cookieJar } from "./mock-next-headers";
|
||||
import { getPrismaClient, truncateAllTables } from "./setup";
|
||||
|
||||
import { MGDL_PER_MMOL } from "@/lib/glucose";
|
||||
|
||||
const USER = "user-csv-glucose";
|
||||
|
||||
vi.mock("next/headers", async () => {
|
||||
@@ -111,7 +113,10 @@ describe("POST /api/import/csv — contextless glucose (real Postgres)", () => {
|
||||
expect(rows[0].glucoseContext).toBeNull();
|
||||
expect(rows[0].source).toBe("IMPORT");
|
||||
expect(rows[0].unit).toBe("mg/dL");
|
||||
expect(rows[0].value).toBeCloseTo(95.4848, 3);
|
||||
// Derived from the shared factor rather than pinned, for the same reason
|
||||
// as below: a literal here re-pins whichever copy of the conversion the
|
||||
// import path happened to use when it was written.
|
||||
expect(rows[0].value).toBeCloseTo(5.3 * MGDL_PER_MMOL, 3);
|
||||
expect(rows[0].externalId).toBe("sensor-1");
|
||||
expect(rows[0].measuredAt.toISOString()).toBe("2024-04-03T02:15:00.000Z");
|
||||
});
|
||||
@@ -141,7 +146,10 @@ describe("POST /api/import/csv — contextless glucose (real Postgres)", () => {
|
||||
});
|
||||
expect(rows).toHaveLength(1);
|
||||
expect(rows[0].glucoseContext).toBeNull();
|
||||
expect(rows[0].value).toBeCloseTo(106.2944, 3);
|
||||
// Derived, not pinned: this carried the import path's own copy of the
|
||||
// conversion factor, so unifying the two conversions left it asserting a
|
||||
// number the code no longer produces.
|
||||
expect(rows[0].value).toBeCloseTo(5.9 * MGDL_PER_MMOL, 3);
|
||||
});
|
||||
|
||||
it("keeps a named context, and still refuses one that is not in the enum", async () => {
|
||||
|
||||
Reference in new issue
Block a user