mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
fix(day): run only records with a start of their own through a day
The "Running that day" list carried the profile facts (smoking status, alcohol pattern, shift schedule) as running items, titled by their raw codes and counted "day n" from the date the fact was filed. A person who quit smoking years ago and entered it last week read "day 13". Those facts describe the person, hold no start the person gave, and are not part of a day; the lifestyle section and its running kind are gone from the day, its index and the model-facing get_day. The same false count reached a medication filed without a start date: its creation date stood in as the start. `since` is now null there, with no day count, and the entry's date only bounds which days show it. A life event's category is worded in the reader's language instead of its code.
This commit is contained in:
1 parent
88836452eb
commit
09f94d3eac
13 files changed
+211
-83
No files matched your search
@@ -211,6 +211,43 @@ describe("a local day across a clock change", () => {
|
||||
expect(after.events.some((e) => e.kind === "mood")).toBe(false);
|
||||
});
|
||||
|
||||
it("runs only records with a start of their own, never a profile fact or an entry date", async () => {
|
||||
const db = getPrismaClient();
|
||||
const owner = await makeUser("run");
|
||||
// Filed on the 17th: a person who quit years ago would read "day 13".
|
||||
await db.healthProfileFactRevision.create({
|
||||
data: {
|
||||
userId: owner.id,
|
||||
kind: "SMOKING_STATUS",
|
||||
valueEncrypted: encryptToBytes("FORMER"),
|
||||
validFrom: new Date("2026-03-17T08:00:00.000Z"),
|
||||
provenance: "USER_REPORTED",
|
||||
},
|
||||
});
|
||||
// A medication filed on the 17th without a start date.
|
||||
await db.medication.create({
|
||||
data: {
|
||||
userId: owner.id,
|
||||
name: "Levothyroxine",
|
||||
dose: "50 µg",
|
||||
createdAt: new Date("2026-03-17T08:00:00.000Z"),
|
||||
},
|
||||
});
|
||||
await signIn(owner.id);
|
||||
|
||||
const day = await json<Day>(await getDay("2026-03-29"));
|
||||
expect(day.running.map((r) => r.kind)).toEqual(["medication"]);
|
||||
expect(day.running[0]).toMatchObject({
|
||||
title: "Levothyroxine",
|
||||
since: null,
|
||||
dayIndex: null,
|
||||
dayCount: null,
|
||||
});
|
||||
// The entry's date still bounds which days show it.
|
||||
const before = await json<Day>(await getDay("2026-03-16"));
|
||||
expect(before.running).toEqual([]);
|
||||
});
|
||||
|
||||
it("holds 25 hours on the fall-back day", async () => {
|
||||
const db = getPrismaClient();
|
||||
const owner = await makeUser("fall");
|
||||
|
||||
Reference in new issue
Block a user