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{ LadderKey: "mapfirst-" + uuid.New().String()[:8], Name: "Map First Ladder", 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") } }