package server import ( "bytes" "html/template" "io/fs" "strings" "testing" "git.coopcloud.tech/wiki-cafe/member-console/internal/embeds" "git.coopcloud.tech/wiki-cafe/member-console/internal/web" ) // renderGrantsIndex executes the real operator_grants.html template with the // given data, mirroring renderOrgEnrollment (operator_enrollment_render_test.go) // so the grants index and the org-detail composite are both exercised // against their real templates rather than a stub. func renderGrantsIndex(t *testing.T, data GrantsData) string { t.Helper() partialsSub, err := fs.Sub(embeds.Templates, "templates/partials") if err != nil { t.Fatalf("fs.Sub partials: %v", err) } tmpl := template.New("operator").Funcs(template.FuncMap{ "renderBody": func(string, any) (template.HTML, error) { return "", nil }, "routeURL": web.RouteURL, "stripeEntityURL": func(string, string) string { return "" }, "fieldErr": func(activeForm, expectedForm, activeScope, expectedScope string, errs web.FieldErrors, field string) string { return "" }, }) tmpl, err = tmpl.ParseFS(partialsSub, "operator_*.html") if err != nil { t.Fatalf("ParseFS: %v", err) } var buf bytes.Buffer if err := tmpl.ExecuteTemplate(&buf, "operator_grants.html", data); err != nil { t.Fatalf("ExecuteTemplate: %v", err) } return buf.String() } // TestGrantsIndex_RendersDeliveryStateNotLedgerBadge covers // ux-honest-surfaces UX-3: /operator/grants must render the derived // delivery state (live/superseded/inactive), not the raw grants.status // ledger as a green "active" badge under a bare "Status" header, and must // carry the ledger-vs-delivery explanation and lineage. func TestGrantsIndex_RendersDeliveryStateNotLedgerBadge(t *testing.T) { data := GrantsData{ Grants: []GrantViewModel{ {GrantID: "g-old", OrgName: "Acme Co", ProductName: "Legacy Plan", GrantReason: "manual", Status: "active", CreatedAt: "Jan 1, 2026", DeliveryState: "superseded", ReplacedByGrantID: "g-new", ReplacedByLabel: "Standard Plan"}, {GrantID: "g-new", OrgName: "Acme Co", ProductName: "Standard Plan", GrantReason: "manual", Status: "active", CreatedAt: "Jan 2, 2026", DeliveryState: "live", ExtendsGrantID: "g-old", ExtendsLabel: "Legacy Plan"}, {GrantID: "g-gone", OrgName: "Beta Org", ProductName: "Trial", GrantReason: "evaluation", Status: "revoked", CreatedAt: "Jan 3, 2026", DeliveryState: "inactive"}, }, } out := renderGrantsIndex(t, data) if !strings.Contains(out, "