mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
test: name the shared glucose factor where the CSV import pinned the old one
Three assertions repeated 18.016 and the product it gave. They were the reason the two factors could sit in the tree at once looking correct. They take the exported constant now, and the parser test asserts the round trip a reader on mmol/L experiences rather than a magic product.
This commit is contained in:
1 parent
9e47b47b00
commit
4cb15232a2
2 files changed
+10
-3
No files matched your search
@@ -59,6 +59,7 @@ vi.mock("@/lib/rollups/measurement-rollups", async () => {
|
||||
|
||||
import { NextRequest } from "next/server";
|
||||
import { POST } from "../route";
|
||||
import { MGDL_PER_MMOL } from "@/lib/glucose";
|
||||
import { checkRateLimit } from "@/lib/rate-limit";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { recomputeBucketsForMeasurement } from "@/lib/rollups/measurement-rollups";
|
||||
@@ -369,7 +370,7 @@ describe("POST /api/import/csv — contextless blood glucose", () => {
|
||||
externalId: "sensor-1",
|
||||
glucoseContext: null,
|
||||
});
|
||||
expect(row.value).toBeCloseTo(95.4848, 3);
|
||||
expect(row.value).toBeCloseTo(5.3 * MGDL_PER_MMOL, 3);
|
||||
expect((row.measuredAt as Date).toISOString()).toBe(
|
||||
"2024-04-03T02:15:00.000Z",
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { MGDL_PER_MMOL, mgdlToMmol } from "@/lib/glucose";
|
||||
|
||||
import {
|
||||
parseCsvMeasurements,
|
||||
@@ -98,7 +99,12 @@ describe("parseCsvMeasurements — unit conversion", () => {
|
||||
]);
|
||||
expect(out.rows[0].status).toBe("ok");
|
||||
expect(out.rows[0].row?.unit).toBe("mg/dL");
|
||||
expect(out.rows[0].row?.value).toBeCloseTo(5.3 * 18.016, 3);
|
||||
// The one factor the app converts glucose by, both directions. The
|
||||
// literal that used to sit here was 18.016 while every display path
|
||||
// divided by 18.0182, so a reading imported in mmol/L did not read back
|
||||
// as the number it went in as.
|
||||
expect(out.rows[0].row?.value).toBeCloseTo(5.3 * MGDL_PER_MMOL, 3);
|
||||
expect(mgdlToMmol(out.rows[0].row?.value ?? 0)).toBe(5.3);
|
||||
});
|
||||
|
||||
it("converts weight lb to canonical kg", () => {
|
||||
@@ -176,7 +182,7 @@ describe("parseCsvMeasurements — glucose context", () => {
|
||||
for (const result of out.rows) {
|
||||
expect(result.row).not.toHaveProperty("glucoseContext");
|
||||
expect(result.row?.unit).toBe("mg/dL");
|
||||
expect(result.row?.value).toBeCloseTo(95.4848, 3);
|
||||
expect(result.row?.value).toBeCloseTo(5.3 * MGDL_PER_MMOL, 3);
|
||||
}
|
||||
expect(out.rows[0].row?.measuredAt.toISOString()).toBe(
|
||||
"2024-04-03T02:15:00.000Z",
|
||||
|
||||
Reference in new issue
Block a user