Phase 4 part 6: the dashboard, CSV exports and an open metrics page

The MRR page adds churn, CLV, CAC and CLV:CAC. Eight tables download as
CSV (MRR, NRR and revenue cohorts, CAC by month and channel, spend,
products, customers). Metrics → Publish builds an open metrics page from
chosen totals only (never a customer) and opens a pull request that adds
or updates it on the site, checked with a Hugo build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 13:28:50 -07:00
co-authored by Claude Opus 5.5
parent 23f765159f
commit 152c14b580
18 changed files with 637 additions and 5 deletions
+33
View File
@@ -160,3 +160,36 @@ func TestSpendPage(t *testing.T) {
t.Error("the entry wasn't deleted")
}
}
func TestExportAndPublishPages(t *testing.T) {
s, h := newTestServer(t, nil)
profile.Save(s.DB, &profile.Profile{Name: "Us", Websites: []profile.Website{{URL: "https://us.example"}}})
s.DB.Exec(`INSERT INTO stripe_objects (kind, id, currency, data) VALUES ('invoice', 'in_0', 'usd', '{}')`)
start := time.Date(time.Now().Year(), time.Now().Month(), 1, 0, 0, 0, 0, time.UTC).AddDate(0, -2, 0)
for i := 0; i < 3; i++ {
ps := start.AddDate(0, i, 0)
s.DB.Exec(`INSERT INTO stripe_invoice_lines (invoice, id, customer, status, currency, amount, period_start, period_end, interval, interval_count, recurring)
VALUES (?, ?, 'cus_a', 'paid', 'usd', 9900, ?, ?, 'month', 1, 1)`, fmt.Sprint("in_", i), fmt.Sprint("il_", i), ps.Unix(), ps.AddDate(0, 1, 0).Unix())
}
rec := do(h, http.MethodGet, "/metrics/export/mrr.csv", nil, nil)
if rec.Header().Get("Content-Type") != "text/csv; charset=utf-8" || !strings.Contains(rec.Header().Get("Content-Disposition"), "supermarket-mrr-") ||
!strings.HasPrefix(rec.Body.String(), "month,partial,mrr") {
t.Errorf("export: %v %s", rec.Header(), rec.Body)
}
if rec := do(h, http.MethodGet, "/metrics/export/secrets.csv", nil, nil); rec.Code != http.StatusNotFound {
t.Errorf("unknown export: %d", rec.Code)
}
if body := do(h, http.MethodGet, "/metrics", nil, nil).Body.String(); !strings.Contains(body, "/metrics/export/mrr.csv") {
t.Error("no download link on Metrics")
}
postForm(h, "/metrics/publish", url.Values{"site": {"0"}, "path": {"/numbers/"}, "title": {"Our numbers"}, "part": {"mrr", "table"}, "do": {"save"}})
body := do(h, http.MethodGet, "/metrics/publish", nil, nil).Body.String()
for _, want := range []string{`value="/numbers/"`, "Monthly recurring revenue:** $99", "| Month | MRR |"} {
if !strings.Contains(body, want) {
t.Errorf("publish page lacks %q", want)
}
}
if rec := postForm(h, "/metrics/publish", url.Values{"site": {"0"}, "path": {""}, "title": {"x"}}); !strings.Contains(rec.Body.String(), "an address and a title") {
t.Error("an empty address was accepted")
}
}