MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordIgnoreUnchangedFields

Function TestRecordIgnoreUnchangedFields

core/record_model_test.go:1294–1366  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1292}
1293
1294func TestRecordIgnoreUnchangedFields(t *testing.T) {
1295 t.Parallel()
1296
1297 app, _ := tests.NewTestApp()
1298 defer app.Cleanup()
1299
1300 col, err := app.FindCollectionByNameOrId("demo3")
1301 if err != nil {
1302 t.Fatal(err)
1303 }
1304
1305 new := core.NewRecord(col)
1306
1307 existing, err := app.FindRecordById(col, "mk5fmymtx4wsprk")
1308 if err != nil {
1309 t.Fatal(err)
1310 }
1311 existing.Set("title", "test_new")
1312 existing.Set("files", existing.Get("files")) // no change
1313
1314 scenarios := []struct {
1315 ignoreUnchangedFields bool
1316 record *core.Record
1317 expected []string
1318 }{
1319 {
1320 false,
1321 new,
1322 []string{"id", "created", "updated", "title", "files"},
1323 },
1324 {
1325 true,
1326 new,
1327 []string{"id", "created", "updated", "title", "files"},
1328 },
1329 {
1330 false,
1331 existing,
1332 []string{"id", "created", "updated", "title", "files"},
1333 },
1334 {
1335 true,
1336 existing,
1337 []string{"id", "title"},
1338 },
1339 }
1340
1341 for i, s := range scenarios {
1342 action := "create"
1343 if !s.record.IsNew() {
1344 action = "update"
1345 }
1346
1347 t.Run(fmt.Sprintf("%d_%s_%v", i, action, s.ignoreUnchangedFields), func(t *testing.T) {
1348 s.record.IgnoreUnchangedFields(s.ignoreUnchangedFields)
1349
1350 result, err := s.record.DBExport(app)
1351 if err != nil {

Callers

nothing calls this directly

Calls 11

CleanupMethod · 0.95
NewTestAppFunction · 0.92
NewRecordFunction · 0.92
IgnoreUnchangedFieldsMethod · 0.80
FindRecordByIdMethod · 0.65
SetMethod · 0.65
GetMethod · 0.65
IsNewMethod · 0.65
DBExportMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…