Files
member-console/internal/integrations/fedwiki/web/operator_render_test.go
T
cgalo5758 56a512ca2a Fix Stripe deduplication and FedWiki operator 500s
Stripe's webhook deduplication used ON CONFLICT on a partitioned table
where the unique key included received_at, which only collapsed
same-instant duplicates. Switch to WHERE NOT EXISTS to deduplicate
across time.

FedWiki's operator page failed to render because html/template's
escape analysis requires all referenced templates in the set, even on
untaken branches. Include partials/operator_lookup_result.html in the
parsed template set.

Move resolved issues to archive.
2026-07-20 20:02:34 -07:00

50 lines
1.6 KiB
Go

package web
import (
"log/slog"
"net/http/httptest"
"os"
"strings"
"testing"
"git.coopcloud.tech/wiki-cafe/member-console/internal/server"
)
// Scenario: the operator shell's landing branch references
// operator_lookup_result.html, and html/template's escape analysis demands
// every referenced template exist in the set even on branches this page
// never takes — a handler that parses only operator.html + its own body
// partial 500s on EVERY render ("no such template"). This regressed live
// on /operator/fedwiki-sites (discourse-integration findings #8); guard
// the template-set composition without needing a DB or auth session.
func TestOperatorSitesPageRenders(t *testing.T) {
h, err := NewFedWikiOperatorHandler(FedWikiOperatorHandlerConfig{
Logger: slog.Default(),
TemplatesFS: os.DirFS("../templates"),
})
if err != nil {
t.Fatalf("construct handler: %v", err)
}
page := server.OperatorPageData{
IAPosition: "integration:fedwiki-sites",
ActiveCapability: "fedwiki-sites",
BodyTemplate: "fedwiki_operator_sites.html",
BodyData: FedWikiSitesData{
Sites: []FedWikiSiteViewModel{{
ID: "site-1", Domain: "wiki.example.test", URL: "https://wiki.example.test",
OwnerOrgName: "Test Org", CreatedAt: "Jan 2, 2026", Status: "active",
}},
},
}
rec := httptest.NewRecorder()
h.Templates.Render(rec, "operator.html", page)
if rec.Code != 200 {
t.Fatalf("render = %d (template-set regression?), body: %s", rec.Code, rec.Body.String())
}
if !strings.Contains(rec.Body.String(), "wiki.example.test") {
t.Errorf("rendered page missing site row")
}
}