MCPcopy
hub / github.com/pocketbase/pocketbase / TestCollectionSaveModel

Function TestCollectionSaveModel

core/collection_model_test.go:1297–1515  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1295}
1296
1297func TestCollectionSaveModel(t *testing.T) {
1298 t.Parallel()
1299
1300 scenarios := []struct {
1301 name string
1302 collection func(app core.App) (*core.Collection, error)
1303 expectError bool
1304 expectColumns []string
1305 }{
1306 // trigger validators
1307 {
1308 name: "create - trigger validators",
1309 collection: func(app core.App) (*core.Collection, error) {
1310 c := core.NewBaseCollection("!invalid")
1311 c.Fields.Add(&core.TextField{Name: "example"})
1312 c.AddIndex("test_save_idx", false, "example", "")
1313 return c, nil
1314 },
1315 expectError: true,
1316 },
1317 {
1318 name: "update - trigger validators",
1319 collection: func(app core.App) (*core.Collection, error) {
1320 c, _ := app.FindCollectionByNameOrId("demo5")
1321 c.Name = "demo1"
1322 c.Fields.Add(&core.TextField{Name: "example"})
1323 c.Fields.RemoveByName("file")
1324 c.AddIndex("test_save_idx", false, "example", "")
1325 return c, nil
1326 },
1327 expectError: true,
1328 },
1329
1330 // create
1331 {
1332 name: "create base collection",
1333 collection: func(app core.App) (*core.Collection, error) {
1334 c := core.NewBaseCollection("new")
1335 c.Type = "" // should be auto set to "base"
1336 c.Fields.RemoveByName("id") // ensure that the default fields will be loaded
1337 c.Fields.Add(&core.TextField{Name: "example"})
1338 c.AddIndex("test_save_idx", false, "example", "")
1339 return c, nil
1340 },
1341 expectError: false,
1342 expectColumns: []string{
1343 "id", "example",
1344 },
1345 },
1346 {
1347 name: "create auth collection",
1348 collection: func(app core.App) (*core.Collection, error) {
1349 c := core.NewAuthCollection("new")
1350 c.Fields.RemoveByName("id") // ensure that the default fields will be loaded
1351 c.Fields.RemoveByName("email") // ensure that the default fields will be loaded
1352 c.Fields.Add(&core.TextField{Name: "example"})
1353 c.AddIndex("test_save_idx", false, "example", "")
1354 return c, nil

Callers

nothing calls this directly

Calls 15

CleanupMethod · 0.95
NewBaseCollectionFunction · 0.92
NewAuthCollectionFunction · 0.92
NewViewCollectionFunction · 0.92
NewTestAppFunction · 0.92
ParseIndexFunction · 0.92
AddIndexMethod · 0.80
RemoveByNameMethod · 0.80
GetByNameMethod · 0.80
collectionMethod · 0.80
SetNameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…