MCPcopy
hub / github.com/pocketbase/pocketbase / TestCollectionUpdate

Function TestCollectionUpdate

apis/collection_test.go:984–1450  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

982}
983
984func TestCollectionUpdate(t *testing.T) {
985 t.Parallel()
986
987 scenarios := []tests.ApiScenario{
988 {
989 Name: "unauthorized",
990 Method: http.MethodPatch,
991 URL: "/api/collections/demo1",
992 ExpectedStatus: 401,
993 ExpectedContent: []string{`"data":{}`},
994 ExpectedEvents: map[string]int{"*": 0},
995 },
996 {
997 Name: "authorized as regular user",
998 Method: http.MethodPatch,
999 URL: "/api/collections/demo1",
1000 Headers: map[string]string{
1001 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyNTI0NjA0NDYxLCJyZWZyZXNoYWJsZSI6dHJ1ZX0.ZT3F0Z3iM-xbGgSG3LEKiEzHrPHr8t8IuHLZGGNuxLo",
1002 },
1003 ExpectedStatus: 403,
1004 ExpectedContent: []string{`"data":{}`},
1005 ExpectedEvents: map[string]int{"*": 0},
1006 },
1007 {
1008 Name: "authorized as superuser + missing collection",
1009 Method: http.MethodPatch,
1010 URL: "/api/collections/missing",
1011 Body: strings.NewReader(`{}`),
1012 Headers: map[string]string{
1013 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY",
1014 },
1015 ExpectedStatus: 404,
1016 ExpectedContent: []string{`"data":{}`},
1017 ExpectedEvents: map[string]int{"*": 0},
1018 },
1019 {
1020 Name: "authorized as superuser + empty body",
1021 Method: http.MethodPatch,
1022 URL: "/api/collections/demo1",
1023 Body: strings.NewReader(`{}`),
1024 Headers: map[string]string{
1025 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY",
1026 },
1027 ExpectedStatus: 200,
1028 ExpectedContent: []string{
1029 `"id":"wsmn24bux7wo113"`,
1030 `"name":"demo1"`,
1031 },
1032 ExpectedEvents: map[string]int{
1033 "*": 0,
1034 "OnCollectionUpdateRequest": 1,
1035 "OnCollectionUpdate": 1,
1036 "OnCollectionUpdateExecute": 1,
1037 "OnCollectionAfterUpdateSuccess": 1,
1038 "OnCollectionValidate": 1,
1039 "OnModelUpdate": 1,
1040 "OnModelUpdateExecute": 1,
1041 "OnModelAfterUpdateSuccess": 1,

Callers

nothing calls this directly

Calls 13

ExistInSliceFunction · 0.92
NewReaderMethod · 0.80
BadRequestErrorMethod · 0.80
AddIndexMethod · 0.80
TestMethod · 0.80
RunInTransactionMethod · 0.65
NextMethod · 0.65
HasTableMethod · 0.65
SaveMethod · 0.65
TableIndexesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…