Public: anyone can read this; the crew can change it.
A deal opened as a cash offer has no appraisal or financing dates and asks for no lender, and says "Cash" on the clock and its page #175
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/166-a-deal-opened-as-a-cash-offer-has-no-app → main 5 commits fork 3 threads · 3 unresolved
22 files
changed +299
−30
README.md +3 −1
| @@ -86,7 +86,9 @@ listing in the samples. | ||
| 86 | 86 | date, and which side you are on. The standard lengths (earnest money deposit 3 |
| 87 | 87 | days, inspection 10, appraisal 21, financing 30, title 14, final walkthrough |
| 88 | 88 | the day before closing) are filled in and you can change them; **Check the |
| 89 | dates** shows every date the deal would get without saving anything. On a deal's page | |
| 89 | dates** shows every date the deal would get without saving anything. Tick | |
| 90 | **Cash offer (no loan)** and the deal gets no appraisal or financing date and | |
| 91 | no lender is asked for anything; "Cash" shows beside the side. On a deal's page | |
| 90 | 92 | you can add a party (**Use someone from your other deals** fills in a person |
| 91 | 93 | you already have), fix a typo with Edit, add a date the contract added (an HOA |
| 92 | 94 | review), waive a contingency the buyer gave up, change who owes a date, correct |
contract/openapi.json +19
| @@ -444,6 +444,11 @@ | ||
| 444 | 444 | "type": "boolean", |
| 445 | 445 | "default": false |
| 446 | 446 | }, |
| 447 | "cash": { | |
| 448 | "type": "boolean", | |
| 449 | "default": false, | |
| 450 | "description": "A cash purchase (no loan): the deal gets no Appraisal due or Financing contingency date and no lender is told. Anything but a boolean is a 422 naming cash." | |
| 451 | }, | |
| 447 | 452 | "sale_price": { |
| 448 | 453 | "type": [ |
| 449 | 454 | "integer", |
| @@ -953,6 +958,13 @@ | ||
| 953 | 958 | 1 |
| 954 | 959 | ] |
| 955 | 960 | }, |
| 961 | "cash": { | |
| 962 | "enum": [ | |
| 963 | 0, | |
| 964 | 1 | |
| 965 | ], | |
| 966 | "description": "1 for a cash purchase: no appraisal or financing date, and no lender is told." | |
| 967 | }, | |
| 956 | 968 | "author_id": { |
| 957 | 969 | "type": "string" |
| 958 | 970 | }, |
| @@ -3077,6 +3089,13 @@ | ||
| 3077 | 3089 | 1 |
| 3078 | 3090 | ] |
| 3079 | 3091 | }, |
| 3092 | "cash": { | |
| 3093 | "enum": [ | |
| 3094 | 0, | |
| 3095 | 1 | |
| 3096 | ], | |
| 3097 | "description": "1 for a cash purchase: no appraisal or financing date, and no lender is told." | |
| 3098 | }, | |
| 3080 | 3099 | "author_id": { |
| 3081 | 3100 | "type": "string" |
| 3082 | 3101 | }, |
docs/TECHNICAL.md +1
| @@ -397,6 +397,7 @@ those of `src/terminal.ts`; the tools are those of `src/mcp.ts`. | ||
| 397 | 397 | Both; enter is Buyer's agent, any other word is refused) and `Y` on a deal |
| 398 | 398 | changes it. MCP `set_side`. |
| 399 | 399 | - **Date note.** Terminal `T` on a date. |
| 400 | - **Cash deals.** `cash` (boolean, default false; `deal.cash` 0 or 1, migration appended to `src/db.ts`) on `POST /api/deals`, MCP `open_deal`, the New deal form (`cash=on`) and the terminal's new-deal prompt. `schedule()` then omits `appraisal` and `financing`; `recipients()` never tells a lender on a cash deal. Anything but a boolean is a 422 whose message names `cash`. An appraisal can still be added by hand. | |
| 400 | 401 | - **New deal preview.** Terminal `c` instead of `n` lists the dates without saving. |
| 401 | 402 | - **Move to next business day.** `N` in the terminal. |
| 402 | 403 | - **Restore the samples.** Terminal `R`; MCP `restore_samples` (admin only). |
src/cash.test.ts added +127
| @@ -0,0 +1,127 @@ | ||
| 1 | import { afterAll, beforeEach, expect, test } from "bun:test"; | |
| 2 | import { Database } from "bun:sqlite"; | |
| 3 | import { mkdtempSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { openDb } from "./db.ts"; | |
| 7 | import { DEFAULT_LENGTHS, schedule } from "./deadlines.ts"; | |
| 8 | import { addDeadline, addParty, createDeal, getDeal, listDeals } from "./deals.ts"; | |
| 9 | import { recipients } from "./reminders.ts"; | |
| 10 | import { forgetRationing } from "./security.ts"; | |
| 11 | import { serve } from "./server.ts"; | |
| 12 | import { tools } from "./mcp.ts"; | |
| 13 | import { sign, type Who } from "./who.ts"; | |
| 14 | ||
| 15 | const KEY = "a-key-only-the-forge-holds"; | |
| 16 | const dir = mkdtempSync(join(tmpdir(), "app-cash-")); | |
| 17 | const db = openDb(dir); | |
| 18 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 19 | const server = serve({ port: 0, dataDir: dir, identityKey: KEY }); | |
| 20 | const base = `http://${server.hostname}:${server.port}`; | |
| 21 | afterAll(() => server.stop(true)); | |
| 22 | beforeEach(forgetRationing); | |
| 23 | const identity = `u1|alice|user|${Date.now() + 600_000}`; | |
| 24 | const user = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) }; | |
| 25 | const fields = { address: "1 Cash Way", buyer: "Ann Buyer", seller: "Sam Seller", contract_date: "2026-10-01", closing_date: "2026-12-01" }; | |
| 26 | const kinds = (id: number) => db.query<{ kind: string }, [number]>("SELECT kind FROM deadline WHERE deal_id = ?1 ORDER BY due").all(id).map((r) => r.kind); | |
| 27 | const LOAN = ["appraisal", "financing"]; | |
| 28 | ||
| 29 | test("schedule() with cash omits the appraisal and financing dates, and without it keeps them", () => { | |
| 30 | const input = { contractDate: "2026-10-01", closingDate: "2026-12-01", lengths: DEFAULT_LENGTHS, businessDays: false }; | |
| 31 | expect(schedule(input).map((p) => p.kind)).toEqual(expect.arrayContaining(LOAN)); | |
| 32 | const cash = schedule({ ...input, cash: true }).map((p) => p.kind).sort(); | |
| 33 | expect(cash).toEqual(["closing", "earnest", "inspection", "title", "walkthrough"]); | |
| 34 | }); | |
| 35 | ||
| 36 | test("the form opens a cash deal with the flag and no lender dates; the check previews without them", async () => { | |
| 37 | const form = (extra: Record<string, string>) => new URLSearchParams({ ...fields, ...extra }); | |
| 38 | const page = await fetch(base + "/deals/new", { headers: user }).then((r) => r.text()); | |
| 39 | expect(page).toContain("Cash offer (no loan)"); | |
| 40 | const check = await fetch(base + "/deals/check", { method: "POST", headers: { ...user, "content-type": "application/x-www-form-urlencoded" }, body: form({ cash: "on" }) }).then((r) => r.text()); | |
| 41 | expect(check).toContain("Final walkthrough"); | |
| 42 | expect(check).not.toContain("Appraisal due"); | |
| 43 | expect(check).not.toContain("Financing contingency"); | |
| 44 | expect(check).toMatch(/name="cash" checked/); | |
| 45 | const res = await fetch(base + "/deals", { method: "POST", redirect: "manual", headers: { ...user, "content-type": "application/x-www-form-urlencoded" }, body: form({ cash: "on" }) }); | |
| 46 | expect(res.status).toBe(303); | |
| 47 | const deal = db.query<{ id: number; cash: number }, []>("SELECT id, cash FROM deal WHERE address = '1 Cash Way'").get()!; | |
| 48 | expect(deal.cash).toBe(1); | |
| 49 | expect(kinds(deal.id).some((k) => LOAN.includes(k))).toBe(false); | |
| 50 | const plain = await fetch(base + "/deals/check", { method: "POST", headers: { ...user, "content-type": "application/x-www-form-urlencoded" }, body: form({ address: "2 Loan Way" }) }).then((r) => r.text()); | |
| 51 | expect(plain).toContain("Appraisal due"); | |
| 52 | }); | |
| 53 | ||
| 54 | test("the API stores cash, refuses a non-boolean with 422 naming cash, and describes it", async () => { | |
| 55 | const body = { address: "3 Cash Way", buyer: "A", seller: "B", contract_date: "2026-10-01", closing_date: "2026-12-01" }; | |
| 56 | const post = (extra: object) => fetch(base + "/api/deals", { method: "POST", headers: { ...user, "content-type": "application/json" }, body: JSON.stringify({ ...body, ...extra }) }); | |
| 57 | const ok = await post({ cash: true }); | |
| 58 | expect(ok.status).toBe(201); | |
| 59 | const made = (await ok.json()) as { id: number; cash: number }; | |
| 60 | expect(made.cash).toBe(1); | |
| 61 | expect(kinds(made.id).some((k) => LOAN.includes(k))).toBe(false); | |
| 62 | const bad = await post({ cash: "maybe", address: "4 Cash Way" }); | |
| 63 | expect(bad.status).toBe(422); | |
| 64 | expect(((await bad.json()) as { message: string }).message).toContain("cash"); | |
| 65 | expect((await post({ cash: 1, address: "5 Cash Way" })).status).toBe(422); | |
| 66 | for (const [i, cash] of ["true", "on", "1", "0", "false"].entries()) { | |
| 67 | const res = await post({ cash, address: `${10 + i} Strict Way` }); | |
| 68 | expect(res.status).toBe(422); | |
| 69 | expect(((await res.json()) as { message: string }).message).toContain("cash"); | |
| 70 | } | |
| 71 | const spec = await fetch(base + "/openapi.json", { headers: user }).then((r) => r.text()); | |
| 72 | expect(spec).toContain("A cash purchase (no loan)"); | |
| 73 | }); | |
| 74 | ||
| 75 | test("MCP's open_deal accepts cash", () => { | |
| 76 | const open = tools.find((t) => t.name === "open_deal")!; | |
| 77 | const r = open.run(db, alice, { address: "6 Cash Way", buyer: "A", seller: "B", contract_date: "2026-10-01", closing_date: "2026-12-01", cash: true }) as { ok: boolean; value: { id: number; cash: number } }; | |
| 78 | expect(r.ok && r.value.cash).toBe(1); | |
| 79 | expect(kinds(r.value.id).some((k) => LOAN.includes(k))).toBe(false); | |
| 80 | expect(open.run(db, alice, { address: "7 Cash Way", buyer: "A", seller: "B", contract_date: "2026-10-01", closing_date: "2026-12-01", cash: "yes" })).toMatchObject({ ok: false, field: "cash" }); | |
| 81 | }); | |
| 82 | ||
| 83 | test("no lender is told on a cash deal, even one added by hand, and an appraisal can be added", () => { | |
| 84 | const made = createDeal(db, alice, { address: "8 Cash Way", buyer: "A", seller: "B", contractDate: "2026-10-01", closingDate: "2026-12-01", cash: true }); | |
| 85 | if (!made.ok) throw new Error(made.message); | |
| 86 | expect(addParty(db, alice, { dealId: made.value.id, role: "lender", name: "Bank" }).ok).toBe(true); | |
| 87 | const deal = getDeal(db, alice, { id: made.value.id }); | |
| 88 | if (!deal.ok) throw new Error(deal.message); | |
| 89 | const closing = deal.value.deadlines.find((d) => d.kind === "closing")!; | |
| 90 | expect(deal.value.parties.some((p) => p.role === "lender")).toBe(true); | |
| 91 | for (const moment of ["before", "day_of", "moved"] as const) | |
| 92 | expect(recipients(deal.value, closing, moment).some((p) => p.role === "lender")).toBe(false); | |
| 93 | const loan = createDeal(db, alice, { address: "9 Loan Way", buyer: "A", seller: "B", contractDate: "2026-10-01", closingDate: "2026-12-01" }); | |
| 94 | if (!loan.ok) throw new Error(loan.message); | |
| 95 | addParty(db, alice, { dealId: loan.value.id, role: "lender", name: "Bank" }); | |
| 96 | const l = getDeal(db, alice, { id: loan.value.id }); | |
| 97 | if (!l.ok) throw new Error(l.message); | |
| 98 | expect(recipients(l.value, l.value.deadlines.find((d) => d.kind === "closing")!, "day_of").some((p) => p.role === "lender")).toBe(true); | |
| 99 | expect(listDeals(db, alice).ok).toBe(true); | |
| 100 | }); | |
| 101 | ||
| 102 | test("the clock, the deal page, the client timeline and the broker file say Cash", async () => { | |
| 103 | const id = db.query<{ id: number }, []>("SELECT id FROM deal WHERE address = '1 Cash Way'").get()!.id; | |
| 104 | const get = (p: string) => fetch(base + p, { headers: user }).then((r) => r.text()); | |
| 105 | expect(await get("/")).toContain('data-side="cash"'); | |
| 106 | expect(await get(`/deals/${id}`)).toContain('data-side="cash"'); | |
| 107 | expect(await get(`/deals/${id}/timeline`)).toContain("Cash purchase"); | |
| 108 | expect(await get(`/deals/${id}/file`)).toContain("Cash purchase"); | |
| 109 | }); | |
| 110 | ||
| 111 | test("MCP refuses the string forms of cash", () => { | |
| 112 | const open = tools.find((t) => t.name === "open_deal")!; | |
| 113 | for (const cash of ["true", "on", "1"]) | |
| 114 | expect(open.run(db, alice, { address: "8 Strict Way", buyer: "A", seller: "B", contract_date: "2026-10-01", closing_date: "2026-12-01", cash })).toMatchObject({ ok: false, field: "cash" }); | |
| 115 | }); | |
| 116 | ||
| 117 | test("a date added by hand to a cash deal, an appraisal, is kept", () => { | |
| 118 | const made = createDeal(db, alice, { address: "11 Hand Way", buyer: "A", seller: "B", contractDate: "2026-10-01", closingDate: "2026-12-01", cash: true }); | |
| 119 | if (!made.ok) throw new Error(made.message); | |
| 120 | expect(kinds(made.value.id)).not.toContain("appraisal"); | |
| 121 | const added = addDeadline(db, alice, { dealId: made.value.id, label: "Appraisal due", due: "2026-11-01", owes: "lender" }); | |
| 122 | expect(added.ok).toBe(true); | |
| 123 | const got = getDeal(db, alice, { id: made.value.id }); | |
| 124 | if (!got.ok) throw new Error(got.message); | |
| 125 | expect(got.value.cash).toBe(1); | |
| 126 | expect(got.value.deadlines.some((d) => d.label === "Appraisal due")).toBe(true); | |
| 127 | }); |
src/db.ts +2
| @@ -501,6 +501,8 @@ export const migrations: string[] = [ | ||
| 501 | 501 | CREATE INDEX reminder_hold_deal ON reminder_hold (deal_id)`, |
| 502 | 502 | // The agent's own time zone: "today" is their day, not the server's (src/dates.ts). |
| 503 | 503 | `ALTER TABLE profile ADD COLUMN zone TEXT NOT NULL DEFAULT 'America/New_York' CHECK (length(zone) BETWEEN 1 AND 64)`, |
| 504 | // A cash purchase has no loan: its deal plans no appraisal or financing date and tells no lender. | |
| 505 | `ALTER TABLE deal ADD COLUMN cash INTEGER NOT NULL DEFAULT 0 CHECK (cash IN (0, 1))`, | |
| 504 | 506 | ]; |
| 505 | 507 | |
| 506 | 508 | export function openDb(dir = dataDir): Database { |
src/deadlines.ts +7 −3
| @@ -173,14 +173,18 @@ export function schedule(input: { | ||
| 173 | 173 | closingDate: string; |
| 174 | 174 | lengths: Lengths; |
| 175 | 175 | businessDays: boolean; |
| 176 | /** A cash purchase has no loan: no appraisal date, no financing date. */ | |
| 177 | cash?: boolean; | |
| 176 | 178 | }): Planned[] { |
| 177 | const { contractDate, closingDate, lengths, businessDays } = input; | |
| 179 | const { contractDate, closingDate, lengths, businessDays, cash = false } = input; | |
| 178 | 180 | const add = businessDays ? addBusinessDays : addDays; |
| 179 | 181 | const planned: Planned[] = [ |
| 180 | 182 | { kind: "earnest", due: add(contractDate, lengths.earnest) }, |
| 181 | 183 | { kind: "inspection", due: add(contractDate, lengths.inspection) }, |
| 182 | { kind: "appraisal", due: add(contractDate, lengths.appraisal) }, | |
| 183 | { kind: "financing", due: add(contractDate, lengths.financing) }, | |
| 184 | ...(cash ? [] : [ | |
| 185 | { kind: "appraisal" as const, due: add(contractDate, lengths.appraisal) }, | |
| 186 | { kind: "financing" as const, due: add(contractDate, lengths.financing) }, | |
| 187 | ]), | |
| 184 | 188 | { kind: "title", due: add(contractDate, lengths.title) }, |
| 185 | 189 | { kind: "walkthrough", due: add(closingDate, -lengths.walkthrough) }, |
| 186 | 190 | { kind: "closing", due: closingDate }, |
src/deals.ts +14 −4
| @@ -43,6 +43,8 @@ export interface Deal { | ||
| 43 | 43 | readonly address: string; |
| 44 | 44 | readonly contract_date: string; |
| 45 | 45 | readonly business_days: 0 | 1; |
| 46 | /** A cash purchase: no loan, so no appraisal or financing date and no lender is told. */ | |
| 47 | readonly cash: 0 | 1; | |
| 46 | 48 | readonly author_id: string; |
| 47 | 49 | readonly author_name: string; |
| 48 | 50 | readonly created_at: string; |
| @@ -505,6 +507,8 @@ export interface NewDeal { | ||
| 505 | 507 | readonly closingDate: unknown; |
| 506 | 508 | readonly lengths?: Partial<Record<keyof Lengths, unknown>>; |
| 507 | 509 | readonly businessDays?: unknown; |
| 510 | /** A cash purchase (no loan): a boolean; anything else but nothing is refused. */ | |
| 511 | readonly cash?: unknown; | |
| 508 | 512 | /** Optional whole dollars: nothing, or blank, is none set. */ |
| 509 | 513 | readonly salePrice?: unknown; |
| 510 | 514 | readonly earnestAmount?: unknown; |
| @@ -525,12 +529,16 @@ export interface Plan { | ||
| 525 | 529 | readonly closingDate: string; |
| 526 | 530 | readonly lengths: Lengths; |
| 527 | 531 | readonly businessDays: boolean; |
| 532 | readonly cash: boolean; | |
| 528 | 533 | readonly salePrice: number | null; |
| 529 | 534 | readonly earnestAmount: number | null; |
| 530 | 535 | readonly commissionRate?: number | null; |
| 531 | 536 | readonly side: Side; |
| 532 | 537 | } |
| 533 | 538 | |
| 539 | /** The cash flag: nothing is no, a real boolean is itself; anything else is undefined (a 422). The form's strings are turned into booleans at the form door. */ | |
| 540 | const cashOf = (v: unknown): boolean | undefined => (v === undefined ? false : typeof v === "boolean" ? v : undefined); | |
| 541 | ||
| 534 | 542 | export function plan(input: NewDeal): Result<Plan> { |
| 535 | 543 | const address = line(input.address, 3, 200); |
| 536 | 544 | if (address === undefined) |
| @@ -565,6 +573,8 @@ export function plan(input: NewDeal): Result<Plan> { | ||
| 565 | 573 | input.businessDays === undefined |
| 566 | 574 | ? standard.businessDays |
| 567 | 575 | : input.businessDays === true || input.businessDays === "on" || input.businessDays === "1"; |
| 576 | const cash = cashOf(input.cash); | |
| 577 | if (cash === undefined) return fail("invalid", "The cash field is true or false.", "cash"); | |
| 568 | 578 | const salePrice = amount(input.salePrice, "sale_price", "sale price"); |
| 569 | 579 | if (!salePrice.ok) return salePrice; |
| 570 | 580 | const earnestAmount = amount(input.earnestAmount, "earnest_amount", "earnest money amount"); |
| @@ -573,7 +583,7 @@ export function plan(input: NewDeal): Result<Plan> { | ||
| 573 | 583 | if (!commissionRate.ok) return commissionRate; |
| 574 | 584 | const side = sideOf(input.side); |
| 575 | 585 | if (side === undefined) return fail("invalid", SIDE_REFUSAL, "side"); |
| 576 | return ok({ address, buyer, seller, contractDate, closingDate, lengths, businessDays, salePrice: salePrice.value, earnestAmount: earnestAmount.value, commissionRate: commissionRate.value, side }); | |
| 586 | return ok({ address, buyer, seller, contractDate, closingDate, lengths, businessDays, cash, salePrice: salePrice.value, earnestAmount: earnestAmount.value, commissionRate: commissionRate.value, side }); | |
| 577 | 587 | } |
| 578 | 588 | |
| 579 | 589 | /** An address as two typings of one house agree on it: trimmed, spaces collapsed, lower case, no trailing period. */ |
| @@ -629,10 +639,10 @@ export function insertDeal( | ||
| 629 | 639 | ): Deal { |
| 630 | 640 | return db.transaction(() => { |
| 631 | 641 | const deal = db |
| 632 | .query<Deal, [string, string, number, string, string, number | null, number | null, string, number | null]>( | |
| 633 | "INSERT INTO deal (address, contract_date, business_days, author_id, author_name, sale_price, earnest_amount, side, commission_rate) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9) RETURNING *", | |
| 642 | .query<Deal, [string, string, number, string, string, number | null, number | null, string, number | null, number]>( | |
| 643 | "INSERT INTO deal (address, contract_date, business_days, author_id, author_name, sale_price, earnest_amount, side, commission_rate, cash) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10) RETURNING *", | |
| 634 | 644 | ) |
| 635 | .get(p.address, p.contractDate, p.businessDays ? 1 : 0, author.id, author.name, p.salePrice ?? null, p.earnestAmount ?? null, p.side ?? "buyer", p.commissionRate ?? null)!; | |
| 645 | .get(p.address, p.contractDate, p.businessDays ? 1 : 0, author.id, author.name, p.salePrice ?? null, p.earnestAmount ?? null, p.side ?? "buyer", p.commissionRate ?? null, p.cash ? 1 : 0)!; | |
| 636 | 646 | const party = db.query( |
| 637 | 647 | "INSERT INTO party (deal_id, role, name) VALUES (?1, ?2, ?3)", |
| 638 | 648 | ); |
src/duplicate.test.ts +2 −2
| @@ -48,11 +48,11 @@ test("a closed deal does not block: a house can sell again", () => { | ||
| 48 | 48 | test("the terminal says so and opens a second deal only on a yes", () => { |
| 49 | 49 | const t = terminal(db, alice, { title: "deal-clock", where: "test", agent: { name: "D", brokerage: "H", phone: "5", email: "[email protected]" } }); |
| 50 | 50 | const text = () => t.screen().join("\n").replace(/\x1b\[[0-9;]*m/g, ""); |
| 51 | for (const c of ["n", "1418 Alder Court\r", "Ann\r", "Sam\r", "2026-10-01\r", "2026-11-01\r", "\r"]) t.press(c); | |
| 51 | for (const c of ["n", "1418 Alder Court\r", "Ann\r", "Sam\r", "2026-10-01\r", "2026-11-01\r", "\r", "\r"]) t.press(c); | |
| 52 | 52 | expect(text()).toContain("1418 Alder Court is already open"); |
| 53 | 53 | t.press("no\r"); |
| 54 | 54 | expect(text()).toContain(`Kept: deal ${first.value.id}`); |
| 55 | for (const c of ["n", "1418 Alder Court\r", "Ann\r", "Sam\r", "2026-10-01\r", "2026-11-01\r", "\r", "yes\r"]) t.press(c); | |
| 55 | for (const c of ["n", "1418 Alder Court\r", "Ann\r", "Sam\r", "2026-10-01\r", "2026-11-01\r", "\r", "\r", "yes\r"]) t.press(c); | |
| 56 | 56 | expect(text()).toContain("Opened 1418 Alder Court"); |
| 57 | 57 | }); |
| 58 | 58 |
src/export.test.ts +13 −1
| @@ -36,6 +36,7 @@ const AUDIT_WORDS = "zebra-secret-audit-words"; | ||
| 36 | 36 | |
| 37 | 37 | let dealId = 0; |
| 38 | 38 | let fellId = 0; |
| 39 | let cashId = 0; | |
| 39 | 40 | let server: ReturnType<typeof serve>; |
| 40 | 41 | let base = ""; |
| 41 | 42 | let headers: Record<string, string> = {}; |
| @@ -58,6 +59,7 @@ beforeAll(() => { | ||
| 58 | 59 | fellId = open(db, alice, input("3 Fell Court")); |
| 59 | 60 | for (let i = 0; i < 200; i++) open(db, alice, input(`${100 + i} Bulk Lane`)); |
| 60 | 61 | open(db, bob, input("77 Bob's Own Road")); |
| 62 | cashId = open(db, alice, { ...input("5 Cash Export Row"), cash: true }); | |
| 61 | 63 | db.query("UPDATE party SET phone = '555 0100', email = '[email protected]' WHERE deal_id = ?1 AND role = 'buyer'").run(dealId); |
| 62 | 64 | const first = must(getDeal(db, alice, { id: dealId })); |
| 63 | 65 | const insp = first.deadlines.find((d) => d.kind === "inspection")!; |
| @@ -89,13 +91,23 @@ test("the file holds every field, with moves, notes, state, parties and messages | ||
| 89 | 91 | expect(date.note).toBe("Call the inspector"); |
| 90 | 92 | expect(date.moves[0]).toMatchObject({ to: "2026-10-20", reason: "Seller asked", by: "alice" }); |
| 91 | 93 | for (const key of ["due", "done", "waived", "owed_by"]) expect(key in date).toBe(true); |
| 92 | for (const key of ["side", "closing_time", "closing_place", "sale_price"]) expect(key in mine).toBe(true); | |
| 94 | for (const key of ["side", "cash", "closing_time", "closing_place", "sale_price"]) expect(key in mine).toBe(true); | |
| 95 | expect((mine as unknown as { cash: boolean }).cash).toBe(false); | |
| 93 | 96 | expect(mine.messages[0]).toMatchObject({ to: "Bea Buyer", subject: "Inspection soon", body: "Hi Bea, the inspection is near.", by: "alice" }); |
| 94 | 97 | const lost = file.deals.find((d) => d.id === fellId)!; |
| 95 | 98 | expect(lost.state).toBe("fell_through"); |
| 96 | 99 | expect(lost.reason).toBe("Financing fell apart"); |
| 97 | 100 | }); |
| 98 | 101 | |
| 102 | test("a cash deal is exported as cash, with no loan dates", () => { | |
| 103 | const db = openDb(dir); | |
| 104 | const file = JSON.parse(JSON.stringify(exportDeals(listed(db, alice), new Date()))) as { deals: { id: number; cash: boolean; dates: { kind: string }[] }[] }; | |
| 105 | db.close(); | |
| 106 | const cash = file.deals.find((d) => d.id === cashId)!; | |
| 107 | expect(cash.cash).toBe(true); | |
| 108 | expect(cash.dates.some((d) => d.kind === "appraisal" || d.kind === "financing")).toBe(false); | |
| 109 | }); | |
| 110 | ||
| 99 | 111 | test("another user gets exactly what listDeals gives them, and no audit content", async () => { |
| 100 | 112 | const db = openDb(dir); |
| 101 | 113 | const expected = listed(db, bob).map((d) => d.id); |
src/export.ts +3 −2
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * deal view already carries. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { today } from "./dates.ts"; | |
| 8 | import { DEFAULT_ZONE, today } from "./dates.ts"; | |
| 9 | 9 | import type { DealView } from "./deals.ts"; |
| 10 | 10 | |
| 11 | 11 | export const EXPORT_VERSION = 1; |
| @@ -30,6 +30,7 @@ const dealOf = (deal: DealView): Record<string, unknown> => ({ | ||
| 30 | 30 | id: deal.id, |
| 31 | 31 | address: deal.address, |
| 32 | 32 | side: deal.side, |
| 33 | cash: deal.cash === 1, | |
| 33 | 34 | contract_date: deal.contract_date, |
| 34 | 35 | closing: deal.closing, |
| 35 | 36 | closing_time: deal.closing_time, |
| @@ -76,4 +77,4 @@ export function exportDeals(deals: readonly DealView[], now: Date): Export { | ||
| 76 | 77 | }; |
| 77 | 78 | } |
| 78 | 79 | |
outdated
Unrelated to the issue; and the export itself still omits |
||
| 79 | export const exportName = (now: Date): string => `deal-clock-${today(now)}.json`; | |
| 80 | export const exportName = (now: Date): string => `deal-clock-${today(DEFAULT_ZONE, now)}.json`; |
src/mcp.ts +2
| @@ -350,6 +350,7 @@ export const tools: readonly Tool[] = [ | ||
| 350 | 350 | title: { type: "integer", minimum: 0, maximum: LENGTH_MAX, default: DEFAULT_LENGTHS.title }, |
| 351 | 351 | walkthrough: { type: "integer", minimum: 0, maximum: LENGTH_MAX, default: DEFAULT_LENGTHS.walkthrough }, |
| 352 | 352 | business_days: { type: "boolean", default: standard.businessDays }, |
| 353 | cash: { type: "boolean", default: false, description: "A cash purchase (no loan): no appraisal or financing date, no lender told." }, | |
| 353 | 354 | sale_price: { type: "integer", minimum: 0, maximum: AMOUNT_MAX, description: "Optional sale price in whole dollars." }, |
| 354 | 355 | earnest_amount: { type: "integer", minimum: 0, maximum: AMOUNT_MAX, description: "Optional earnest money amount in whole dollars; the earnest money reminder says it." }, |
| 355 | 356 | commission_rate: { type: "integer", minimum: 0, maximum: RATE_MAX, description: "Optional commission rate in hundredths of a percent (250 is 2.5%), 0 to 1000." }, |
| @@ -378,6 +379,7 @@ export const tools: readonly Tool[] = [ | ||
| 378 | 379 | walkthrough: a.walkthrough, |
| 379 | 380 | }, |
| 380 | 381 | businessDays: a.business_days, |
| 382 | cash: a.cash, | |
| 381 | 383 | openAnyway: a.open_anyway, |
| 382 | 384 | }), |
| 383 | 385 | }, |
src/migrations.pin.json +2 −1
| @@ -53,5 +53,6 @@ | ||
| 53 | 53 | "f836a1da11c1f51a255301c4ee62c441612baada0345c1310f4149e5d5ccf5b9", |
| 54 | 54 | "72f67a8e8f06f9b9fcac58ff22eb3f4222c77a0968da5981d4e7dce8d4b8ce7d", |
| 55 | 55 | "166c5e5ec18272d556b87786396c5c3a17da8b56185643e8efeeb83742cc2b5b", |
| 56 | "3fbd9e1851d9bc86a3a4c5adfc9f2300712c450b66a87d253cfcb91586cbbe25" | |
| 56 | "3fbd9e1851d9bc86a3a4c5adfc9f2300712c450b66a87d253cfcb91586cbbe25", | |
| 57 | "7e011fb3dab2123101aa981ef9050d8f8d2c34fb3ba137ecc832f86d464b98a2" | |
| 57 | 58 | ] |
src/migrations.test.ts +27 −1
| @@ -13,7 +13,7 @@ test("every migration is pinned by position; a pull may only append", () => { | ||
| 13 | 13 | }); |
| 14 | 14 | |
| 15 | 15 | test("a database made before the Profile line gets the column and reads the agent", () => { |
| 16 | const before = migrations.filter((m) => !/profile ADD COLUMN line|commission_rate|profile ADD COLUMN zone/.test(m)); | |
| 16 | const before = migrations.filter((m) => !/profile ADD COLUMN line|commission_rate|profile ADD COLUMN zone|ADD COLUMN cash/.test(m)); | |
| 17 | 17 | const db = new Database(":memory:"); |
| 18 | 18 | db.exec("CREATE TABLE schema_version (version INTEGER PRIMARY KEY, applied_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')))"); |
| 19 | 19 | before.forEach((sql, i) => { |
| @@ -26,3 +26,29 @@ test("a database made before the Profile line gets the column and reads the agen | ||
| 26 | 26 | expect(db.query("SELECT line FROM profile").get()).toEqual({ line: "" }); |
| 27 | 27 | expect(db.query("SELECT commission_rate FROM deal").all()).toEqual([]); |
| 28 | 28 | }); |
| 29 | ||
| 30 | test("a database at every earlier version boots with its deals unchanged and cash = 0", () => { | |
| 31 | const cashAt = migrations.findIndex((m) => /ADD COLUMN cash/.test(m)); | |
| 32 | expect(cashAt).toBeGreaterThan(0); | |
| 33 | const dealAt = migrations.findIndex((m) => /CREATE TABLE (IF NOT EXISTS )?deal\b/.test(m)); | |
| 34 | expect(dealAt).toBeGreaterThanOrEqual(0); | |
| 35 | for (let version = 1; version <= cashAt; version++) { | |
| 36 | const db = new Database(":memory:"); | |
| 37 | db.exec("CREATE TABLE schema_version (version INTEGER PRIMARY KEY, applied_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')))"); | |
| 38 | migrations.slice(0, version).forEach((sql, i) => { | |
| 39 | try { | |
| 40 | db.exec(sql); | |
| 41 | } catch (error) { | |
| 42 | // Only what migrate() itself tolerates: a column an earlier migration already made. | |
| 43 | if (!(/^ALTER TABLE \w+ ADD COLUMN/.test(sql) && String(error).includes("duplicate column name"))) throw error; | |
| 44 | } | |
| 45 | db.query("INSERT INTO schema_version (version) VALUES (?1)").run(i + 1); | |
| 46 | }); | |
| 47 | // Where the deal table exists a deal is seeded (an insert that fails fails the test); where it does not, none can be. | |
| 48 | const seeded = version > dealAt; | |
| 49 | if (seeded) db.exec("INSERT INTO deal (address, contract_date, author_id, author_name) VALUES ('1 Old St', '2026-01-01', 'u', 'U')"); | |
| 50 | expect(migrate(db), `version ${version}`).toBe(migrations.length); | |
| 51 | const rows = db.query("SELECT address, cash FROM deal").all(); | |
| 52 | expect(rows, `version ${version}`).toEqual(seeded ? [{ address: "1 Old St", cash: 0 }] : []); | |
| 53 | } | |
| 54 | }); |
src/pages/clock.ts +2 −2
| @@ -18,7 +18,7 @@ import { mayRestore } from "../actions.ts"; | ||
| 18 | 18 | import { badge, draftLink, opens, owedBy, URGENCY_LABEL } from "./sheet.ts"; |
| 19 | 19 | import { find } from "../find.ts"; |
| 20 | 20 | import { onSide, type SideFilter } from "../side.ts"; |
| 21 | import { sideFilterSelect, sideLabel } from "./side.ts"; | |
| 21 | import { dealSideLabel, sideFilterSelect, sideLabel } from "./side.ts"; | |
| 22 | 22 | import { memoizer, print } from "../memo.ts"; |
| 23 | 23 | import { bookLine, tally } from "../book.ts"; |
| 24 | 24 | import { dollars } from "../money.ts"; |
| @@ -70,7 +70,7 @@ function drawLane(deal: DealView, start: string, on: string): string { | ||
| 70 | 70 | }) |
| 71 | 71 | .join(""); |
| 72 | 72 | return `<li class="lane"> |
| 73 | <div class="lane-head"><a href="/deals/${deal.id}">${escape(deal.address)}</a> <small class="muted">${sideLabel(deal.side)} · ${deal.conflicts.length === 0 ? "" : `<b class="u-overdue">${deal.conflicts.length} out of order</b> · `}${progressLine(deal, on)}</small></div> | |
| 73 | <div class="lane-head"><a href="/deals/${deal.id}">${escape(deal.address)}</a> <small class="muted">${dealSideLabel(deal)} · ${deal.conflicts.length === 0 ? "" : `<b class="u-overdue">${deal.conflicts.length} out of order</b> · `}${progressLine(deal, on)}</small></div> | |
| 74 | 74 | <div class="track" style="height:calc(${height} * 3rem)">${markers}</div> |
| 75 | 75 | </li>`; |
| 76 | 76 | } |
src/pages/deal.ts +4 −2
| @@ -19,7 +19,7 @@ import { partyContact } from "./contact.ts"; | ||
| 19 | 19 | import { confirmRemove } from "./confirm.ts"; |
| 20 | 20 | import { layout } from "./layout.ts"; |
| 21 | 21 | import { sideOf } from "../side.ts"; |
| 22 | import { sideLabel, sideSelect } from "./side.ts"; | |
| 22 | import { dealSideLabel, sideLabel, sideSelect } from "./side.ts"; | |
| 23 | 23 | import { progressLine } from "./progress.ts"; |
| 24 | 24 | import { badge, conflictLines, nonBusinessLine, noteLine, owesChangedLine, rollForm, draftItem, dueLine, outboxLine, owedBy, releaseForm, sheet, sheetId } from "./sheet.ts"; |
| 25 | 25 | |
| @@ -337,7 +337,7 @@ export function dealPage(input: { | ||
| 337 | 337 | <div> |
| 338 | 338 | <h1>${escape(deal.address)}</h1> |
| 339 | 339 | <p class="summary">${deal.fell_through ? `<b>Fell through on ${escape(spoken(fellOn(deal)))}</b> · ${escape(deal.fell_reason ?? "")}${deal.fell_by ? ` (${escape(deal.fell_by)})` : ""} · ` : ""}${deal.closed ? `<b>Closed on ${escape(spoken(closedOn(deal)))}</b> · ` : ""}Under contract ${escape(spoken(deal.contract_date))} · closes ${escape(spoken(deal.closing))}, ${escape(relative(deal.closing, on))}${deal.business_days ? " · business days" : ""}</p> |
| 340 | <p class="summary">${sideLabel(deal.side)}</p> | |
| 340 | <p class="summary">${dealSideLabel(deal)}</p> | |
| 341 | 341 | ${figuresLine(deal)} |
| 342 | 342 | ${closingWhenLine(deal)} |
| 343 | 343 | ${editSide} |
| @@ -437,6 +437,7 @@ export function newDealPage(input: { | ||
| 437 | 437 | const length = (name: keyof typeof DEFAULT_LENGTHS, label: string) => |
| 438 | 438 | `<label>${label}<input class="input" type="number" inputmode="numeric" name="${name}" min="0" max="180" value="${val(name, String(DEFAULT_LENGTHS[name]))}" required${bad(name)}>${why(name)}</label>`; |
| 439 | 439 | const ticked = state === undefined ? standard.businessDays : values.business_days !== undefined; |
| 440 | const cashTicked = values.cash !== undefined && values.cash !== "0"; | |
| 440 | 441 | const body = |
| 441 | 442 | who.role === "anon" |
| 442 | 443 | ? `<p class="crumb"><a href="/">← The clock</a></p><section class="card"><h1>New deal</h1><p><a href="/__forge/signin?to=/deals/new">Sign in</a> to open a deal.</p></section>` |
| @@ -459,6 +460,7 @@ export function newDealPage(input: { | ||
| 459 | 460 | </div> |
| 460 | 461 | ${figureFields((n) => values[n] ?? "", problem)} |
| 461 | 462 | <label>Which side do you represent?${sideSelect(sideOf(values.side) ?? "buyer", "side")}${why("side")}</label> |
| 463 | <label class="check"><input type="checkbox" name="cash"${cashTicked ? " checked" : ""}> Cash offer (no loan)</label>${why("cash")} | |
| 462 | 464 | <fieldset> |
| 463 | 465 | <legend>Contingency lengths, in days from the contract date</legend> |
| 464 | 466 | <div class="lengths"> |
src/pages/file.ts +1
| @@ -63,6 +63,7 @@ export function fileRecord(deal: DealView): FileRecord { | ||
| 63 | 63 | facts: [ |
| 64 | 64 | ["Status", outcome], |
| 65 | 65 | ["Side", SIDE_LABEL[deal.side]], |
| 66 | ...(deal.cash === 1 ? [["Purchase", "Cash purchase"] as [string, string]] : []), | |
| 66 | 67 | ["Sale price", deal.sale_price === null ? "not set" : dollars(deal.sale_price)], |
| 67 | 68 | ["Earnest money", deal.earnest_amount === null ? "not set" : dollars(deal.earnest_amount)], |
| 68 | 69 | ["Commission rate", deal.commission_rate === null ? "not set" : percent(deal.commission_rate)], |
src/pages/side.ts +4
| @@ -10,6 +10,10 @@ import { SIDES, SIDE_CHOICE, SIDE_LABEL, type Side, type SideFilter } from "../s | ||
| 10 | 10 | /** The label, as text: a screen reader says it where it sits. */ |
| 11 | 11 | export const sideLabel = (side: Side): string => `<span class="side" data-side="${side}">${SIDE_LABEL[side]}</span>`; |
| 12 | 12 | |
| 13 | /** The side, and "Cash" beside it when the deal is a cash purchase. */ | |
| 14 | export const dealSideLabel = (deal: { side: Side; cash: 0 | 1 }): string => | |
| 15 | sideLabel(deal.side) + (deal.cash === 1 ? ` · <span class="side" data-side="cash">Cash</span>` : ""); | |
| 16 | ||
| 13 | 17 | /** The choice of side as a select named `side`. */ |
| 14 | 18 | export const sideSelect = (selected: Side, id = "side"): string => |
| 15 | 19 | `<select class="input" id="${id}" name="side">${SIDES.map((s) => `<option value="${s}"${s === selected ? " selected" : ""}>${escape(SIDE_CHOICE[s])}</option>`).join("")}</select>`; |
src/pages/timeline.ts +1
| @@ -42,6 +42,7 @@ export function timelinePage(input: { who: Who; agent?: Agent | undefined; deal: | ||
| 42 | 42 | const figures = [ |
| 43 | 43 | deal.sale_price === null ? "" : `Sale price ${dollars(deal.sale_price)}`, |
| 44 | 44 | deal.earnest_amount === null ? "" : `Earnest money ${dollars(deal.earnest_amount)}`, |
| 45 | deal.cash === 1 ? "Cash purchase" : "", | |
| 45 | 46 | ].filter((p) => p !== ""); |
| 46 | 47 | const body = `<p class="crumb timeline-tools"><a href="/deals/${deal.id}">← Back to the deal</a> · <button type="button" class="button button-small" data-print hidden>Print</button> <span class="muted">or your browser's print (Ctrl/Cmd+P)</span></p> |
| 47 | 48 | <section class="timeline"> |
src/reminders.ts +2
| @@ -101,6 +101,8 @@ export function recipients(deal: DealView, deadline: DeadlineView, moment: Momen | ||
| 101 | 101 | const roles = new Set<PartyRole>( |
| 102 | 102 | moment === "late" ? [deadline.owes] : [deadline.owes, ...KIND[deadline.kind].notify], |
| 103 | 103 | ); |
| 104 | // A cash purchase has no loan, so a lender added by hand is not told. | |
| 105 | if (deal.cash === 1) roles.delete("lender"); | |
| 104 | 106 | return deal.parties.filter((p) => roles.has(p.role)); |
| 105 | 107 | } |
| 106 | 108 |
src/routes.ts +7
| @@ -286,6 +286,7 @@ export const DEAL: Schema = { | ||
| 286 | 286 | closing_time: CLOSING_TIME, |
| 287 | 287 | closing_place: CLOSING_PLACE, |
| 288 | 288 | business_days: { enum: [0, 1] }, |
| 289 | cash: { enum: [0, 1], description: "1 for a cash purchase: no appraisal or financing date, and no lender is told." }, | |
| 289 | 290 | author_id: { type: "string" }, |
| 290 | 291 | author_name: { type: "string" }, |
| 291 | 292 | created_at: { type: "string", format: "date-time" }, |
| @@ -408,6 +409,7 @@ const NEW_DEAL: Schema = { | ||
| 408 | 409 | title: { type: "integer", minimum: 0, maximum: 180, default: DEFAULT_LENGTHS.title }, |
| 409 | 410 | walkthrough: { type: "integer", minimum: 0, maximum: 180, default: DEFAULT_LENGTHS.walkthrough }, |
| 410 | 411 | business_days: { type: "boolean", default: standard.businessDays }, |
| 412 | cash: { type: "boolean", default: false, description: "A cash purchase (no loan): the deal gets no Appraisal due or Financing contingency date and no lender is told. Anything but a boolean is a 422 naming cash." }, | |
| 411 | 413 | sale_price: { ...FIGURE, description: "Optional, whole dollars." }, |
| 412 | 414 | earnest_amount: { ...FIGURE, description: "Optional, whole dollars; the earnest money reminder says it." }, |
| 413 | 415 | commission_rate: { ...RATE, description: "Optional, hundredths of a percent (250 is 2.5%), 0 to 1000." }, |
| @@ -658,8 +660,12 @@ const HELD = "Held until tomorrow."; | ||
| 658 | 660 | const fromForm = (f: Record<string, unknown>): Record<string, unknown> => ({ |
| 659 | 661 | ...f, |
| 660 | 662 | business_days: f.business_days ?? "0", |
| 663 | cash: cashFromForm(f.cash), | |
| 661 | 664 | }); |
| 662 | 665 | |
| 666 | /** A ticked box ("on", "1") is cash, an absent or "0" one is not; any other text stays as sent and is refused naming cash. */ | |
| 667 | const cashFromForm = (v: unknown): unknown => (v === undefined || v === "" || v === "0" ? false : v === "on" || v === "1" ? true : v); | |
| 668 | ||
| 663 | 669 | /** A new deal from a form or a JSON body: the same names either way. */ |
| 664 | 670 | const newDeal = (f: Record<string, unknown>): NewDeal => ({ |
| 665 | 671 | address: f.address, |
| @@ -676,6 +682,7 @@ const newDeal = (f: Record<string, unknown>): NewDeal => ({ | ||
| 676 | 682 | walkthrough: f.walkthrough, |
| 677 | 683 | }, |
| 678 | 684 | businessDays: f.business_days, |
| 685 | cash: f.cash, | |
| 679 | 686 | salePrice: f.sale_price, |
| 680 | 687 | earnestAmount: f.earnest_amount, |
| 681 | 688 | commissionRate: f.commission_rate, |
src/terminal.test.ts +49 −7
| @@ -151,7 +151,7 @@ test("e with an empty answer keeps that part of the draft; too long a message is | ||
| 151 | 151 | |
| 152 | 152 | test("n opens a deal from five answers, and shows it", () => { |
| 153 | 153 | const t = terminal(db, alice, context); |
| 154 | press(t, "n", "31 Birch Row\r", "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "\r"); | |
| 154 | press(t, "n", "31 Birch Row\r", "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "\r", "\r"); | |
| 155 | 155 | const listed = listDeals(db, alice); |
| 156 | 156 | if (!listed.ok) throw new Error(listed.message); |
| 157 | 157 | const made = listed.value.find((d) => d.address === "31 Birch Row"); |
| @@ -160,7 +160,7 @@ test("n opens a deal from five answers, and shows it", () => { | ||
| 160 | 160 | expect(lines(t).join("\n")).toContain("Opened 31 Birch Row"); |
| 161 | 161 | expect(lines(t)).toContain("31 Birch Row"); |
| 162 | 162 | // A bad answer is the action's to refuse, and nothing is opened. |
| 163 | press(t, "d", "n", "x\r", "A\r", "B\r", "soon\r", "later\r", "\r"); | |
| 163 | press(t, "d", "n", "x\r", "A\r", "B\r", "soon\r", "later\r", "\r", "\r"); | |
| 164 | 164 | expect(lines(t).join("\n")).toContain("The address is 3 to 200 characters."); |
| 165 | 165 | }); |
| 166 | 166 | |
| @@ -168,7 +168,7 @@ test("c lists the dates n would create and writes nothing; a guest is asked to s | ||
| 168 | 168 | const before = listDeals(db, alice); |
| 169 | 169 | if (!before.ok) throw new Error(before.message); |
| 170 | 170 | const t = terminal(db, alice, context); |
| 171 | press(t, "c", "44 Cedar Way\r", "Kim Buyer\r", "Lou Seller\r", "2026-10-02\r", "2026-11-20\r", "\r"); | |
| 171 | press(t, "c", "44 Cedar Way\r", "Kim Buyer\r", "Lou Seller\r", "2026-10-02\r", "2026-11-20\r", "\r", "\r"); | |
| 172 | 172 | const shown = lines(t).join("\n"); |
| 173 | 173 | expect(shown).toContain("Dates for 44 Cedar Way"); |
| 174 | 174 | expect(shown).toContain("Mon, Oct 12"); |
| @@ -177,7 +177,7 @@ test("c lists the dates n would create and writes nothing; a guest is asked to s | ||
| 177 | 177 | const after = listDeals(db, alice); |
| 178 | 178 | if (!after.ok) throw new Error(after.message); |
| 179 | 179 | expect(after.value.length).toBe(before.value.length); |
| 180 | press(t, "c", "x\r", "A\r", "B\r", "soon\r", "later\r", "\r"); | |
| 180 | press(t, "c", "x\r", "A\r", "B\r", "soon\r", "later\r", "\r", "\r"); | |
| 181 | 181 | expect(lines(t).join("\n")).toContain("The address is 3 to 200 characters."); |
| 182 | 182 | const guest = terminal(db, { role: "anon" }, context); |
| 183 | 183 | guest.press("c"); |
| @@ -844,15 +844,15 @@ test("a signed-out terminal is not asked for a closing time", () => { | ||
| 844 | 844 | |
| 845 | 845 | test("n asks which side, defaults to Buyer's agent, and refuses an unknown word", () => { |
| 846 | 846 | const t = terminal(db, alice, context); |
| 847 | press(t, "n", "51 Side St\r", "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "Listing agent\r"); | |
| 847 | press(t, "n", "51 Side St\r", "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "Listing agent\r", "\r"); | |
| 848 | 848 | const listed = listDeals(db, alice); |
| 849 | 849 | if (!listed.ok) throw new Error(listed.message); |
| 850 | 850 | expect(listed.value.find((d) => d.address === "51 Side St")?.side).toBe("listing"); |
| 851 | press(t, "d", "n", "52 Side St\r", "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "\r"); | |
| 851 | press(t, "d", "n", "52 Side St\r", "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "\r", "\r"); | |
| 852 | 852 | const again = listDeals(db, alice); |
| 853 | 853 | if (!again.ok) throw new Error(again.message); |
| 854 | 854 | expect(again.value.find((d) => d.address === "52 Side St")?.side).toBe("buyer"); |
| 855 | press(t, "d", "n", "53 Side St\r", "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "seller\r"); | |
| 855 | press(t, "d", "n", "53 Side St\r", "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "seller\r", "\r"); | |
| 856 | 856 | expect(lines(t).join("\n")).toContain("Side is buyer, listing or both."); |
| 857 | 857 | const last = listDeals(db, alice); |
| 858 | 858 | if (!last.ok) throw new Error(last.message); |
| @@ -877,3 +877,45 @@ test("the side is shown on the deal, the clock and the week, and Y changes it", | ||
| 877 | 877 | press(t, "w"); |
| 878 | 878 | expect(lines(t).join("\n")).toContain("[Listing]"); |
| 879 | 879 | }); |
| 880 | ||
| 881 | test("n asks if the offer is cash: yes opens a cash deal with no loan dates, no and enter stay financed, anything else is refused", () => { | |
| 882 | const t = terminal(db, alice, context); | |
| 883 | const answers = (address: string, cash: string) => ["n", `${address}\r`, "Kim Buyer\r", "Lou Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "\r", cash]; | |
| 884 | const find = (address: string) => { | |
| 885 | const listed = listDeals(db, alice); | |
| 886 | if (!listed.ok) throw new Error(listed.message); | |
| 887 | return listed.value.find((d) => d.address === address); | |
| 888 | }; | |
| 889 | press(t, ...answers("61 Cash St", "yes\r")); | |
| 890 | const cash = find("61 Cash St")!; | |
| 891 | expect(cash.cash).toBe(1); | |
| 892 | expect(cash.deadlines.some((d) => d.kind === "appraisal" || d.kind === "financing")).toBe(false); | |
| 893 | press(t, "d", ...answers("62 Cash St", "no\r")); | |
| 894 | expect(find("62 Cash St")?.cash).toBe(0); | |
| 895 | press(t, "d", ...answers("63 Cash St", "\r")); | |
| 896 | expect(find("63 Cash St")?.cash).toBe(0); | |
| 897 | for (const word of ["y", "Yes please", "maybe"]) { | |
| 898 | press(t, "d", ...answers("64 Cash St", `${word}\r`)); | |
| 899 | expect(lines(t).join("\n")).toContain("Cash is yes or no."); | |
| 900 | expect(find("64 Cash St")).toBeUndefined(); | |
| 901 | } | |
| 902 | }); | |
| 903 | ||
| 904 | test("c with yes lists no appraisal or financing date, and with enter lists them; nothing is written", () => { | |
| 905 | const t = terminal(db, alice, context); | |
| 906 | const preview = (cash: string) => { | |
| 907 | press(t, "d", "c", "70 Preview Ln\r", "Kim Buyer\r", "Lou Seller\r", "2026-10-02\r", "2026-11-20\r", "\r", cash); | |
| 908 | const screen = lines(t).join("\n"); | |
| 909 | return screen.slice(screen.lastIndexOf("Dates for 70 Preview Ln")); | |
| 910 | }; | |
| 911 | const cashScreen = preview("yes\r"); | |
| 912 | expect(cashScreen).toContain("Dates for 70 Preview Ln"); | |
| 913 | expect(cashScreen).not.toContain("Appraisal"); | |
| 914 | expect(cashScreen).not.toContain("Financing"); | |
| 915 | const loanScreen = preview("\r"); | |
| 916 | expect(loanScreen).toContain("Appraisal"); | |
| 917 | expect(loanScreen).toContain("Financing"); | |
| 918 | const listed = listDeals(db, alice); | |
| 919 | if (!listed.ok) throw new Error(listed.message); | |
| 920 | expect(listed.value.some((d) => d.address === "70 Preview Ln")).toBe(false); | |
| 921 | }); |
src/terminal.ts +7 −4
| @@ -90,6 +90,7 @@ const esc = "\x1b["; | ||
| 90 | 90 | const dim = (s: string): string => `${esc}2m${s}${esc}0m`; |
| 91 | 91 | const bold = (s: string): string => `${esc}1m${s}${esc}0m`; |
| 92 | 92 | /** Audit rows to a screen. */ |
| 93 | const CASH_REFUSAL = "Cash is yes or no."; | |
| 93 | 94 | const ACTIVITY_ROWS = 20; |
| 94 | 95 | const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2", waived: "2" }; |
| 95 | 96 | const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`; |
| @@ -643,13 +644,15 @@ export function terminal( | ||
| 643 | 644 | if (!may.ok) said = may.message; |
| 644 | 645 | else |
| 645 | 646 | prompt = { |
outdated
Only |
||
| 646 | steps: ["Property address", "Buyer", "Seller", "Contract date (YYYY-MM-DD)", "Closing date (YYYY-MM-DD)", "Side: Buyer's agent, Listing agent or Both (enter for Buyer's agent)"], | |
| 647 | steps: ["Property address", "Buyer", "Seller", "Contract date (YYYY-MM-DD)", "Closing date (YYYY-MM-DD)", "Side: Buyer's agent, Listing agent or Both (enter for Buyer's agent)", "Cash offer, no loan? Type yes or no (enter for no, a financed deal)"], | |
| 647 | 648 | answers: [], |
| 648 | 649 | text: "", |
| 649 | finish: ([address, buyer, seller, contractDate, closingDate, typedSide]) => { | |
| 650 | finish: ([address, buyer, seller, contractDate, closingDate, typedSide, typedCash]) => { | |
| 650 | 651 | const side = sideTyped(typedSide ?? ""); |
| 651 | 652 | if (side === undefined) return SIDE_REFUSAL; |
| 652 | const input: NewDeal = { address, buyer, seller, contractDate, closingDate, side }; | |
| 653 | const word = (typedCash ?? "").trim().toLowerCase(); | |
| 654 | if (word !== "" && word !== "yes" && word !== "no") return CASH_REFUSAL; | |
| 655 | const input: NewDeal = { address, buyer, seller, contractDate, closingDate, side, cash: word === "yes" }; | |
| 653 | 656 | if (key === "c") return previewDates(input); |
| 654 | 657 | const made = createDeal(db, me, input); |
| 655 | 658 | if (!made.ok && made.error === "conflict" && made.existing !== undefined) { |
| @@ -859,7 +862,7 @@ export function terminal( | ||
| 859 | 862 | const deal = openDeal(); |
| 860 | 863 | if (deal === undefined) lines.push(dim("That deal is gone.")); |
| 861 | 864 | else { |
| 862 | lines.push(bold(deal.address), ...(deal.fell_through ? [bold(`Fell through on ${spoken(fellOn(deal))}: ${deal.fell_reason ?? ""}`)] : []), ...(deal.closed ? [bold(`Closed on ${spoken(closedOn(deal))}`)] : []), dim(`${SIDE_LABEL[deal.side]} · under contract ${spoken(deal.contract_date)} · closes ${spoken(deal.closing)}, ${relative(deal.closing, day)}`), ...(deal.closing_time === null && deal.closing_place === null ? [] : [dim(closingLine(deal))]), ""); | |
| 865 | lines.push(bold(deal.address), ...(deal.fell_through ? [bold(`Fell through on ${spoken(fellOn(deal))}: ${deal.fell_reason ?? ""}`)] : []), ...(deal.closed ? [bold(`Closed on ${spoken(closedOn(deal))}`)] : []), dim(`${SIDE_LABEL[deal.side]}${deal.cash === 1 ? " · Cash" : ""} · under contract ${spoken(deal.contract_date)} · closes ${spoken(deal.closing)}, ${relative(deal.closing, day)}`), ...(deal.closing_time === null && deal.closing_place === null ? [] : [dim(closingLine(deal))]), ""); | |
| 863 | 866 | deal.deadlines.forEach((date, i) => lines.push(dateLine({ deal, date }, i, false))); |
| 864 | 867 | if (deal.conflicts.length > 0) lines.push("", ...deal.conflicts.map((c) => tint("overdue", `! ${conflictLine(c)}`))); |
| 865 | 868 | lines.push("", bold("Parties")); |
new above
offline
Accepts string forms for every door, so JSON
cash:"true"is stored as cash. Issue: anything other than a boolean is a 422. Restrict string forms to the form door.