Public: anyone can read this; the crew can change it.
Add a deal from a contract's key dates in one short form, with every date checked before it is saved #286
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/284-add-a-deal-from-a-contract-s-key-dates-i → main 4 commits fork 2 threads · 2 unresolved
9 files
changed +200
−20
README.md +7 −2
| @@ -103,8 +103,13 @@ days ahead. | ||
| 103 | 103 | |
| 104 | 104 | ## Opening and shaping a deal |
| 105 | 105 | |
| 106 | **New deal** asks for an address, buyer, seller, contract date and closing | |
| 107 | date, and which side you are on. The standard lengths (earnest money deposit 3 | |
| 106 | **New deal** asks for an address, buyer, seller (with an optional email and | |
| 107 | phone for each), contract date and closing date, and which side you are on. | |
| 108 | Each mistake is named in a sentence beside its field and nothing is saved until | |
| 109 | all are right; a good deal lands on its own page with every date and the | |
| 110 | reminders drafted. Both doors ask for the contacts: the terminal's **n** asks | |
| 111 | for each party's email or phone after the side and cash questions (enter skips; | |
| 112 | an answer with an @ is the email, anything else the phone). The standard lengths (earnest money deposit 3 | |
| 108 | 113 | days, inspection 10, appraisal 21, financing 30, title 14, final walkthrough |
| 109 | 114 | the day before closing) are filled in and you can change them; **Check the |
| 110 | 115 | dates** shows every date the deal would get without saving anything. Tick |
contract/openapi.json +20
| @@ -476,6 +476,26 @@ | ||
| 476 | 476 | "maximum": 1000, |
| 477 | 477 | "description": "Optional, hundredths of a percent (250 is 2.5%), 0 to 1000." |
| 478 | 478 | }, |
| 479 | "buyer_email": { | |
| 480 | "type": "string", | |
| 481 | "maxLength": 200, | |
| 482 | "description": "Optional." | |
| 483 | }, | |
| 484 | "buyer_phone": { | |
| 485 | "type": "string", | |
| 486 | "maxLength": 30, | |
| 487 | "description": "Optional." | |
| 488 | }, | |
| 489 | "seller_email": { | |
| 490 | "type": "string", | |
| 491 | "maxLength": 200, | |
| 492 | "description": "Optional." | |
| 493 | }, | |
| 494 | "seller_phone": { | |
| 495 | "type": "string", | |
| 496 | "maxLength": 30, | |
| 497 | "description": "Optional." | |
| 498 | }, | |
| 479 | 499 | "side": { |
| 480 | 500 | "enum": [ |
| 481 | 501 | "buyer", |
src/deals.ts +31 −4
| @@ -534,6 +534,11 @@ export interface NewDeal { | ||
| 534 | 534 | readonly address: unknown; |
| 535 | 535 | readonly buyer: unknown; |
| 536 | 536 | readonly seller: unknown; |
| 537 | /** Optional contacts for the two parties; blank is none. */ | |
| 538 | readonly buyerEmail?: unknown; | |
| 539 | readonly buyerPhone?: unknown; | |
| 540 | readonly sellerEmail?: unknown; | |
| 541 | readonly sellerPhone?: unknown; | |
| 537 | 542 | readonly contractDate: unknown; |
| 538 | 543 | readonly closingDate: unknown; |
| 539 | 544 | readonly lengths?: Partial<Record<keyof Lengths, unknown>>; |
| @@ -556,6 +561,10 @@ export interface Plan { | ||
| 556 | 561 | readonly address: string; |
| 557 | 562 | readonly buyer: string; |
| 558 | 563 | readonly seller: string; |
| 564 | readonly buyerEmail?: string; | |
| 565 | readonly buyerPhone?: string; | |
| 566 | readonly sellerEmail?: string; | |
| 567 | readonly sellerPhone?: string; | |
| 559 | 568 | readonly contractDate: string; |
| 560 | 569 | readonly closingDate: string; |
| 561 | 570 | readonly lengths: Lengths; |
| @@ -570,6 +579,14 @@ export interface Plan { | ||
| 570 | 579 | /** 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. */ |
| 571 | 580 | const cashOf = (v: unknown): boolean | undefined => (v === undefined ? false : typeof v === "boolean" ? v : undefined); |
| 572 | 581 | |
| 582 | /** What each contact field says when refused: one sentence per field, not derived from `partyText`'s. */ | |
| 583 | const CONTACT_REFUSAL: Readonly<Record<string, string>> = { | |
| 584 | buyer_email: "The buyer's email looks like [email protected], up to 200 characters.", | |
| 585 | buyer_phone: "The buyer's phone is digits, spaces and + - ( ) . up to 30 characters.", | |
| 586 | seller_email: "The seller's email looks like [email protected], up to 200 characters.", | |
| 587 | seller_phone: "The seller's phone is digits, spaces and + - ( ) . up to 30 characters.", | |
| 588 | }; | |
| 589 | ||
| 573 | 590 | export function plan(input: NewDeal): Result<Plan> { |
| 574 | 591 | const address = line(input.address, 3, 200); |
| 575 | 592 | if (address === undefined) |
| @@ -582,6 +599,15 @@ export function plan(input: NewDeal): Result<Plan> { | ||
| 582 | 599 | "Name the buyer and the seller (up to 100 characters each).", |
| 583 | 600 | buyer === undefined ? "buyer" : "seller", |
| 584 | 601 | ); |
| 602 | const contacts: Record<string, string> = {}; | |
| 603 | for (const [who, name] of [["buyer", buyer], ["seller", seller]] as const) { | |
| 604 | for (const kind of ["email", "phone"] as const) { | |
| 605 | const key = `${who}${kind === "email" ? "Email" : "Phone"}` as const; | |
| 606 | const text = partyText({ name, [kind]: input[key] }); | |
| 607 | if (!text.ok) return fail("invalid", CONTACT_REFUSAL[`${who}_${kind}`], `${who}_${kind}`); | |
| 608 | contacts[key] = text.value[kind]; | |
| 609 | } | |
| 610 | } | |
| 585 | 611 | const { contractDate, closingDate } = input; |
| 586 | 612 | if (!isDate(contractDate) || !isDate(closingDate)) |
| 587 | 613 | return fail( |
| @@ -614,7 +640,7 @@ export function plan(input: NewDeal): Result<Plan> { | ||
| 614 | 640 | if (!commissionRate.ok) return commissionRate; |
| 615 | 641 | const side = sideOf(input.side); |
| 616 | 642 | if (side === undefined) return fail("invalid", SIDE_REFUSAL, "side"); |
| 617 | return ok({ address, buyer, seller, contractDate, closingDate, lengths, businessDays, cash, salePrice: salePrice.value, earnestAmount: earnestAmount.value, commissionRate: commissionRate.value, side }); | |
| 643 | return ok({ address, buyer, seller, ...contacts, contractDate, closingDate, lengths, businessDays, cash, salePrice: salePrice.value, earnestAmount: earnestAmount.value, commissionRate: commissionRate.value, side }); | |
| 618 | 644 | } |
| 619 | 645 | |
| 620 | 646 | /** An address as two typings of one house agree on it: trimmed, spaces collapsed, lower case, no trailing period. */ |
| @@ -675,10 +701,11 @@ export function insertDeal( | ||
| 675 | 701 | ) |
| 676 | 702 | .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)!; |
| 677 | 703 | const party = db.query( |
| 678 | "INSERT INTO party (deal_id, role, name) VALUES (?1, ?2, ?3)", | |
| 704 | "INSERT INTO party (deal_id, role, name, contact, email, phone) VALUES (?1, ?2, ?3, ?4, ?5, ?6)", | |
| 679 | 705 | ); |
| 680 | party.run(deal.id, "buyer", p.buyer); | |
| 681 | party.run(deal.id, "seller", p.seller); | |
| 706 | const [be, bp, se, sp] = [p.buyerEmail ?? "", p.buyerPhone ?? "", p.sellerEmail ?? "", p.sellerPhone ?? ""]; | |
| 707 | party.run(deal.id, "buyer", p.buyer, be || bp, be, bp); | |
| 708 | party.run(deal.id, "seller", p.seller, se || sp, se, sp); | |
| 682 | 709 | const deadline = db.query( |
| 683 | 710 | "INSERT INTO deadline (deal_id, kind, label, due, owes, what, lead_days) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)", |
| 684 | 711 | ); |
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", "\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", "\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", "\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", "\r", "\r", "yes\r"]) t.press(c); | |
| 56 | 56 | expect(text()).toContain("Opened 1418 Alder Court"); |
| 57 | 57 | }); |
| 58 | 58 |
src/newdeal.test.ts added +89
| @@ -0,0 +1,89 @@ | ||
| 1 | /** The add-deal form: every field checked at the boundary, a saved deal on the clock, escaped, same-origin only. */ | |
| 2 | import { afterAll, beforeEach, expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { forgetRationing } from "./security.ts"; | |
| 7 | import { serve } from "./server.ts"; | |
| 8 | import { sign } from "./who.ts"; | |
| 9 | ||
| 10 | const KEY = "a-key-only-the-forge-holds"; | |
| 11 | const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-newdeal-")), identityKey: KEY }); | |
| 12 | const base = `http://${server.hostname}:${server.port}`; | |
| 13 | afterAll(() => server.stop(true)); | |
| 14 | beforeEach(forgetRationing); | |
| 15 | const identity = `u1|alice|user|${Date.now() + 600_000}`; | |
| 16 | const me = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) }; | |
| 17 | const good: Record<string, string> = { address: "12 Maple Court", buyer: "Ann Buyer", seller: "Sam Seller", contract_date: "2026-10-01", closing_date: "2026-12-01", open_anyway: "on" }; | |
| 18 | const post = (fields: Record<string, string>, headers: Record<string, string> = {}) => { | |
| 19 | const f = new FormData(); | |
| 20 | for (const [k, v] of Object.entries(fields)) f.set(k, v); | |
| 21 | return fetch(base + "/deals", { method: "POST", body: f, headers: { ...me, ...headers }, redirect: "manual" }); | |
| 22 | }; | |
| 23 | ||
| 24 | const refusals: [string, Record<string, string>, string, string][] = [ | |
| 25 | ["address", { address: "ab" }, "address", "The address is 3 to 200 characters."], | |
| 26 | ["long address", { address: "x".repeat(201) }, "address", "The address is 3 to 200 characters."], | |
| 27 | ["buyer", { buyer: "" }, "buyer", "Name the buyer and the seller (up to 100 characters each)."], | |
| 28 | ["seller", { seller: "" }, "seller", "Name the buyer and the seller (up to 100 characters each)."], | |
| 29 | ["buyer email", { buyer_email: "nope" }, "buyer_email", "The buyer's email looks like [email protected], up to 200 characters."], | |
| 30 | ["seller phone", { seller_phone: "call me" }, "seller_phone", "The seller's phone is digits, spaces and + - ( ) . up to 30 characters."], | |
| 31 | ["contract date", { contract_date: "2026-02-30" }, "contract_date", "The contract and closing dates are dates (YYYY-MM-DD)."], | |
| 32 | ["closing date", { closing_date: "soon" }, "closing_date", "The contract and closing dates are dates (YYYY-MM-DD)."], | |
| 33 | ["order", { closing_date: "2026-09-01" }, "closing_date", "Closing comes after the contract date."], | |
| 34 | ["price", { sale_price: "$4.5" }, "sale_price", "The sale price is whole dollars, digits only, 0 to 100,000,000."], | |
| 35 | ]; | |
| 36 | ||
| 37 | for (const [name, change, field, sentence] of refusals) | |
| 38 | test(`a bad ${name} is refused with its sentence beside the field`, async () => { | |
| 39 | const res = await post({ ...good, ...change }); | |
| 40 | expect(res.status).toBe(422); | |
| 41 | const html = await res.text(); | |
| 42 | expect(html).toContain(`id="${field}-why"`); | |
| 43 | expect(html.replaceAll("'", "'")).toContain(sentence); | |
| 44 | }); | |
| 45 | ||
| 46 | test("a saved deal lands on its page and is on the clock, contacts kept", async () => { | |
| 47 | const res = await post({ ...good, buyer_email: "[email protected]", seller_phone: "555-0100" }); | |
| 48 | expect(res.status).toBe(303); | |
| 49 | const page = await (await fetch(base + res.headers.get("location")!, { headers: me })).text(); | |
| 50 | expect(page).toContain("12 Maple Court"); | |
| 51 | expect(page).toContain("[email protected]"); | |
| 52 | expect(page).toContain("555-0100"); | |
| 53 | expect(await (await fetch(base + "/", { headers: me })).text()).toContain("12 Maple Court"); | |
| 54 | }); | |
| 55 | ||
| 56 | test("a hostile address is escaped on the form and on the deal", async () => { | |
| 57 | const address = `<script>alert(1)</script>"><img src=x>`; | |
| 58 | const bad = await (await post({ ...good, address, buyer: "" })).text(); | |
| 59 | expect(bad).not.toContain("<script>alert(1)"); | |
| 60 | const res = await post({ ...good, address }); | |
| 61 | const page = await (await fetch(base + res.headers.get("location")!, { headers: me })).text(); | |
| 62 | expect(page).not.toContain("<script>alert(1)"); | |
| 63 | expect(page).toContain("<script>alert(1)"); | |
| 64 | }); | |
| 65 | ||
| 66 | test("a POST from another origin is refused and saves nothing", async () => { | |
| 67 | const res = await post({ ...good, address: "99 Foreign Road" }, { origin: "https://evil.example" }); | |
| 68 | expect(res.status).toBe(403); | |
| 69 | expect(await (await fetch(base + "/", { headers: me })).text()).not.toContain("99 Foreign Road"); | |
| 70 | }); | |
| 71 | ||
| 72 | test("the JSON door takes the contacts too and saves them on the parties", async () => { | |
| 73 | const res = await fetch(base + "/api/deals", { | |
| 74 | method: "POST", | |
| 75 | headers: { ...me, "content-type": "application/json" }, | |
| 76 | body: JSON.stringify({ ...good, address: "14 Api Lane", open_anyway: true, buyer_email: "[email protected]", seller_phone: "555-0100" }), | |
| 77 | }); | |
| 78 | expect(res.status).toBe(201); | |
| 79 | const deal = (await res.json()) as { parties: { role: string; email: string; phone: string }[] }; | |
| 80 | expect(deal.parties.find((p) => p.role === "buyer")?.email).toBe("[email protected]"); | |
| 81 | expect(deal.parties.find((p) => p.role === "seller")?.phone).toBe("555-0100"); | |
| 82 | const bad = await fetch(base + "/api/deals", { | |
| 83 | method: "POST", | |
| 84 | headers: { ...me, "content-type": "application/json" }, | |
| 85 | body: JSON.stringify({ ...good, address: "15 Api Lane", open_anyway: true, buyer_email: "nope" }), | |
| 86 | }); | |
| 87 | expect(bad.status).toBe(422); | |
| 88 | expect(JSON.stringify(await bad.json())).toContain("The buyer's email looks like [email protected]"); | |
| 89 | }); |
src/pages/deal.ts +8
| @@ -492,6 +492,14 @@ export function newDealPage(input: { | ||
| 492 | 492 | <label>Buyer<input class="input" name="buyer" required maxlength="100" value="${val("buyer", "")}"${bad("buyer")}>${why("buyer")}</label> |
| 493 | 493 | <label>Seller<input class="input" name="seller" required maxlength="100" value="${val("seller", "")}"${bad("seller")}>${why("seller")}</label> |
| 494 | 494 | </div> |
| 495 | <div class="pair"> | |
| 496 | <label>Buyer email <span class="muted">(optional)</span><input class="input" type="email" name="buyer_email" maxlength="200" autocomplete="off" value="${val("buyer_email", "")}"${bad("buyer_email")}>${why("buyer_email")}</label> | |
| 497 | <label>Buyer phone <span class="muted">(optional)</span><input class="input" type="tel" name="buyer_phone" maxlength="30" autocomplete="off" value="${val("buyer_phone", "")}"${bad("buyer_phone")}>${why("buyer_phone")}</label> | |
| 498 | </div> | |
| 499 | <div class="pair"> | |
| 500 | <label>Seller email <span class="muted">(optional)</span><input class="input" type="email" name="seller_email" maxlength="200" autocomplete="off" value="${val("seller_email", "")}"${bad("seller_email")}>${why("seller_email")}</label> | |
| 501 | <label>Seller phone <span class="muted">(optional)</span><input class="input" type="tel" name="seller_phone" maxlength="30" autocomplete="off" value="${val("seller_phone", "")}"${bad("seller_phone")}>${why("seller_phone")}</label> | |
| 502 | </div> | |
| 495 | 503 | <div class="pair"> |
| 496 | 504 | <label>Contract date<input class="input" type="date" name="contract_date" required value="${val("contract_date", on)}"${bad("contract_date")}>${why("contract_date")}</label> |
| 497 | 505 | <label>Closing date<input class="input" type="date" name="closing_date" required value="${val("closing_date", addDays(on, 35))}"${bad("closing_date")}>${why("closing_date")}</label> |
src/routes.ts +8
| @@ -460,6 +460,10 @@ const NEW_DEAL: Schema = { | ||
| 460 | 460 | sale_price: { ...FIGURE, description: "Optional, whole dollars." }, |
| 461 | 461 | earnest_amount: { ...FIGURE, description: "Optional, whole dollars; the earnest money reminder says it." }, |
| 462 | 462 | commission_rate: { ...RATE, description: "Optional, hundredths of a percent (250 is 2.5%), 0 to 1000." }, |
| 463 | buyer_email: { type: "string", maxLength: 200, description: "Optional." }, | |
| 464 | buyer_phone: { type: "string", maxLength: 30, description: "Optional." }, | |
| 465 | seller_email: { type: "string", maxLength: 200, description: "Optional." }, | |
| 466 | seller_phone: { type: "string", maxLength: 30, description: "Optional." }, | |
| 463 | 467 | side: { enum: [...SIDES], default: "buyer", description: "Which side the agent represents." }, |
| 464 | 468 | open_anyway: { type: "boolean", default: false }, |
| 465 | 469 | }, |
| @@ -721,6 +725,10 @@ const newDeal = (f: Record<string, unknown>): NewDeal => ({ | ||
| 721 | 725 | address: f.address, |
| 722 | 726 | buyer: f.buyer, |
| 723 | 727 | seller: f.seller, |
| 728 | buyerEmail: f.buyer_email, | |
| 729 | buyerPhone: f.buyer_phone, | |
| 730 | sellerEmail: f.seller_email, | |
| 731 | sellerPhone: f.seller_phone, | |
| 724 | 732 | contractDate: f.contract_date, |
| 725 | 733 | closingDate: f.closing_date, |
| 726 | 734 | lengths: { |
src/terminal.test.ts +28 −9
| @@ -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", "\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", "\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", "\r"); | |
| 163 | press(t, "d", "n", "x\r", "A\r", "B\r", "soon\r", "later\r", "\r", "\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", "\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", "\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", "\r"); | |
| 180 | press(t, "c", "x\r", "A\r", "B\r", "soon\r", "later\r", "\r", "\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"); |
| @@ -877,15 +877,15 @@ test("a signed-out terminal is not asked for a closing time", () => { | ||
| 877 | 877 | |
| 878 | 878 | test("n asks which side, defaults to Buyer's agent, and refuses an unknown word", () => { |
| 879 | 879 | const t = terminal(db, alice, context); |
| 880 | 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"); | |
| 880 | 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", "\r", "\r"); | |
| 881 | 881 | const listed = listDeals(db, alice); |
| 882 | 882 | if (!listed.ok) throw new Error(listed.message); |
| 883 | 883 | expect(listed.value.find((d) => d.address === "51 Side St")?.side).toBe("listing"); |
| 884 | 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"); | |
| 884 | 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", "\r", "\r"); | |
| 885 | 885 | const again = listDeals(db, alice); |
| 886 | 886 | if (!again.ok) throw new Error(again.message); |
| 887 | 887 | expect(again.value.find((d) => d.address === "52 Side St")?.side).toBe("buyer"); |
| 888 | 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"); | |
| 888 | 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", "\r", "\r"); | |
| 889 | 889 | expect(lines(t).join("\n")).toContain("Side is buyer, listing or both."); |
| 890 | 890 | const last = listDeals(db, alice); |
| 891 | 891 | if (!last.ok) throw new Error(last.message); |
| @@ -913,7 +913,7 @@ test("the side is shown on the deal, the clock and the week, and Y changes it", | ||
| 913 | 913 | |
| 914 | 914 | 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", () => { |
| 915 | 915 | const t = terminal(db, alice, context); |
| 916 | 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]; | |
| 916 | 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, "\r", "\r"]; | |
| 917 | 917 | const find = (address: string) => { |
| 918 | 918 | const listed = listDeals(db, alice); |
| 919 | 919 | if (!listed.ok) throw new Error(listed.message); |
| @@ -937,7 +937,7 @@ test("n asks if the offer is cash: yes opens a cash deal with no loan dates, no | ||
| 937 | 937 | test("c with yes lists no appraisal or financing date, and with enter lists them; nothing is written", () => { |
| 938 | 938 | const t = terminal(db, alice, context); |
| 939 | 939 | const preview = (cash: string) => { |
| 940 | press(t, "d", "c", "70 Preview Ln\r", "Kim Buyer\r", "Lou Seller\r", "2026-10-02\r", "2026-11-20\r", "\r", cash); | |
| 940 | press(t, "d", "c", "70 Preview Ln\r", "Kim Buyer\r", "Lou Seller\r", "2026-10-02\r", "2026-11-20\r", "\r", cash, "\r", "\r"); | |
| 941 | 941 | const screen = lines(t).join("\n"); |
| 942 | 942 | return screen.slice(screen.lastIndexOf("Dates for 70 Preview Ln")); |
| 943 | 943 | }; |
| @@ -1007,6 +1007,25 @@ test("the deal view and the week say which other appointment the same day is les | ||
| 1007 | 1007 | expect(lines(t).join("\n")).toContain("Also at 10:00 am: Inspection, 7 Twin Ln"); |
| 1008 | 1008 | }); |
| 1009 | 1009 | |
| 1010 | test("n takes each party's email or phone: an @ is an email, anything else a phone, and a bad one is refused with its sentence", () => { | |
| 1011 | const t = terminal(db, alice, context); | |
| 1012 | const find = (address: string) => { | |
| 1013 | const listed = listDeals(db, alice); | |
| 1014 | if (!listed.ok) throw new Error(listed.message); | |
| 1015 | return listed.value.find((d) => d.address === address); | |
| 1016 | }; | |
| 1017 | press(t, "n", "61 Contact Ct\r", "Ann Buyer\r", "Sam Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "\r", "\r", "[email protected]\r", "555-0100\r"); | |
| 1018 | const made = find("61 Contact Ct"); | |
| 1019 | if (made === undefined) throw new Error("not opened"); | |
| 1020 | const buyer = made.parties.find((p) => p.role === "buyer"); | |
| 1021 | const seller = made.parties.find((p) => p.role === "seller"); | |
| 1022 | expect([buyer?.email, buyer?.phone]).toEqual(["[email protected]", ""]); | |
| 1023 | expect([seller?.email, seller?.phone]).toEqual(["", "555-0100"]); | |
| 1024 | press(t, "d", "n", "62 Contact Ct\r", "Ann Buyer\r", "Sam Seller\r", `${today(DEFAULT_ZONE)}\r`, `${addDays(today(DEFAULT_ZONE), 40)}\r`, "\r", "\r", "call me\r", "\r"); | |
| 1025 | expect(lines(t).join("\n")).toContain("The buyer's phone is digits, spaces and + - ( ) . up to 30 characters."); | |
| 1026 | expect(find("62 Contact Ct")).toBeUndefined(); | |
| 1027 | }); | |
| 1028 | ||
| 1010 | 1029 | test("G lists the ten tour steps from src/tour.ts, a guest is refused, ", () => { |
| 1011 | 1030 | const own = openDb(mkdtempSync(join(tmpdir(), "app-terminal-tour-"))); |
| 1012 | 1031 | const t = terminal(own, alice, context); |
src/terminal.ts +7 −3
| @@ -673,15 +673,19 @@ export function terminal( | ||
| 673 | 673 | if (!may.ok) said = may.message; |
| 674 | 674 | else |
| 675 | 675 | prompt = { |
| 676 | 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)"], | |
| 676 | 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)", "Buyer's email or phone (enter to skip)", "Seller's email or phone (enter to skip)"], | |
| 677 | 677 | answers: [], |
| 678 | 678 | text: "", |
| 679 | finish: ([address, buyer, seller, contractDate, closingDate, typedSide, typedCash]) => { | |
| 679 | finish: ([address, buyer, seller, contractDate, closingDate, typedSide, typedCash, buyerContact, sellerContact]) => { | |
outdated
New behaviour with no test: add a terminal test that enters an email and a phone and checks they are saved on the parties. Add a bad-value case too. |
||
| 680 | 680 | const side = sideTyped(typedSide ?? ""); |
| 681 | 681 | if (side === undefined) return SIDE_REFUSAL; |
| 682 | 682 | const word = (typedCash ?? "").trim().toLowerCase(); |
| 683 | 683 | if (word !== "" && word !== "yes" && word !== "no") return CASH_REFUSAL; |
| 684 | const input: NewDeal = { address, buyer, seller, contractDate, closingDate, side, cash: word === "yes" }; | |
| 684 | const reach = (v: string | undefined, who: "buyer" | "seller") => { | |
| 685 | const t = (v ?? "").trim(); | |
| 686 | return t.includes("@") ? { [`${who}Email`]: t } : { [`${who}Phone`]: t }; | |
| 687 | }; | |
| 688 | const input: NewDeal = { address, buyer, seller, contractDate, closingDate, side, cash: word === "yes", ...reach(buyerContact, "buyer"), ...reach(sellerContact, "seller") }; | |
| 685 | 689 | if (key === "c") return previewDates(input); |
| 686 | 690 | const made = createDeal(db, me, input); |
| 687 | 691 | if (!made.ok && made.error === "conflict" && made.existing !== undefined) { |
new above
offline
Rewriting partyText's message with a regex is brittle; use an explicit per-field sentence table.