| 429 | } |
| 430 | |
| 431 | func TestCollectionPostScan(t *testing.T) { |
| 432 | t.Parallel() |
| 433 | |
| 434 | rawOptions := types.JSONRaw(`{ |
| 435 | "viewQuery":"select 1", |
| 436 | "authRule":"1=2" |
| 437 | }`) |
| 438 | |
| 439 | scenarios := []struct { |
| 440 | typ string |
| 441 | rawOptions types.JSONRaw |
| 442 | expected []string |
| 443 | }{ |
| 444 | { |
| 445 | core.CollectionTypeBase, |
| 446 | rawOptions, |
| 447 | []string{ |
| 448 | `lastSavedPK:"test"`, |
| 449 | `ViewQuery:""`, |
| 450 | `AuthRule:(*string)(nil)`, |
| 451 | }, |
| 452 | }, |
| 453 | { |
| 454 | core.CollectionTypeView, |
| 455 | rawOptions, |
| 456 | []string{ |
| 457 | `lastSavedPK:"test"`, |
| 458 | `ViewQuery:"select 1"`, |
| 459 | `AuthRule:(*string)(nil)`, |
| 460 | }, |
| 461 | }, |
| 462 | { |
| 463 | core.CollectionTypeAuth, |
| 464 | rawOptions, |
| 465 | []string{ |
| 466 | `lastSavedPK:"test"`, |
| 467 | `ViewQuery:""`, |
| 468 | `AuthRule:(*string)(0x`, |
| 469 | }, |
| 470 | }, |
| 471 | } |
| 472 | |
| 473 | for i, s := range scenarios { |
| 474 | t.Run(fmt.Sprintf("%d_%s", i, s.typ), func(t *testing.T) { |
| 475 | c := core.Collection{} |
| 476 | c.Id = "test" |
| 477 | c.Type = s.typ |
| 478 | c.RawOptions = s.rawOptions |
| 479 | |
| 480 | err := c.PostScan() |
| 481 | if err != nil { |
| 482 | t.Fatal(err) |
| 483 | } |
| 484 | |
| 485 | if c.IsNew() { |
| 486 | t.Fatal("Expected the collection to be marked as not new") |
| 487 | } |
| 488 | |