MCPcopy Create free account
hub / github.com/pocketbase/pocketbase / TestBindCoreRecord

Function TestBindCoreRecord

plugins/jsvm/binds_test.go:265–309  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

263}
264
265func 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
311func TestBindCoreCollection(t *testing.T) {
312 vm := goja.New()

Callers

nothing calls this directly

Calls 7

CleanupMethod · 0.95
NewTestAppFunction · 0.92
BindCoreFunction · 0.85
CollectionMethod · 0.80
EmailMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…