fix(labs): keep a reading's conversion record unless its value actually changes

The single-reading edit cleared sourceValue and sourceUnit whenever the body
carried a value, and the web edit sheet always sends one, so a date or note
edit erased the "converted from" hint. It is now cleared only when the value
differs from the stored one. The sheet also opened a converted reading at its
stored precision (100.90191999999999); it now starts from the value as the lab
surfaces show it and leaves an untouched value out of the request, so the
stored full-precision number is not replaced by its rounded display.
This commit is contained in:
Marc-André Bombeck committed 2026-10-14 19:15:33 +02:00
1 parent 47a91d6922
commit cd1449e63e
6 files changed
+118 -9

No files matched your search

+17 -2
View File
@@ -14,7 +14,8 @@
* the printed unit is in range after conversion;
* - the OCR commit converts, and the same scan committed again is a duplicate
* (the stored number is converted, so the printed one is what matches);
* - editing the value of a converted reading clears the conversion record;
* - changing the value of a converted reading clears the conversion record,
* and an edit that sends the value back unchanged keeps it;
* - the list returns the fields.
*/
import { NextRequest } from "next/server";
@@ -338,10 +339,24 @@ describe("editing and reading back", () => {
takenAt: "2026-07-02T08:00:00.000Z",
});
const id = created.json.data!.id;
const edited = await call<Dto>("one", "PUT", { note: "fasting" }, id);
const storedValue = created.json.data!.value;
// The web edit dialog sends the form back whole, the unchanged value
// included; only a changed value clears the record.
const edited = await call<Dto>(
"one",
"PUT",
{
value: storedValue,
takenAt: "2026-07-02T09:00:00.000Z",
note: "fasting",
},
id,
);
expect(edited.status).toBe(200);
expect(edited.json.data!.value).toBe(storedValue);
expect(edited.json.data!.converted).toBe(true);
expect(edited.json.data!.sourceValue).toBe(6.1);
expect(edited.json.data!.sourceUnit).toBe("mmol/L");
});
it("returns the fields on the list and on the single reading", async () => {