(t *testing.T)
| 445 | } |
| 446 | |
| 447 | func TestCollectionCreate(t *testing.T) { |
| 448 | t.Parallel() |
| 449 | |
| 450 | scenarios := []tests.ApiScenario{ |
| 451 | { |
| 452 | Name: "unauthorized", |
| 453 | Method: http.MethodPost, |
| 454 | URL: "/api/collections", |
| 455 | ExpectedStatus: 401, |
| 456 | ExpectedContent: []string{`"data":{}`}, |
| 457 | ExpectedEvents: map[string]int{"*": 0}, |
| 458 | }, |
| 459 | { |
| 460 | Name: "authorized as regular user", |
| 461 | Method: http.MethodPost, |
| 462 | URL: "/api/collections", |
| 463 | Body: strings.NewReader(`{"name":"new","type":"base","fields":[{"type":"text","name":"test"}]}`), |
| 464 | Headers: map[string]string{ |
| 465 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyNTI0NjA0NDYxLCJyZWZyZXNoYWJsZSI6dHJ1ZX0.ZT3F0Z3iM-xbGgSG3LEKiEzHrPHr8t8IuHLZGGNuxLo", |
| 466 | }, |
| 467 | ExpectedStatus: 403, |
| 468 | ExpectedContent: []string{`"data":{}`}, |
| 469 | ExpectedEvents: map[string]int{"*": 0}, |
| 470 | }, |
| 471 | { |
| 472 | Name: "authorized as superuser + empty data", |
| 473 | Method: http.MethodPost, |
| 474 | URL: "/api/collections", |
| 475 | Body: strings.NewReader(``), |
| 476 | Headers: map[string]string{ |
| 477 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY", |
| 478 | }, |
| 479 | ExpectedStatus: 400, |
| 480 | ExpectedContent: []string{ |
| 481 | `"data":{`, |
| 482 | `"name":{"code":"validation_required"`, |
| 483 | }, |
| 484 | NotExpectedContent: []string{ |
| 485 | `"fields":{`, |
| 486 | }, |
| 487 | ExpectedEvents: map[string]int{ |
| 488 | "*": 0, |
| 489 | "OnCollectionCreateRequest": 1, |
| 490 | "OnCollectionCreate": 1, |
| 491 | "OnCollectionAfterCreateError": 1, |
| 492 | "OnCollectionValidate": 1, |
| 493 | "OnModelCreate": 1, |
| 494 | "OnModelAfterCreateError": 1, |
| 495 | "OnModelValidate": 1, |
| 496 | }, |
| 497 | }, |
| 498 | { |
| 499 | Name: "authorized as superuser + invalid data (eg. existing name)", |
| 500 | Method: http.MethodPost, |
| 501 | URL: "/api/collections", |
| 502 | Body: strings.NewReader(`{"name":"demo1","type":"base","fields":[{"type":"text","name":""}]}`), |
| 503 | Headers: map[string]string{ |
| 504 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY", |
nothing calls this directly
no test coverage detected
searching dependent graphs…