(t *testing.T)
| 320 | } |
| 321 | |
| 322 | func TestImportCollectionsUpdateRules(t *testing.T) { |
| 323 | t.Parallel() |
| 324 | |
| 325 | scenarios := []struct { |
| 326 | name string |
| 327 | data map[string]any |
| 328 | deleteMissing bool |
| 329 | }{ |
| 330 | { |
| 331 | "extend existing by name (without deleteMissing)", |
| 332 | map[string]any{"name": "clients", "authToken": map[string]any{"duration": 100}, "fields": []map[string]any{{"name": "test", "type": "text"}}}, |
| 333 | false, |
| 334 | }, |
| 335 | { |
| 336 | "extend existing by id (without deleteMissing)", |
| 337 | map[string]any{"id": "v851q4r790rhknl", "authToken": map[string]any{"duration": 100}, "fields": []map[string]any{{"name": "test", "type": "text"}}}, |
| 338 | false, |
| 339 | }, |
| 340 | { |
| 341 | "extend with delete missing", |
| 342 | map[string]any{ |
| 343 | "id": "v851q4r790rhknl", |
| 344 | "authToken": map[string]any{"duration": 100}, |
| 345 | "fields": []map[string]any{{"name": "test", "type": "text"}}, |
| 346 | "passwordAuth": map[string]any{"identityFields": []string{"email"}}, |
| 347 | "indexes": []string{ |
| 348 | // min required system fields indexes |
| 349 | "CREATE UNIQUE INDEX `_v851q4r790rhknl_email_idx` ON `clients` (email) WHERE email != ''", |
| 350 | "CREATE UNIQUE INDEX `_v851q4r790rhknl_tokenKey_idx` ON `clients` (tokenKey)", |
| 351 | }, |
| 352 | }, |
| 353 | true, |
| 354 | }, |
| 355 | } |
| 356 | |
| 357 | for _, s := range scenarios { |
| 358 | t.Run(s.name, func(t *testing.T) { |
| 359 | testApp, _ := tests.NewTestApp() |
| 360 | defer testApp.Cleanup() |
| 361 | |
| 362 | beforeCollection, err := testApp.FindCollectionByNameOrId("clients") |
| 363 | if err != nil { |
| 364 | t.Fatal(err) |
| 365 | } |
| 366 | |
| 367 | err = testApp.ImportCollections([]map[string]any{s.data}, s.deleteMissing) |
| 368 | if err != nil { |
| 369 | t.Fatal(err) |
| 370 | } |
| 371 | |
| 372 | afterCollection, err := testApp.FindCollectionByNameOrId("clients") |
| 373 | if err != nil { |
| 374 | t.Fatal(err) |
| 375 | } |
| 376 | |
| 377 | if afterCollection.AuthToken.Duration != 100 { |
| 378 | t.Fatalf("Expected AuthToken duration to be %d, got %d", 100, afterCollection.AuthToken.Duration) |
| 379 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…