MCPcopy
hub / github.com/pocketbase/pocketbase / TestDynamicModelMapFieldCaching

Function TestDynamicModelMapFieldCaching

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

Source from the content-addressed store, hash-verified

1287}
1288
1289func TestDynamicModelMapFieldCaching(t *testing.T) {
1290 app, _ := tests.NewTestApp()
1291 defer app.Cleanup()
1292
1293 vm := goja.New()
1294 BindCore(vm)
1295 BindDbx(vm)
1296 vm.Set("$app", app)
1297
1298 _, err := vm.RunString(`
1299 let m1 = new DynamicModel({
1300 int: 0,
1301 float: -0,
1302 text: "",
1303 bool: false,
1304 obj: {},
1305 arr: [],
1306 })
1307
1308 let m2 = new DynamicModel({
1309 int: 0,
1310 float: -0,
1311 text: "",
1312 bool: false,
1313 obj: {},
1314 arr: [],
1315 })
1316
1317 m1.int = 1
1318 m1.float = 1.5
1319 m1.text = "a"
1320 m1.bool = true
1321 m1.obj.set("a", 1)
1322 m1.arr.push(1)
1323
1324 m2.int = 2
1325 m2.float = 2.5
1326 m2.text = "b"
1327 m2.bool = false
1328 m2.obj.set("b", 1)
1329 m2.arr.push(2)
1330
1331 let m1Expected = '{"arr":[1],"bool":true,"float":1.5,"int":1,"obj":{"a":1},"text":"a"}';
1332 let m1Serialized = JSON.stringify(m1);
1333 if (m1Serialized != m1Expected) {
1334 throw new Error("Expected m1 \n" + m1Expected + "\ngot\n" + m1Serialized);
1335 }
1336
1337 let m2Expected = '{"arr":[2],"bool":false,"float":2.5,"int":2,"obj":{"b":1},"text":"b"}';
1338 let m2Serialized = JSON.stringify(m2);
1339 if (m2Serialized != m2Expected) {
1340 throw new Error("Expected m2 \n" + m2Expected + "\ngot\n" + m2Serialized);
1341 }
1342 `)
1343 if err != nil {
1344 t.Fatal(err)
1345 }
1346}

Callers

nothing calls this directly

Calls 5

CleanupMethod · 0.95
NewTestAppFunction · 0.92
BindCoreFunction · 0.85
BindDbxFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…