MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordDBExport

Function TestRecordDBExport

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

Source from the content-addressed store, hash-verified

1215}
1216
1217func TestRecordDBExport(t *testing.T) {
1218 t.Parallel()
1219
1220 app, _ := tests.NewTestApp()
1221 defer app.Cleanup()
1222
1223 f1 := &core.TextField{Name: "field1"}
1224 f2 := &core.FileField{Name: "field2", MaxSelect: 1, MaxSize: 1}
1225 f3 := &core.SelectField{Name: "field3", MaxSelect: 2, Values: []string{"test1", "test2", "test3"}}
1226 f4 := &core.RelationField{Name: "field4", MaxSelect: 2}
1227
1228 colBase := core.NewBaseCollection("test_base")
1229 colBase.Fields.Add(f1, f2, f3, f4)
1230
1231 colAuth := core.NewAuthCollection("test_auth")
1232 colAuth.Fields.Add(f1, f2, f3, f4)
1233
1234 scenarios := []struct {
1235 collection *core.Collection
1236 expected string
1237 }{
1238 {
1239 colBase,
1240 `{"field1":"test","field2":"test.png","field3":["test1","test2"],"field4":["test11","test12"],"id":"test_id"}`,
1241 },
1242 {
1243 colAuth,
1244 `{"email":"test_email","emailVisibility":true,"field1":"test","field2":"test.png","field3":["test1","test2"],"field4":["test11","test12"],"id":"test_id","password":"_TEST_","tokenKey":"test_tokenKey","verified":false}`,
1245 },
1246 }
1247
1248 data := map[string]any{
1249 "id": "test_id",
1250 "field1": "test",
1251 "field2": "test.png",
1252 "field3": []string{"test1", "test2"},
1253 "field4": []string{"test11", "test12", "test11"}, // strip duplicate,
1254 "unknown": "test_unknown",
1255 "password": "test_passwordHash",
1256 "username": "test_username",
1257 "emailVisibility": true,
1258 "email": "test_email",
1259 "verified": "invalid", // should be casted
1260 "tokenKey": "test_tokenKey",
1261 }
1262
1263 for i, s := range scenarios {
1264 t.Run(fmt.Sprintf("%d_%s_%s", i, s.collection.Type, s.collection.Name), func(t *testing.T) {
1265 record := core.NewRecord(s.collection)
1266
1267 record.Load(data)
1268
1269 result, err := record.DBExport(app)
1270 if err != nil {
1271 t.Fatal(err)
1272 }
1273
1274 raw, err := json.Marshal(result)

Callers

nothing calls this directly

Calls 9

CleanupMethod · 0.95
LoadMethod · 0.95
DBExportMethod · 0.95
NewTestAppFunction · 0.92
NewBaseCollectionFunction · 0.92
NewAuthCollectionFunction · 0.92
NewRecordFunction · 0.92
AddMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…