chore: initial commit of ai site platform
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
52
platform/internal/blueprint/ident_test.go
Normal file
52
platform/internal/blueprint/ident_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package blueprint
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeIdent(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"beforeDay": "before_day",
|
||||
"cjl.value": "cjl_value",
|
||||
"nextDay": "next_day",
|
||||
"settlement-observation": "settlement_observation",
|
||||
"Already_ok": "already_ok",
|
||||
}
|
||||
for in, want := range cases {
|
||||
got := NormalizeIdent(in)
|
||||
if got != want {
|
||||
t.Fatalf("%s => %s, want %s", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeFields(t *testing.T) {
|
||||
bp := &Blueprint{
|
||||
Version: "1.0",
|
||||
Meta: Meta{Name: "t", Slug: "demo_app", Locale: "zh-CN"},
|
||||
Storage: Storage{Mode: "schema_per_app", Engine: "postgres"},
|
||||
Entities: []Entity{{
|
||||
Name: "Point", Table: "Point", PrimaryKey: "id", Label: "p",
|
||||
Fields: []Field{
|
||||
{Name: "id", Label: "ID", Type: "bigint"},
|
||||
{Name: "beforeDay", Label: "b", Type: "int"},
|
||||
{Name: "cjl.value", Label: "v", Type: "decimal"},
|
||||
},
|
||||
}},
|
||||
Apis: Apis{Resources: []APIResource{{
|
||||
Entity: "Point", Path: "/Points", Operations: []string{"list"},
|
||||
List: &ListOpt{AllowedFilters: []string{"beforeDay"}},
|
||||
}}},
|
||||
Pages: []Page{{
|
||||
ID: "l", Title: "list", Route: "/x", Type: "list", Entity: "Point",
|
||||
Layout: &PageLayout{Columns: []string{"beforeDay", "cjl.value"}, Filters: []string{"beforeDay"}},
|
||||
}},
|
||||
}
|
||||
if err := bp.Validate("demo_app"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if bp.Entities[0].Fields[1].Name != "before_day" {
|
||||
t.Fatalf("field=%s", bp.Entities[0].Fields[1].Name)
|
||||
}
|
||||
if bp.Pages[0].Layout.Columns[0] != "before_day" {
|
||||
t.Fatalf("col=%v", bp.Pages[0].Layout.Columns)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user