(t *testing.T)
| 263 | } |
| 264 | |
| 265 | func TestBindCoreRecord(t *testing.T) { |
| 266 | app, _ := tests.NewTestApp() |
| 267 | defer app.Cleanup() |
| 268 | |
| 269 | collection, err := app.FindCachedCollectionByNameOrId("users") |
| 270 | if err != nil { |
| 271 | t.Fatal(err) |
| 272 | } |
| 273 | |
| 274 | vm := goja.New() |
| 275 | BindCore(vm) |
| 276 | vm.Set("collection", collection) |
| 277 | |
| 278 | // without record data |
| 279 | // --- |
| 280 | v1, err := vm.RunString(`new Record(collection)`) |
| 281 | if err != nil { |
| 282 | t.Fatal(err) |
| 283 | } |
| 284 | |
| 285 | m1, ok := v1.Export().(*core.Record) |
| 286 | if !ok { |
| 287 | t.Fatalf("Expected m1 to be models.Record, got \n%v", m1) |
| 288 | } |
| 289 | |
| 290 | // with record data |
| 291 | // --- |
| 292 | v2, err := vm.RunString(`new Record(collection, { email: "test@example.com" })`) |
| 293 | if err != nil { |
| 294 | t.Fatal(err) |
| 295 | } |
| 296 | |
| 297 | m2, ok := v2.Export().(*core.Record) |
| 298 | if !ok { |
| 299 | t.Fatalf("Expected m2 to be core.Record, got \n%v", m2) |
| 300 | } |
| 301 | |
| 302 | if m2.Collection().Name != "users" { |
| 303 | t.Fatalf("Expected record with collection %q, got \n%v", "users", m2.Collection()) |
| 304 | } |
| 305 | |
| 306 | if m2.Email() != "test@example.com" { |
| 307 | t.Fatalf("Expected record with email field set to %q, got \n%v", "test@example.com", m2) |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | func TestBindCoreCollection(t *testing.T) { |
| 312 | vm := goja.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…