Phase 2 part 2: prospects, the review screen and the suppression list
Schema 6 adds prospect_companies, prospect_contacts (merged by domain and email, each with its source, detail and date) and suppressions. Prospects -> Review lists New, Accepted and Set aside: accepting a company queues an EspoCRM Account, a person a Lead at their company, with provenance and why they fit in the description; the page warns about records already in the CRM as of the last sync, and shows each accepted prospect's CRM progress. Prospects can be added by hand. The suppression list (emails and domains) is checked on add and again before queueing, and suppressing sets matching new prospects aside. Search finds prospects too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"supermarket/internal/mcpserver"
|
||||
"supermarket/internal/models"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/prospects"
|
||||
"supermarket/internal/secrets"
|
||||
)
|
||||
|
||||
@@ -97,7 +98,8 @@ func TestEveryPageRenders(t *testing.T) {
|
||||
"/inventory/new", "/inventory/1", "/inventory/import", "/inventory/export",
|
||||
"/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/favicon.ico", "/static/favicon.png", "/static/logo.png", "/static/apple-touch-icon.png", "/search", "/crm", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz",
|
||||
"/content", "/content/1", "/content/1?dismissed=1", "/posts", "/posts?msg=drafted",
|
||||
"/content/scheduled", "/content/published"} {
|
||||
"/content/scheduled", "/content/published",
|
||||
"/prospects", "/prospects?status=accepted", "/prospects?status=rejected", "/prospects/new", "/prospects/suppressed"} {
|
||||
rec := do(h, http.MethodGet, path, nil, nil)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Errorf("core=%v GET %s: %d %s", c != nil, path, rec.Code, rec.Body.String())
|
||||
@@ -538,3 +540,62 @@ func TestCRMReachHint(t *testing.T) {
|
||||
t.Errorf("unreachable: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
// Prospects: add by hand, see the CRM warning, accept into the CRM queue,
|
||||
// and the suppression list stops what's on it.
|
||||
func TestProspectsReview(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
rec, _ := crm.RecordFrom("Account", map[string]any{"id": "a1", "name": "Acme", "website": "https://acme.com"}, time.Now())
|
||||
crm.Ingest(s.DB, []crm.Record{rec})
|
||||
|
||||
if rec := postForm(h, "/prospects/new", url.Values{}); !strings.Contains(rec.Body.String(), "Give a company, a person, or both") {
|
||||
t.Error("an empty form was accepted")
|
||||
}
|
||||
form := url.Values{"company_name": {"Acme"}, "website": {"acme.com"}, "why": {"Runs its own servers"},
|
||||
"first_name": {"Pat"}, "last_name": {"Lee"}, "title": {"CTO"}, "email": {"pat@acme.com"}, "source_detail": {"Met at FOSDEM"}}
|
||||
if rec := postForm(h, "/prospects/new", form); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("add: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
body := do(h, http.MethodGet, "/prospects", nil, nil).Body.String()
|
||||
for _, want := range []string{"Acme", "Pat Lee", "Runs its own servers", "Met at FOSDEM", "Already in your CRM", "Accept with 1 person",
|
||||
`<span class="count-badge" title="2 waiting for review">2</span>`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("review page lacks %q in %s", want, body)
|
||||
}
|
||||
}
|
||||
if rec := postForm(h, "/prospects/company/1/accept-all", url.Values{"tab": {"new"}}); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("accept all: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
as, _ := crm.List(s.DB, 10)
|
||||
if len(as) != 2 {
|
||||
t.Fatalf("queued: %+v", as)
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/prospects?status=accepted", nil, nil).Body.String(); !strings.Contains(body, "waiting for Hermes") {
|
||||
t.Error("accepted tab doesn't show the CRM state")
|
||||
}
|
||||
|
||||
// Suppression.
|
||||
postForm(h, "/prospects/new", url.Values{"first_name": {"Ray"}, "last_name": {"Doe"}, "email": {"ray@other.org"}})
|
||||
if rec := postForm(h, "/prospects/suppressed", url.Values{"value": {"other.org"}, "reason": {"partner"}}); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("suppress: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/prospects?status=rejected", nil, nil).Body.String(); !strings.Contains(body, "Ray Doe") {
|
||||
t.Error("a suppressed prospect should be set aside")
|
||||
}
|
||||
if rec := postForm(h, "/prospects/new", url.Values{"last_name": {"Kim"}, "email": {"kim@other.org"}}); !strings.Contains(rec.Body.String(), "suppression list (kim@other.org)") {
|
||||
t.Errorf("adding a suppressed person: %s", rec.Body.String())
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/prospects/suppressed", nil, nil).Body.String(); !strings.Contains(body, "other.org") || !strings.Contains(body, "partner") {
|
||||
t.Error("suppression list page")
|
||||
}
|
||||
postForm(h, "/prospects/suppressed", url.Values{"kind": {"domain"}, "value": {"other.org"}, "remove": {"1"}})
|
||||
if list, _ := prospects.Suppressions(s.DB); len(list) != 0 {
|
||||
t.Errorf("remove: %+v", list)
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/search?q=pat+cto", nil, nil).Body.String(); !strings.Contains(body, "Pat Lee") || !strings.Contains(body, "/prospects?status=accepted") {
|
||||
t.Error("search doesn't find the prospect")
|
||||
}
|
||||
if rec := postForm(h, "/prospects/contact/99/accept", url.Values{}); rec.Code != http.StatusNotFound {
|
||||
t.Errorf("missing prospect: %d", rec.Code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user