Public: anyone can read this; the crew can change it.
Realtor.com is its own lead source: its leads get their own opener, their own row in the response record, and a sample lead #57
Check · Review · Land · Live done — Landed and live in production.
mason/speed-to-lead:mason/55-realtor-com-is-its-own-lead-source-its-l → main 3 commits fork
14 files
changed +187
−19
README.md +2 −2
| @@ -325,7 +325,7 @@ signed in can read it. The license number is required, because every | ||
| 325 | 325 | message shows it. Drafts you have not sent take the new profile at once; |
| 326 | 326 | messages already sent keep the signature they went out with. |
| 327 | 327 | |
| 328 | Under **How your first reply opens**, an admin can write the opening line for each source (Zillow, website, open house, referral), up to 160 characters on one line; leave one empty to keep the built-in wording. **Preview** shows the first reply to a sample lead in your words without saving; new first replies use them, drafts already on the desk keep theirs, and an opener too long to leave a text under its limit falls back to the built-in line for that text. | |
| 328 | Under **How your first reply opens**, an admin can write the opening line for each source (Zillow, Realtor.com, website, open house, referral), up to 160 characters on one line; leave one empty to keep the built-in wording. **Preview** shows the first reply to a sample lead in your words without saving; new first replies use them, drafts already on the desk keep theirs, and an opener too long to leave a text under its limit falls back to the built-in line for that text. | |
| 329 | 329 | |
| 330 | 330 | Until you save one, the app uses these environment variables (forge |
| 331 | 331 | Settings → App → Environment) or, failing those, a sample agent, Jordan |
| @@ -372,7 +372,7 @@ curl -X POST https://<app>/leads/1/state -H 'content-type: application/json' -d | ||
| 372 | 372 | curl -X POST https://<app>/tick # the day turns: follow-ups come due |
| 373 | 373 | |
| 374 | 374 | |
| 375 | `source` is `zillow`, `website`, `open_house` or `referral`. Names, | |
| 375 | `source` is `zillow`, `realtor_com`, `website`, `open_house` or `referral`. Names, | |
| 376 | 376 | emails, phones and messages are plain text: anything carrying control |
| 377 | 377 | characters is turned away. `POST /tick` is safe to call as often as you |
| 378 | 378 | like, but only as someone the forge has signed in — an unsigned scheduled |
contract/openapi.json +17
| @@ -98,6 +98,7 @@ | ||
| 98 | 98 | "source": { |
| 99 | 99 | "enum": [ |
| 100 | 100 | "zillow", |
| 101 | "realtor_com", | |
| 101 | 102 | "website", |
| 102 | 103 | "open_house", |
| 103 | 104 | "referral" |
| @@ -251,6 +252,7 @@ | ||
| 251 | 252 | "source": { |
| 252 | 253 | "enum": [ |
| 253 | 254 | "zillow", |
| 255 | "realtor_com", | |
| 254 | 256 | "website", |
| 255 | 257 | "open_house", |
| 256 | 258 | "referral" |
| @@ -509,6 +511,7 @@ | ||
| 509 | 511 | "source": { |
| 510 | 512 | "enum": [ |
| 511 | 513 | "zillow", |
| 514 | "realtor_com", | |
| 512 | 515 | "website", |
| 513 | 516 | "open_house", |
| 514 | 517 | "referral" |
| @@ -1446,6 +1449,10 @@ | ||
| 1446 | 1449 | "type": "string", |
| 1447 | 1450 | "maxLength": 160 |
| 1448 | 1451 | }, |
| 1452 | "realtor_com": { | |
| 1453 | "type": "string", | |
| 1454 | "maxLength": 160 | |
| 1455 | }, | |
| 1449 | 1456 | "website": { |
| 1450 | 1457 | "type": "string", |
| 1451 | 1458 | "maxLength": 160 |
| @@ -1535,6 +1542,10 @@ | ||
| 1535 | 1542 | "type": "string", |
| 1536 | 1543 | "maxLength": 160 |
| 1537 | 1544 | }, |
| 1545 | "realtor_com": { | |
| 1546 | "type": "string", | |
| 1547 | "maxLength": 160 | |
| 1548 | }, | |
| 1538 | 1549 | "website": { |
| 1539 | 1550 | "type": "string", |
| 1540 | 1551 | "maxLength": 160 |
| @@ -1610,6 +1621,10 @@ | ||
| 1610 | 1621 | "type": "string", |
| 1611 | 1622 | "maxLength": 160 |
| 1612 | 1623 | }, |
| 1624 | "realtor_com": { | |
| 1625 | "type": "string", | |
| 1626 | "maxLength": 160 | |
| 1627 | }, | |
| 1613 | 1628 | "website": { |
| 1614 | 1629 | "type": "string", |
| 1615 | 1630 | "maxLength": 160 |
| @@ -1879,6 +1894,7 @@ | ||
| 1879 | 1894 | "source": { |
| 1880 | 1895 | "enum": [ |
| 1881 | 1896 | "zillow", |
| 1897 | "realtor_com", | |
| 1882 | 1898 | "website", |
| 1883 | 1899 | "open_house", |
| 1884 | 1900 | "referral" |
| @@ -2221,6 +2237,7 @@ | ||
| 2221 | 2237 | "source": { |
| 2222 | 2238 | "enum": [ |
| 2223 | 2239 | "zillow", |
| 2240 | "realtor_com", | |
| 2224 | 2241 | "website", |
| 2225 | 2242 | "open_house", |
| 2226 | 2243 | "referral" |
src/actions.test.ts +1 −1
| @@ -242,7 +242,7 @@ test("the sample desk: twelve leads, some red, some mid-cadence; only an admin r | ||
| 242 | 242 | .map((l) => T0.getTime() - Date.parse(l.created_at)); |
| 243 | 243 | expect(waited.filter((ms) => ms >= 3_600_000).length).toBeGreaterThanOrEqual(3); |
| 244 | 244 | expect(waited.filter((ms) => ms < 300_000).length).toBeGreaterThanOrEqual(2); |
| 245 | expect(new Set(desk.map((l) => l.source)).size).toBe(4); | |
| 245 | expect(new Set(desk.map((l) => l.source)).size).toBe(5); | |
| 246 | 246 | expect(desk.some((l) => l.consent) && desk.some((l) => !l.consent)).toBe(true); |
| 247 | 247 | expect(desk.filter((l) => l.ready !== null && l.ready.day > 0).length).toBeGreaterThanOrEqual(2); |
| 248 | 248 | expect(desk.some((l) => l.state === "qualified")).toBe(true); |
src/actions.ts +2 −2
| @@ -214,7 +214,7 @@ export function sourceOf(value: unknown): Source | undefined { | ||
| 214 | 214 | const key = String(value ?? "") |
| 215 | 215 | .trim() |
| 216 | 216 | .toLowerCase() |
| 217 | .replace(/[\s-]+/g, "_") | |
| 217 | .replace(/[\s.-]+/g, "_") | |
| 218 | 218 | .replace(/_form$/, ""); |
| 219 | 219 | return (SOURCES as readonly string[]).includes(key) |
| 220 | 220 | ? (key as Source) |
| @@ -276,7 +276,7 @@ export function readNewLead(input: Record<string, unknown>): Result<NewLead> { | ||
| 276 | 276 | if (source === undefined) |
| 277 | 277 | return fail( |
| 278 | 278 | "invalid", |
| 279 | "The source is one of zillow, website, open_house or referral.", | |
| 279 | "The source is one of zillow, realtor_com, website, open_house or referral.", | |
| 280 | 280 | ); |
| 281 | 281 | if (message.length === 0 || message.length > 2000) |
| 282 | 282 | return fail("invalid", "What they asked is 1 to 2000 characters."); |
src/db.test.ts +31 −2
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import { expect, test } from "bun:test"; |
| 2 | import { Database } from "bun:sqlite"; | |
| 2 | 3 | import { mkdtempSync } from "node:fs"; |
| 3 | 4 | import { tmpdir } from "node:os"; |
| 4 | 5 | import { join } from "node:path"; |
| @@ -38,10 +39,38 @@ test("a database that ran the note columns before the openers still gets the ope | ||
| 38 | 39 | const db = openDb(dir); |
| 39 | 40 | // As a preview left it: the openers column never added, the version past the notes. |
| 40 | 41 | db.exec("ALTER TABLE profile DROP COLUMN openers"); |
| 41 | db.exec("DELETE FROM schema_version WHERE version > " + (migrations.length - 2)); | |
| 42 | const openers = migrations.findIndex((m) => m.includes("ADD COLUMN openers")); | |
| 43 | db.exec("DELETE FROM schema_version WHERE version > " + openers); | |
| 42 | 44 | expect(() => migrate(db)).not.toThrow(); |
| 43 | 45 | expect(db.query("SELECT openers FROM profile").all()).toBeDefined(); |
| 44 | 46 | // And the reverse: a column already there is not added again. |
| 45 | db.exec("DELETE FROM schema_version WHERE version > " + (migrations.length - 3)); | |
| 47 | db.exec("DELETE FROM schema_version WHERE version > " + openers); | |
| 46 | 48 | expect(() => migrate(db)).not.toThrow(); |
| 47 | 49 | }); |
| 50 | ||
| 51 | test("a database made before Realtor.com was a source keeps its leads, their messages and ids, and takes the new source", () => { | |
| 52 | const db = new Database(":memory:"); | |
| 53 | const at = migrations.findIndex((m) => m.includes("CREATE TABLE lead_new") && m.includes("'realtor_com'")); | |
| 54 | expect(at).toBeGreaterThan(0); | |
| 55 | // The schema as it stood before: every migration ahead of the rebuild. | |
| 56 | db.exec("CREATE TABLE schema_version (version INTEGER PRIMARY KEY, applied_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')))"); | |
| 57 | migrations.slice(0, at).forEach((sql, i) => { | |
| 58 | try { | |
| 59 | db.exec(sql); | |
| 60 | } catch (e) { | |
| 61 | if (!/duplicate column/.test(String(e))) throw e; // a column an earlier rebuild already carries | |
| 62 | } | |
| 63 | db.query("INSERT INTO schema_version (version) VALUES (?1)").run(i + 1); | |
| 64 | }); | |
| 65 | db.exec("INSERT INTO lead (id, name, email, source, message, consent) VALUES (7, 'Old Lead', '[email protected]', 'zillow', 'Is it open?', 1)"); | |
| 66 | db.exec("INSERT INTO message (lead_id, day, channel, body, signature, status, due_at) VALUES (7, 0, 'email', 'Hello', 'J', 'draft', '2026-01-01T00:00:00Z')"); | |
| 67 | expect(() => db.exec("INSERT INTO lead (name, email, source, message, consent) VALUES ('X', '[email protected]', 'realtor_com', 'hi', 1)")).toThrow(); | |
| 68 | ||
| 69 | migrate(db); | |
| 70 | ||
| 71 | expect(db.query("SELECT id, name, source FROM lead").all()).toEqual([{ id: 7, name: "Old Lead", source: "zillow" }]); | |
| 72 | expect(db.query("SELECT count(*) AS n FROM message WHERE lead_id = 7").get()).toEqual({ n: 1 }); | |
| 73 | db.exec("INSERT INTO lead (name, email, source, message, consent) VALUES ('New', '[email protected]', 'realtor_com', 'hi', 1)"); | |
| 74 | expect(() => db.exec("INSERT INTO lead (name, email, source, message, consent) VALUES ('Y', '[email protected]', 'trulia', 'hi', 1)")).toThrow(); | |
| 75 | expect(check(db).integrity).toBe("ok"); | |
| 76 | }); |
src/db.ts +27
| @@ -227,6 +227,33 @@ export const migrations: string[] = [ | ||
| 227 | 227 | // A follow-up the agent skipped by hand, so `reopen` leaves it skipped. |
| 228 | 228 | // Existing skipped rows were skipped by a close or a call: 0. |
| 229 | 229 | `ALTER TABLE message ADD COLUMN skipped_by_hand INTEGER NOT NULL DEFAULT 0 CHECK (skipped_by_hand IN (0, 1))`, |
| 230 | // Realtor.com is a source of its own. SQLite cannot widen a CHECK in place: | |
| 231 | // the lead table is rebuilt with its rows (ids kept; `migrate` has foreign | |
| 232 | // keys off, so nothing cascades). Safe to run again. | |
| 233 | `DROP TABLE IF EXISTS lead_new`, | |
| 234 | `CREATE TABLE lead_new ( | |
| 235 | id INTEGER PRIMARY KEY, | |
| 236 | name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 120), | |
| 237 | email TEXT NOT NULL CHECK (length(email) <= 254), | |
| 238 | phone TEXT NOT NULL DEFAULT '', | |
| 239 | source TEXT NOT NULL CHECK (source IN ('zillow', 'realtor_com', 'website', 'open_house', 'referral')), | |
| 240 | message TEXT NOT NULL CHECK (length(message) BETWEEN 1 AND 2000), | |
| 241 | consent INTEGER NOT NULL CHECK (consent IN (0, 1)), | |
| 242 | state TEXT NOT NULL DEFAULT 'new' CHECK (state IN ('new', 'contacted', 'qualified', 'lost')), | |
| 243 | created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')), | |
| 244 | replied_at TEXT, | |
| 245 | updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')), | |
| 246 | opted_out_at TEXT, | |
| 247 | note TEXT NOT NULL DEFAULT '', | |
| 248 | note_updated_at TEXT | |
| 249 | )`, | |
| 250 | `INSERT INTO lead_new (id, name, email, phone, source, message, consent, state, created_at, replied_at, updated_at, opted_out_at, note, note_updated_at) | |
| 251 | SELECT id, name, email, phone, source, message, consent, state, created_at, replied_at, updated_at, opted_out_at, note, note_updated_at FROM lead`, | |
| 252 | `DROP TABLE lead`, | |
| 253 | `PRAGMA legacy_alter_table = ON; | |
| 254 | ALTER TABLE lead_new RENAME TO lead; | |
| 255 | PRAGMA legacy_alter_table = OFF`, | |
| 256 | `CREATE INDEX IF NOT EXISTS lead_created ON lead (created_at)`, | |
| 230 | 257 | ]; |
| 231 | 258 | |
| 232 | 259 | /** An `ALTER TABLE … ADD COLUMN` whose column the table already has: nothing to do. */ |
src/drafts.ts +4 −1
| @@ -10,16 +10,18 @@ | ||
| 10 | 10 | import type { Agent } from "./env.ts"; |
| 11 | 11 | |
| 12 | 12 | export type Channel = "text" | "email"; |
| 13 | export type Source = "zillow" | "website" | "open_house" | "referral"; | |
| 13 | export type Source = "zillow" | "realtor_com" | "website" | "open_house" | "referral"; | |
| 14 | 14 | |
| 15 | 15 | export const SOURCES: readonly Source[] = [ |
| 16 | 16 | "zillow", |
| 17 | "realtor_com", | |
| 17 | 18 | "website", |
| 18 | 19 | "open_house", |
| 19 | 20 | "referral", |
| 20 | 21 | ]; |
| 21 | 22 | export const SOURCE_LABEL: Readonly<Record<Source, string>> = { |
| 22 | 23 | zillow: "Zillow", |
| 24 | realtor_com: "Realtor.com", | |
| 23 | 25 | website: "Website form", |
| 24 | 26 | open_house: "Open house", |
| 25 | 27 | referral: "Referral", |
| @@ -92,6 +94,7 @@ export const firstName = (name: string): string => | ||
| 92 | 94 | /** The opening line of a first reply for each source, until the agent words it themselves. */ |
| 93 | 95 | export const BUILT_IN_OPENER: Readonly<Record<Source, string>> = { |
| 94 | 96 | zillow: "Thanks for reaching out on Zillow", |
| 97 | realtor_com: "Thanks for reaching out on Realtor.com", | |
| 95 | 98 | website: "Thanks for your note through my website", |
| 96 | 99 | open_house: "It was great to have you at the open house", |
| 97 | 100 | referral: "Thank you for reaching out — referrals mean the world to me", |
src/intake.test.ts +1 −1
| @@ -17,7 +17,7 @@ test("a Realtor.com notification reads its wording and a question over two lines | ||
| 17 | 17 | name: "Tomas Okafor", |
| 18 | 18 | email: "[email protected]", |
| 19 | 19 | phone: "425-555-0178", |
| 20 | source: "website", | |
| 20 | source: "realtor_com", | |
| 21 | 21 | message: "We are relocating in June.\nDoes the house on Sample Ave allow dogs?", |
| 22 | 22 | }); |
| 23 | 23 | }); |
src/intake.ts +9 −4
| @@ -85,12 +85,17 @@ const sourceOf = (lines: readonly string[], named: string | undefined): Source | | ||
| 85 | 85 | .filter((l, i) => i < 8 || /^(from|sender|reply-to|subject|via)\s*:/i.test(l)) |
| 86 | 86 | .join("\n") |
| 87 | 87 | .toLowerCase(); |
| 88 | const said = named?.toLowerCase().replace(/[\s-]+/g, "_").replace(/_form$/, ""); | |
| 89 | if (said === "zillow" || said === "open_house" || said === "referral" || said === "website") | |
| 88 | const said = named?.toLowerCase().replace(/[\s.-]+/g, "_").replace(/_form$/, ""); | |
| 89 | if ( | |
| 90 | said === "zillow" || | |
| 91 | said === "realtor_com" || | |
| 92 | said === "open_house" || | |
| 93 | said === "referral" || | |
| 94 | said === "website" | |
| 95 | ) | |
| 90 | 96 | return said; |
| 91 | 97 | if (head.includes("zillow")) return "zillow"; |
| 92 | // The desk has no Realtor.com source: it is a website the lead came in through. | |
| 93 | if (head.includes("realtor.com")) return "website"; | |
| 98 | if (head.includes("realtor.com")) return "realtor_com"; | |
| 94 | 99 | if (/website|web form|contact form|form submission|new inquiry from your/.test(head)) |
| 95 | 100 | return "website"; |
| 96 | 101 | return undefined; |
src/mcp.ts +1 −1
| @@ -313,7 +313,7 @@ export const tools: readonly Tool[] = [ | ||
| 313 | 313 | openers: { |
| 314 | 314 | type: "object", |
| 315 | 315 | description: |
| 316 | "How a first reply opens, by source (zillow, website, open_house, referral): one line of at most 160 characters. A source left out keeps its wording; an empty one goes back to the built-in line. Drafts already on the desk are not rewritten.", | |
| 316 | "How a first reply opens, by source (zillow, realtor_com, website, open_house, referral): one line of at most 160 characters. A source left out keeps its wording; an empty one goes back to the built-in line. Drafts already on the desk are not rewritten.", | |
| 317 | 317 | properties: Object.fromEntries( |
| 318 | 318 | SOURCES.map((s) => [s, { type: "string", maxLength: OPENER_MAX }]), |
| 319 | 319 | ), |
src/pages/desk.ts +1
| @@ -213,6 +213,7 @@ const addForm = (prefill?: Partial<NewLead>): string => `<details class="card ad | ||
| 213 | 213 | const SOURCE_OPTIONS = [ |
| 214 | 214 | ["website", "Website form"], |
| 215 | 215 | ["zillow", "Zillow"], |
| 216 | ["realtor_com", "Realtor.com"], | |
| 216 | 217 | ["open_house", "Open house"], |
| 217 | 218 | ["referral", "Referral"], |
| 218 | 219 | ] as const; |
src/realtor.test.ts added +84
| @@ -0,0 +1,84 @@ | ||
| 1 | /** Realtor.com as a source of its own: every place a source is named or counted. */ | |
| 2 | import { 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 { addLead, listLeads, readNewLead, saveProfile, sourceOf, type Result } from "./actions.ts"; | |
| 7 | import { openDb } from "./db.ts"; | |
| 8 | import { BUILT_IN_OPENER, draft, SOURCE_LABEL } from "./drafts.ts"; | |
| 9 | import { agent } from "./env.ts"; | |
| 10 | import { leadsCsv } from "./export.ts"; | |
| 11 | import { readLeadEmail } from "./intake.ts"; | |
| 12 | import { insertLead, responseRecord } from "./leads.ts"; | |
| 13 | import { deskPage } from "./pages/desk.ts"; | |
| 14 | import { INQUIRIES } from "./sample.ts"; | |
| 15 | import type { Who } from "./who.ts"; | |
| 16 | ||
| 17 | const fresh = () => openDb(mkdtempSync(join(tmpdir(), "app-realtor-"))); | |
| 18 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 19 | const root: Who = { role: "admin", id: "u0", name: "root" }; | |
| 20 | const must = <T>(r: Result<T>): T => { | |
| 21 | if (!r.ok) throw new Error(`${r.error}: ${r.message}`); | |
| 22 | return r.value; | |
| 23 | }; | |
| 24 | const input = (source: string) => ({ | |
| 25 | name: "Dana Whitfield", | |
| 26 | email: "[email protected]", | |
| 27 | phone: "", | |
| 28 | source, | |
| 29 | message: "Is 21 Mercer St still available?", | |
| 30 | consent: false, | |
| 31 | }); | |
| 32 | ||
| 33 | test("a Realtor.com lead has its own row in the response record and its own value in the CSV", () => { | |
| 34 | const db = fresh(); | |
| 35 | const now = Date.now(); | |
| 36 | insertLead(db, { ...input("realtor_com"), source: "realtor_com" }, new Date(now - 60_000).toISOString(), agent); | |
| 37 | insertLead(db, { ...input("website"), source: "website", email: "[email protected]" }, new Date(now - 60_000).toISOString(), agent); | |
| 38 | const record = responseRecord(db, now); | |
| 39 | expect(record.by_source.map((r) => r.source).sort()).toEqual(["realtor_com", "website"]); | |
| 40 | expect(record.by_source.find((r) => r.source === "realtor_com")!.count).toBe(1); | |
| 41 | const listed = must(listLeads(db, alice)); | |
| 42 | const rows = leadsCsv(listed.leads, new Map()).split("\n"); | |
| 43 | expect(rows.filter((r) => r.includes(",realtor_com,")).length).toBe(1); | |
| 44 | expect(deskPage({ who: alice, agent, leads: listed.leads, record: listed.record, mayAdd: true, mayReset: false })).toContain("Realtor.com · 1 lead"); | |
| 45 | }); | |
| 46 | ||
| 47 | test("a Realtor.com first reply opens in its own words, or the agent's", () => { | |
| 48 | const lead = { ...input("realtor_com"), source: "realtor_com" as const }; | |
| 49 | expect(draft(lead, 0, agent)).toContain("Thanks for reaching out on Realtor.com"); | |
| 50 | expect(draft(lead, 0, { ...agent, openers: { ...BUILT_IN_OPENER, realtor_com: "Glad Realtor.com brought you to me" } })).toContain("Glad Realtor.com brought you to me"); | |
| 51 | const db = fresh(); | |
| 52 | must(saveProfile(db, root, { name: "Sam Realtor", brokerage: "Sam & Co", license: "WA 99887", phone: "(555) 010-0000", email: "[email protected]", openers: { realtor_com: "Hello from my Realtor.com page" } })); | |
| 53 | const added = must(addLead(db, alice, input("realtor_com"))); | |
| 54 | expect(added.messages[0]!.body).toContain("Hello from my Realtor.com page"); | |
| 55 | }); | |
| 56 | ||
| 57 | test("the boundary takes Realtor.com however it is written, names it in the refusal, and refuses others", () => { | |
| 58 | for (const said of ["realtor_com", "Realtor.com", "realtor.com", "Realtor-com"]) { | |
| 59 | expect(sourceOf(said)).toBe("realtor_com"); | |
| 60 | expect(must(readNewLead(input(said))).source).toBe("realtor_com"); | |
| 61 | } | |
| 62 | expect(sourceOf("trulia")).toBeUndefined(); | |
| 63 | const refused = readNewLead(input("trulia")); | |
| 64 | expect(refused.ok).toBe(false); | |
| 65 | if (!refused.ok) expect(refused.message).toContain("realtor_com"); | |
| 66 | expect(SOURCE_LABEL.realtor_com).toBe("Realtor.com"); | |
| 67 | }); | |
| 68 | ||
| 69 | test("the log-a-lead form offers Realtor.com", () => { | |
| 70 | const listed = must(listLeads(fresh(), alice)); | |
| 71 | const page = deskPage({ who: alice, agent, leads: listed.leads, record: listed.record, mayAdd: true, mayReset: false }); | |
| 72 | expect(page).toContain('value="realtor_com"'); | |
| 73 | }); | |
| 74 | ||
| 75 | test("the sample inquiries include a Realtor.com one", () => { | |
| 76 | expect(INQUIRIES.some((i) => i.source === "realtor_com")).toBe(true); | |
| 77 | }); | |
| 78 | ||
| 79 | test("a source named in the email as Realtor.com is read, whatever the email's wording", () => { | |
| 80 | for (const said of ["Realtor.com", "realtor_com"]) { | |
| 81 | const read = readLeadEmail(`Name: Pat Doe\nEmail: [email protected]\nSource: ${said}\nMessage: Is it open?`); | |
| 82 | expect(read.source).toBe("realtor_com"); | |
| 83 | } | |
| 84 | }); |
src/sample.ts +2 −1
| @@ -69,7 +69,7 @@ export const SAMPLES: readonly Sample[] = [ | ||
| 69 | 69 | person("Lena Novak", "open_house", false, "Signed in at the open house on Birch St. Could you send me the disclosures and HOA details?", { ago: 26 * H }), |
| 70 | 70 | person("Marcus Lee", "zillow", true, "Can I tour 92 Harbor View Dr this week? Available most evenings after 6.", { ago: 2 * D + 3 * H, answeredIn: 48 * S, touched: [1], note: "Works nights: call after 6. Cash buyer, relocating from Austin; wants a short closing." }), |
| 71 | 71 | person("Rosa Alvarez", "referral", false, "My cousin Elena recommended you. We need a bigger place before the baby comes in March.", { ago: 4 * D + 2 * H, answeredIn: 3 * M + 20 * S, touched: [1] }), |
| 72 | person("Ethan Brooks", "website", true, "What would my 2-bed condo on Seaview Ave sell for? Considering upsizing next year.", { ago: 8 * D + 5 * H, answeredIn: 2 * M + 5 * S, touched: [1, 3] }), | |
| 72 | person("Ethan Brooks", "realtor_com", true, "What would my 2-bed condo on Seaview Ave sell for? Considering upsizing next year.", { ago: 8 * D + 5 * H, answeredIn: 2 * M + 5 * S, touched: [1, 3] }), | |
| 73 | 73 | person("Grace Kim", "zillow", false, "Is the price on 7 Larkspur Ct negotiable? We're pre-approved and ready to move.", { ago: 15 * D, answeredIn: 1 * M + 30 * S, touched: [1, 3, 7], closed: "qualified" }), |
| 74 | 74 | person("Hannah Wright", "open_house", false, "Thanks for the tour of the Maple Ave home. Still deciding whether we want to stay in the city.", { ago: 31 * D, answeredIn: 4 * M + 15 * S, touched: [1, 3, 7, 14] }), |
| 75 | 75 | ]; |
| @@ -139,6 +139,7 @@ const inquiry = ( | ||
| 139 | 139 | |
| 140 | 140 | export const INQUIRIES: readonly NewLead[] = [ |
| 141 | 141 | inquiry("Nadia Farouk", "(206) 555-0201", "zillow", true, "Is 55 Cedar Way still on the market? We could see it tomorrow evening."), |
| 142 | inquiry("Hugo Lindqvist", "(206) 555-0208", "realtor_com", true, "Found 9 Ridge Rd on Realtor.com. Is the seller open to offers before the weekend?"), | |
| 142 | 143 | inquiry("Oliver Grant", "(206) 555-0202", "website", false, "Thinking of selling our duplex on Pine St this summer. Could you tell us what it might fetch?"), |
| 143 | 144 | inquiry("Sofia Marin", "(206) 555-0203", "open_house", true, "We toured the Willow Ct open house today and loved it. What would an offer need to look like?"), |
| 144 | 145 | inquiry("Kenji Watanabe", "(206) 555-0204", "referral", false, "Our neighbour Priya recommended you. We're relocating for work in September and need a 4-bedroom."), |
src/terminal.test.ts +5 −4
| @@ -101,7 +101,7 @@ test("n logs a lead by hand, field by field, and opens it with its reply drafted | ||
| 101 | 101 | const db = fresh(); |
| 102 | 102 | const t = terminal(db, alice); |
| 103 | 103 | t.key("n"); |
| 104 | for (const field of ["Zoe Park", "[email protected]", "", "3", "Saw the yard sign on Elm. Can we tour?", "n"]) { | |
| 104 | for (const field of ["Zoe Park", "[email protected]", "", "4", "Saw the yard sign on Elm. Can we tour?", "n"]) { | |
| 105 | 105 | type(t, field); |
| 106 | 106 | t.key("\r"); |
| 107 | 107 | } |
| @@ -246,7 +246,7 @@ test("an admin edits the profile one field at a time; it is saved, audited and r | ||
| 246 | 246 | next(agent.phone, "(555) 010-0000"); |
| 247 | 247 | next(agent.email, "[email protected]"); |
| 248 | 248 | next(agent.timeZone, "America/Chicago"); |
| 249 | for (let i = 0; i < 4; i++) t.key("\r"); // the openers stay built-in | |
| 249 | for (let i = 0; i < 5; i++) t.key("\r"); // the openers stay built-in | |
| 250 | 250 | expect(read(t)).toContain("Saved."); |
| 251 | 251 | expect(db.query<{ time_zone: string }, []>("SELECT time_zone FROM profile").get()?.time_zone).toBe("America/Chicago"); |
| 252 | 252 | expect(read(t)).toContain("WA 99887"); |
| @@ -274,10 +274,11 @@ test("the profile shows each source's opening; an admin words them in the termin | ||
| 274 | 274 | expect(read(t)).toContain("Opening for Zillow"); |
| 275 | 275 | const current = (db.query("SELECT openers FROM profile").get() as { openers: string } | null)?.openers; |
| 276 | 276 | expect(current).toBeUndefined(); |
| 277 | for (let i = 0; i < 3; i++) t.key("\r"); // Zillow, website and the next stay | |
| 277 | for (let i = 0; i < 3; i++) t.key("\r"); // Zillow, Realtor.com and website stay | |
| 278 | 278 | clear(t, "x".repeat(300)); |
| 279 | 279 | type(t, "Hi from the open house!"); |
| 280 | 280 | t.key("\r"); |
| 281 | t.key("\r"); // Referral stays; the last one saves | |
| 281 | 282 | expect(read(t)).toContain("Saved."); |
| 282 | 283 | expect(read(t)).toContain("Hi from the open house!"); |
| 283 | 284 | const saved = db.query<{ openers: string }, []>("SELECT openers FROM profile").get(); |
| @@ -293,7 +294,7 @@ test("a blank license typed in the terminal is refused and nothing is saved", () | ||
| 293 | 294 | for (const current of [agent.name, agent.brokerage]) t.key("\r"), void current; |
| 294 | 295 | clear(t, agent.license); |
| 295 | 296 | t.key("\r"); |
| 296 | for (let i = 0; i < 7; i++) t.key("\r"); | |
| 297 | for (let i = 0; i < 8; i++) t.key("\r"); | |
| 297 | 298 | expect(read(t)).toContain("license number is required"); |
| 298 | 299 | expect(db.query("SELECT * FROM profile").all()).toHaveLength(0); |
| 299 | 300 | }); |
new above
offline