| 309 | } |
| 310 | |
| 311 | func TestBindCoreCollection(t *testing.T) { |
| 312 | vm := goja.New() |
| 313 | BindCore(vm) |
| 314 | |
| 315 | v, err := vm.RunString(`new Collection({ name: "test", createRule: "@request.auth.id != ''", fields: [{name: "title", "type": "text"}] })`) |
| 316 | if err != nil { |
| 317 | t.Fatal(err) |
| 318 | } |
| 319 | |
| 320 | m, ok := v.Export().(*core.Collection) |
| 321 | if !ok { |
| 322 | t.Fatalf("Expected core.Collection, got %v", m) |
| 323 | } |
| 324 | |
| 325 | if m.Name != "test" { |
| 326 | t.Fatalf("Expected collection with name %q, got %q", "test", m.Name) |
| 327 | } |
| 328 | |
| 329 | expectedRule := "@request.auth.id != ''" |
| 330 | if m.CreateRule == nil || *m.CreateRule != expectedRule { |
| 331 | t.Fatalf("Expected create rule %q, got %v", "@request.auth.id != ''", m.CreateRule) |
| 332 | } |
| 333 | |
| 334 | if f := m.Fields.GetByName("title"); f == nil { |
| 335 | t.Fatalf("Expected fields to be set, got %v", m.Fields) |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | func TestBindCoreFieldsList(t *testing.T) { |
| 340 | vm := goja.New() |