Introduce a commercial license option alongside AGPL-3.0-only, require a CLA for contributors, and document the terms in COMMERCIAL.md and NOTICE. Add a script to stamp SPDX headers on Go files and apply it across the tree.
64 lines
2.2 KiB
Go
64 lines
2.2 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
package server_test
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/forms"
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/server"
|
|
)
|
|
|
|
// TestOperatorPlanLadderEditOmitsSortOrder renders the actual ladder edit
|
|
// template against the actual view model and asserts the raw "Sort order" field
|
|
// is gone: ladder display order is now adjusted via the move-left/move-right
|
|
// controls on the topology overview, never as an absolute integer on this form.
|
|
// Rendering the real template also guards the template/view-model contract —
|
|
// html/template field-reference errors are runtime, so a stray .Ladder.SortOrder
|
|
// reference would 500 here rather than slip past build.
|
|
func TestOperatorPlanLadderEditOmitsSortOrder(t *testing.T) {
|
|
h, err := server.NewOperatorPartialsHandler(server.OperatorPartialsConfig{Logger: discardLogger()})
|
|
if err != nil {
|
|
t.Fatalf("new operator handler: %v", err)
|
|
}
|
|
|
|
ladder := server.PlanLadderViewModel{
|
|
PlanLadderID: "lad-1",
|
|
Name: "Hosting",
|
|
IsActive: true,
|
|
}
|
|
spec, ok := forms.Lookup("operator.plan-ladder")
|
|
if !ok {
|
|
t.Fatal("operator.plan-ladder form not registered")
|
|
}
|
|
values := forms.NewValues()
|
|
values.Set("name", ladder.Name)
|
|
values.Set("description", ladder.Description)
|
|
form := forms.Render(spec, forms.Binding{Mode: forms.ModeRecord, Side: forms.EditOnly, Values: values})
|
|
|
|
rec := httptest.NewRecorder()
|
|
h.Templates.Render(rec, "operator_plan_ladder_edit.html", server.PlanLadderEditData{
|
|
Ladder: ladder,
|
|
Form: form,
|
|
})
|
|
if rec.Code != 200 {
|
|
t.Fatalf("expected 200, got %d: %s", rec.Code, rec.Body.String())
|
|
}
|
|
body := rec.Body.String()
|
|
|
|
if strings.Contains(body, `name="sort_order"`) {
|
|
t.Error("edit form should no longer present a raw sort_order input")
|
|
}
|
|
// The form still binds the editable fields, and points operators at the
|
|
// topology overview for ordering.
|
|
if !strings.Contains(body, `name="name"`) {
|
|
t.Error("expected the display-name input to remain")
|
|
}
|
|
if !strings.Contains(body, "/operator/plan-ladders") {
|
|
t.Error("expected a pointer to the topology overview for reordering")
|
|
}
|
|
}
|