Files
member-console/internal/server/operator_plan_ladders_mapfirst_test.go
T
cgalo5758 dd3962990b Adopt entity keys and add invoice numbers
Replace the entity slugs on organizations, workspaces, resource pools,
and
plan ladders with nullable `key` columns and add keys to products,
prices,
and entitlement sets. Rename `providers.slug` to `provider` and add
partial
unique indexes for system and org role names.

Assign invoice numbers per billing account from a gapless transactional
counter; Stripe's number moves to the invoice mapping as an external
reference.

Seeds, fixtures, and the operator lookup address rows by key, and the
returning-login resync no longer blanks a display name when the IdP
sends
no `name` claim.
2026-08-29 20:12:04 -05:00

76 lines
2.1 KiB
Go

package server
// DB-backed handler-wiring test for ux-ia-naming 2.2: loadPlanLaddersPageData
// must hydrate PlanLaddersData.Topology by reusing loadPlanTopologyData, so
// GET /operator/plan-ladders loads both data sets from one page load. The
// render-only assembly (template include, heading order, health-strip
// states) is covered by operator_plan_ladders_mapfirst_render_test.go; this
// test locks the Go-side wiring that feeds it.
import (
"context"
"io"
"log/slog"
"net/http/httptest"
"testing"
"git.coopcloud.tech/wiki-cafe/member-console/internal/billing"
"git.coopcloud.tech/wiki-cafe/member-console/internal/entitlements"
"git.coopcloud.tech/wiki-cafe/member-console/internal/organization"
"github.com/google/uuid"
_ "github.com/jackc/pgx/v5/stdlib"
)
func TestLoadPlanLaddersPageDataIncludesTopology(t *testing.T) {
database := topoTestDB(t)
ctx := context.Background()
tx, err := database.BeginTx(ctx, nil)
if err != nil {
t.Fatal(err)
}
defer tx.Rollback()
bq := billing.New(tx)
eq := entitlements.New(tx)
oq := organization.New(tx)
ladder, err := bq.CreatePlanLadder(ctx, billing.CreatePlanLadderParams{
Name: "Map First Ladder " + uuid.New().String()[:8],
IsActive: true,
})
if err != nil {
t.Fatalf("create ladder: %v", err)
}
h := &OperatorPartialsHandler{
BillingQ: bq,
EntitlementsQ: eq,
OrgQ: oq,
Database: database,
Logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
}
req := httptest.NewRequest("GET", "/operator/plan-ladders", nil).WithContext(ctx)
data := h.loadPlanLaddersPageData(req, "", "")
foundInList := false
for _, l := range data.Ladders {
if l.PlanLadderID == ladder.PlanLadderID {
foundInList = true
}
}
if !foundInList {
t.Errorf("expected the created ladder in the management list (data.Ladders)")
}
foundInTopology := false
for _, l := range data.Topology.Ladders {
if l.PlanLadderID == ladder.PlanLadderID {
foundInTopology = true
}
}
if !foundInTopology {
t.Errorf("expected the created ladder in the topology overview (data.Topology.Ladders) -- loadPlanLaddersPageData must hydrate Topology via loadPlanTopologyData")
}
}