feat(18.1-01): task 3 flat reorder on the server
- config_reorder.yaml without parentColumn on a record with no parent_id column compiles as a flat (WinterCMS Sortable) reorder; maxDepth above 0 on it fails boot, an explicit parentColumn still means a tree - ListReorder.Flat and AdminReorderTree.Flat (flat, omitempty); flat nodes carry parent_id null, a save writes only the sort column, a parent is a 422 on nodes (reorder.flat_parent); 409 and duplicate rules unchanged - swag descriptions, OpenAPI and schema.d.ts regenerated - acme.catalog badges reorder fixture, TestReorderFlatCompile and TestReorderFlatSmoke; docs Flat reorder section and cabana README
This commit is contained in:
79
modules/cabana/reorder_flat_test.go
Normal file
79
modules/cabana/reorder_flat_test.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package cabana_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/cabana"
|
||||
"git.golem15.com/golem15/summercms/modules/party"
|
||||
)
|
||||
|
||||
// Smoke tests of the flat (WinterCMS Sortable) reorder (Phase 18.1 D-17),
|
||||
// Docker-free: the inference rule and the flat flag. The Postgres routes are
|
||||
// TestReorderFlatSmoke in catalog_smoke_test.go. Full unit coverage is plan
|
||||
// 06. No application names appear in framework tests.
|
||||
|
||||
// TestReorderFlatCompile pins the flat inference: a config_reorder.yaml
|
||||
// without parentColumn on a record without a parent_id column compiles as
|
||||
// flat and the list schema says so; maxDepth on it and an explicit
|
||||
// parentColumn that is not a column fail boot; the tree fixture still
|
||||
// compiles as a tree whose list schema carries no flat key.
|
||||
func TestReorderFlatCompile(t *testing.T) {
|
||||
const cfg = "controllers/badges/config_reorder.yaml"
|
||||
list, err := cabana.CompiledListSchema([]party.Plugin{catalogFSPlugin{fsys: catalogOverlay(t, nil)}}, "acme.catalog.badges")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if list.Reorder == nil || !list.Reorder.Flat || list.Reorder.Title != "Reorder badges" {
|
||||
t.Fatalf("badges reorder = %+v", list.Reorder)
|
||||
}
|
||||
raw, err := json.Marshal(list.Reorder)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(raw), `"flat":true`) {
|
||||
t.Fatalf("flat list schema JSON: %s", raw)
|
||||
}
|
||||
if err := activateCatalog(t, catalogFSPlugin{fsys: catalogOverlay(t, nil)}); err != nil {
|
||||
t.Fatalf("catalog boot: %v", err)
|
||||
}
|
||||
|
||||
src := catalogFile(t, cfg)
|
||||
for _, tc := range []struct {
|
||||
name, add string
|
||||
want []string
|
||||
}{
|
||||
{"maxDepth on a flat reorder", "maxDepth: 2\n", []string{cfg, "maxDepth needs a tree reorder"}},
|
||||
{"an explicit parentColumn that is not a column", "parentColumn: parent_id\n", []string{cfg, "parentColumn parent_id is not a column of the record"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := activateCatalog(t, catalogFSPlugin{fsys: catalogOverlay(t, map[string]string{cfg: src + tc.add})})
|
||||
if err == nil {
|
||||
t.Fatal("boot accepted the reorder config")
|
||||
}
|
||||
for _, part := range tc.want {
|
||||
if !strings.Contains(err.Error(), part) {
|
||||
t.Fatalf("err = %v, want %q", err, part)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("the tree fixture stays a tree", func(t *testing.T) {
|
||||
tree, err := cabana.CompiledListSchema([]party.Plugin{companionsFSPlugin{fsys: companionsOverlay(t, nil)}}, "acme.companions.links")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tree.Reorder == nil || tree.Reorder.Flat {
|
||||
t.Fatalf("links reorder = %+v", tree.Reorder)
|
||||
}
|
||||
raw, err := json.Marshal(tree)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(raw), `"flat"`) {
|
||||
t.Fatalf("tree list schema carries a flat key: %s", raw)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user