Files
supermarket/internal/next/next_test.go
T
davidandClaude Opus 5.5 5705a9b58b Phase 7 part 4: SEO → What to write next
One list per website of everything worth writing: new wording for pages
(Push pages and the audit's title and description issues), landing
pages for signals that get replies, pages for apps people name in their
replies (their own words, without quoted mail or signatures), and
keywords or briefs that stalled. Ranked by the sign-ups each is expected
to bring, at most 10 shown, each with its reason in numbers and the
button that starts its flow; Not now hides one for 90 days. The SEO
module still opens on the Morning check; the Monday report links here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 07:17:42 -07:00

91 lines
3.2 KiB
Go

package next
import (
"path/filepath"
"strings"
"testing"
"time"
"supermarket/internal/db"
"supermarket/internal/profile"
"supermarket/internal/prospects"
"supermarket/internal/signals"
)
var now = time.Date(2026, 11, 24, 9, 0, 0, 0, time.UTC)
func openDB(t *testing.T) *db.DB {
t.Helper()
d, err := db.Open(filepath.Join(t.TempDir(), "app.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { d.Close() })
return d
}
func TestSignalsWithoutPages(t *testing.T) {
d := openDB(t)
edu := &signals.Signal{Name: "Education", Status: "testing"}
quiet := &signals.Signal{Name: "Quiet", Status: "testing"}
signals.Save(d, edu)
signals.Save(d, quiet)
for i, stage := range []string{signals.StageReplied, signals.StageReplied, signals.StageInterested} {
if _, err := signals.Record(d, signals.Event{SignalID: edu.ID, Stage: stage, Channel: "explee", Source: "explee",
Subject: "explee:" + string(rune('a'+i)), ExternalID: stage + string(rune('a'+i)), At: now.AddDate(0, 0, -3)}); err != nil {
t.Fatal(err)
}
}
got, err := SignalsWithoutPages(d, now)
if err != nil {
t.Fatal(err)
}
if len(got) != 1 || got[0].Title != "Education" || !strings.Contains(got[0].Why, "2 replies and 1 interested person") ||
!strings.Contains(got[0].Action.URL, "kind=landing&signal=") {
t.Errorf("got %+v", got)
}
}
func TestAppsInReplies(t *testing.T) {
d := openDB(t)
for i, text := range []string{
"origami.chat campaign “CRM buyers on Salesforce”: We moved our help desk to FreeScout last year and love it.",
"origami.chat campaign “Ministries”: Do you host Planning Center? We also use freescout.",
"explee.com campaign “Startups”: Runs Slack and Planning Center for 40 staff.",
"explee.com campaign “Startups”: nothing useful here",
} {
if _, _, err := prospects.AddContact(d, prospects.Contact{FirstName: "P", LastName: string(rune('a' + i)), Email: string(rune('a'+i)) + "@x.example",
Source: prospects.SourceManual, SourceDetail: text}, now); err != nil {
t.Fatal(err)
}
}
p := &profile.Profile{}
p.Targets.Technologies = []string{"Planning Center", "Slack"}
// The site has a FreeScout page; Salesforce is only in a campaign's name.
ms, err := AppsInReplies(d, p, []string{"/freescout/", "/pricing/"}, []string{"Pricing"})
if err != nil {
t.Fatal(err)
}
if len(ms) != 1 || ms[0].Name != "Planning Center" || ms[0].People != 2 {
t.Fatalf("mentions: %+v", ms)
}
s := MentionSuggestions(ms, p)
if s[0].Kind != "Alternative page" || !strings.Contains(s[0].Why, "2 people named it") {
t.Errorf("suggestion: %+v", s[0])
}
if !hasPage("FreeScout", nil, []string{"FreeScout — help desk you own"}) || hasPage("Plane", []string{"/planning-center/"}, nil) {
t.Error("hasPage")
}
}
func TestOwnWords(t *testing.T) {
in := "Hej, vi använder Planning Center. Mvh Roland Skickat från Outlook för Android Från: Janae <j@x> Skickat: tisdag We host Nextcloud for you"
got := ownWords(in)
if strings.Contains(got, "Outlook") || strings.Contains(got, "Nextcloud") || !strings.Contains(got, "Planning Center") {
t.Errorf("own words: %q", got)
}
if got := ownWords("Sounds good.\n\nOn Mon, 3 Nov 2026 at 10:00, David <d@x> wrote:\n> We run FreeScout"); strings.Contains(got, "FreeScout") {
t.Errorf("quoted: %q", got)
}
}