Sites → Sections and pages → Add a section, on any page built from sections: choose one of the site's section types and where it goes; the AI writes it from the page, its searches, the profile and the Inventory, with the same rules as a new page. It's reviewed like a page (claims to confirm, to-dos), and the pull request inserts it into the page's file as text, so only that section is added; the build checks it. What to write next suggests a FAQ for a section page found with questions, and a comparison for one searched against something else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
4.5 KiB
Go
120 lines
4.5 KiB
Go
package next
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"supermarket/internal/db"
|
|
"supermarket/internal/profile"
|
|
"supermarket/internal/prospects"
|
|
"supermarket/internal/seo"
|
|
"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)
|
|
}
|
|
}
|
|
|
|
func TestSectionIdeas(t *testing.T) {
|
|
pages := []SectionPage{
|
|
{Path: "/freescout/", Title: "FreeScout", Types: []string{"hero", "text"}},
|
|
{Path: "/pricing/", Title: "Pricing", Types: []string{"hero", "faq"}},
|
|
}
|
|
searches := map[string][]seo.QueryRow{
|
|
"/freescout/": {
|
|
{Query: "how to install freescout", Numbers: seo.Numbers{Impressions: 40}},
|
|
{Query: "is freescout free?", Numbers: seo.Numbers{Impressions: 30}},
|
|
{Query: "freescout vs help scout", Numbers: seo.Numbers{Impressions: 20}},
|
|
{Query: "zendesk pricing per agent", Numbers: seo.Numbers{Impressions: 40}},
|
|
{Query: "freescout", Numbers: seo.Numbers{Impressions: 3000}},
|
|
},
|
|
"/pricing/": {{Query: "how much does it cost", Numbers: seo.Numbers{Impressions: 500}}},
|
|
}
|
|
got := SectionIdeas(pages, searches, []string{"hero", "text", "faq", "table"}, []string{"Zendesk"}, 0, 0)
|
|
if len(got) != 2 {
|
|
t.Fatalf("got %+v", got)
|
|
}
|
|
f, c := got[0], got[1]
|
|
if f.Kind != "Add a FAQ" || !strings.Contains(f.Why, "70 times") || !strings.Contains(f.Action.URL, "type=faq") || !strings.Contains(f.Action.URL, "page=%2Ffreescout%2F") {
|
|
t.Errorf("faq: %+v", f)
|
|
}
|
|
if c.Kind != "Add a comparison" || !strings.Contains(c.Why, "60 times") || !strings.Contains(c.Action.URL, "type=table") {
|
|
t.Errorf("comparison: %+v", c)
|
|
}
|
|
}
|