SEO: a domain property (sc-domain:) covers every subdomain, so the shop, Gitea and forum were counted as the website. What ranks, the morning check, the Monday report, keywords, change candidates and the audit's traffic now read only the website's own host (with or without www). The report keeps pages worth a proposal apart from "Waiting for your yes", explains only moves past the thresholds, and says "places up/down". Also: - Feed summaries drop the posts' scripts and styles. - Spend you log can't be negative. - Test and check buttons can't be clicked twice while they run. - Previews show the site's web fonts and icon sprites. - Backups are read without leaving -wal/-shm files; deleting one removes them, and leftovers are swept at start. - The Overview's setup flags a CRM that Hermes can't reach. - Import now says what came in; adding a prospect that exists says so; prospects can be deleted. - Signal tags and brief addresses keep accented letters (Ü → u). - Page errors start with a capital; clearer messages for bad uploads, CRM retry and cancel, keywords, and the finished audit. - The module you're in stays unfolded in the sidebar. - A picked keyword can be unpicked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
3.5 KiB
Go
77 lines
3.5 KiB
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"supermarket/internal/ai"
|
|
"supermarket/internal/profile"
|
|
"supermarket/internal/secrets"
|
|
"supermarket/internal/seo"
|
|
)
|
|
|
|
type briefWriter struct{}
|
|
|
|
func (briefWriter) Generate(context.Context, ai.Request) (string, error) {
|
|
return "## Prices\n\nWe tested it with 12 users. Plans are flat.", nil
|
|
}
|
|
|
|
func (briefWriter) Research(context.Context, ai.ResearchRequest) (*ai.ResearchResult, error) {
|
|
return &ai.ResearchResult{Searches: 3, Text: `{"finding":"Nobody shows prices.","top":[{"url":"https://a.example","title":"A","promises":"a list","lacks":"prices","read":true}],
|
|
"plan":{"title":"Flat-price workspace","description":"Plans.","h1":"Workspace","angle":"Prices","sections":["Prices","Moving"],
|
|
"questions":["How much?"],"links":[],"ask":["Have you moved a team?"],"needs":[]}}`}, nil
|
|
}
|
|
|
|
func TestBriefPages(t *testing.T) {
|
|
newAIClient = func(ai.Config, *secrets.Store) (ai.Client, error) { return briefWriter{}, nil }
|
|
defer func() { newAIClient = ai.New }()
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, `<urlset></urlset>`) }))
|
|
defer srv.Close()
|
|
s, h := newTestServer(t, nil)
|
|
profile.Save(s.DB, &profile.Profile{Name: "Us", Websites: []profile.Website{{URL: srv.URL}}})
|
|
|
|
if body := do(h, http.MethodGet, "/seo/briefs", nil, nil).Body.String(); !strings.Contains(body, "Write a brief") {
|
|
t.Fatal("no form")
|
|
}
|
|
rec := postForm(h, "/seo/briefs?site=0", url.Values{"keyword": {"workspace alternative"}})
|
|
if rec.Code != http.StatusSeeOther || !strings.HasPrefix(rec.Header().Get("Location"), "/seo/briefs/1") {
|
|
t.Fatalf("new: %d %s %s", rec.Code, rec.Header().Get("Location"), rec.Body)
|
|
}
|
|
body := do(h, http.MethodGet, "/seo/briefs/1", nil, nil).Body.String()
|
|
for _, want := range []string{"Nobody shows prices.", `value="Flat-price workspace"`, "Have you moved a team?", "/workspace-alternative/", "Write the page"} {
|
|
if !strings.Contains(body, want) {
|
|
t.Errorf("brief lacks %q", want)
|
|
}
|
|
}
|
|
form := url.Values{"title": {"Flat-price workspace"}, "description": {"Plans."}, "h1": {"Workspace"}, "angle": {"Prices"},
|
|
"sections": {"Prices\nMoving\nFAQ"}, "questions": {"How much?"}, "answer": {"Yes, 12 users."}, "path": {"/workspace/"}}
|
|
if rec := postForm(h, "/seo/briefs/1/write", form); rec.Code != http.StatusSeeOther {
|
|
t.Fatalf("write: %d %s", rec.Code, rec.Body)
|
|
}
|
|
b, _ := seo.GetBrief(s.DB, 1)
|
|
if len(b.Plan.Sections) != 3 || b.Path != "/workspace/" || b.Answers[0] != "Yes, 12 users." || b.Status != seo.BriefPage {
|
|
t.Errorf("saved: %+v", b)
|
|
}
|
|
body = do(h, http.MethodGet, "/seo/briefs/1", nil, nil).Body.String()
|
|
if !strings.Contains(body, "We tested it with 12 users.") || !strings.Contains(body, `name="claim" value="We tested it with 12 users."`) {
|
|
t.Error("the draft or its claim isn't shown")
|
|
}
|
|
if rec := postForm(h, "/seo/briefs/1/pr", url.Values{}); !strings.Contains(rec.Body.String(), "Save a Gitea token") {
|
|
t.Errorf("pr without Gitea: %d", rec.Code)
|
|
}
|
|
s.Secrets.Set(map[string]string{secrets.GiteaToken: "tok"})
|
|
s.DB.PutJSON(giteaURLKey, "https://gitea.example.com")
|
|
if rec := postForm(h, "/seo/briefs/1/pr", url.Values{"draft": {b.Draft}}); !strings.Contains(rec.Body.String(), "Tick each sentence") {
|
|
t.Errorf("pr with an unconfirmed claim: %d", rec.Code)
|
|
}
|
|
postForm(h, "/seo/briefs/1/drop", nil)
|
|
if body := do(h, http.MethodGet, "/seo/briefs", nil, nil).Body.String(); strings.Contains(body, "workspace alternative</a>") {
|
|
t.Error("a dropped brief is listed")
|
|
}
|
|
}
|