Public: anyone can read this; the crew can change it.
small: The review page's finished screen also says how many reminders were held until tomorrow #257
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/255-small-the-review-page-s-finished-screen → main 1 commit fork
3 files
changed +24
−7
src/review.test.ts +10
| @@ -239,3 +239,13 @@ test("the finished screen says how many were approved and declined today, counte | ||
| 239 | 239 | // The count does not come from the query string. |
| 240 | 240 | expect(await get("/reminders/today?q=zzzz-no-such-deal&done=9")).toContain(line![0]); |
| 241 | 241 | }); |
| 242 | ||
| 243 | test("the finished screen adds how many were held until tomorrow, and nothing when none were", async () => { | |
| 244 | const count = (page: string) => Number(/(\d+) held until tomorrow\./.exec(page)?.[1] ?? 0); | |
| 245 | const before = count(await get("/reminders/today?q=zzzz-no-such-deal")); | |
| 246 | const one = shown(await get("/reminders/today")); | |
| 247 | expect((await post("/reminders/today/hold", { ...keys(one), subject: "s", body: "b" })).status).toBeLessThan(400); | |
| 248 | const after = await get("/reminders/today?q=zzzz-no-such-deal"); | |
| 249 | expect(count(after)).toBe(before + 1); | |
| 250 | expect(await get("/reminders/today?q=zzzz-no-such-deal&done=9")).toContain(`${before + 1} held until tomorrow.`); | |
| 251 | }); |
src/settled.test.ts +6 −4
| @@ -2,8 +2,10 @@ import { expect, test } from "bun:test"; | ||
| 2 | 2 | import { settledLine } from "./settled.ts"; |
| 3 | 3 | |
| 4 | 4 | test("the line names what was approved and declined, and is empty when nothing was", () => { |
| 5 | expect(settledLine({ sent: 3, declined: 1 })).toBe("You approved 3 and declined 1 today."); | |
| 6 | expect(settledLine({ sent: 2, declined: 0 })).toBe("You approved 2 today."); | |
| 7 | expect(settledLine({ sent: 0, declined: 4 })).toBe("You declined 4 today."); | |
| 8 | expect(settledLine({ sent: 0, declined: 0 })).toBe(""); | |
| 5 | expect(settledLine({ sent: 3, declined: 1, held: 0 })).toBe("You approved 3 and declined 1 today."); | |
| 6 | expect(settledLine({ sent: 2, declined: 0, held: 0 })).toBe("You approved 2 today."); | |
| 7 | expect(settledLine({ sent: 0, declined: 4, held: 0 })).toBe("You declined 4 today."); | |
| 8 | expect(settledLine({ sent: 0, declined: 0, held: 0 })).toBe(""); | |
| 9 | expect(settledLine({ sent: 3, declined: 1, held: 2 })).toBe("You approved 3 and declined 1 today. 2 held until tomorrow."); | |
| 10 | expect(settledLine({ sent: 0, declined: 0, held: 1 })).toBe("1 held until tomorrow."); | |
| 9 | 11 | }); |
src/settled.ts +8 −3
| @@ -10,6 +10,8 @@ import { dayOfStamp } from "./dates.ts"; | ||
| 10 | 10 | export interface Settled { |
| 11 | 11 | readonly sent: number; |
| 12 | 12 | readonly declined: number; |
| 13 | /** Held today and still held: a release deletes the hold. */ | |
| 14 | readonly held: number; | |
| 13 | 15 | } |
| 14 | 16 | |
| 15 | 17 | /** Records written in the last two days, read in one query, then kept if they fall on `day` in `zone`. */ |
| @@ -28,11 +30,14 @@ export function settledOn(db: Database, zone: string, day: string): Settled { | ||
| 28 | 30 | if (r.kind === "s") sent++; |
| 29 | 31 | else declined++; |
| 30 | 32 | } |
| 31 | return { sent, declined }; | |
| 33 | const held = db.query<{ n: number }, [string]>("SELECT count(*) AS n FROM reminder_hold WHERE held_on = ?1").get(day)!.n; | |
| 34 | return { sent, declined, held }; | |
| 32 | 35 | } |
| 33 | 36 | |
| 34 | /** "You approved 3 and declined 1 today."; empty when nothing was settled today. */ | |
| 37 | /** "You approved 3 and declined 1 today. 2 held until tomorrow."; empty when nothing was settled or held today. */ | |
| 35 | 38 | export function settledLine(s: Settled): string { |
| 36 | 39 | const parts = [s.sent > 0 ? `approved ${s.sent}` : "", s.declined > 0 ? `declined ${s.declined}` : ""].filter((p) => p !== ""); |
| 37 | return parts.length === 0 ? "" : `You ${parts.join(" and ")} today.`; | |
| 40 | const done = parts.length === 0 ? "" : `You ${parts.join(" and ")} today.`; | |
| 41 | const held = s.held > 0 ? `${s.held} held until tomorrow.` : ""; | |
| 42 | return [done, held].filter((p) => p !== "").join(" "); | |
| 38 | 43 | } |
new above
offline