MCPcopy
hub / github.com/pocketbase/pocketbase / TestCollectionDelete

Function TestCollectionDelete

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

Source from the content-addressed store, hash-verified

264}
265
266func TestCollectionDelete(t *testing.T) {
267 t.Parallel()
268
269 ensureDeletedFiles := func(app *tests.TestApp, collectionId string) {
270 storageDir := filepath.Join(app.DataDir(), "storage", collectionId)
271
272 entries, _ := os.ReadDir(storageDir)
273 if len(entries) != 0 {
274 t.Errorf("Expected empty/deleted dir, found %d", len(entries))
275 }
276 }
277
278 scenarios := []tests.ApiScenario{
279 {
280 Name: "unauthorized",
281 Method: http.MethodDelete,
282 URL: "/api/collections/demo1",
283 ExpectedStatus: 401,
284 ExpectedContent: []string{`"data":{}`},
285 ExpectedEvents: map[string]int{"*": 0},
286 },
287 {
288 Name: "authorized as regular user",
289 Method: http.MethodDelete,
290 URL: "/api/collections/demo1",
291 Headers: map[string]string{
292 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyNTI0NjA0NDYxLCJyZWZyZXNoYWJsZSI6dHJ1ZX0.ZT3F0Z3iM-xbGgSG3LEKiEzHrPHr8t8IuHLZGGNuxLo",
293 },
294 ExpectedStatus: 403,
295 ExpectedContent: []string{`"data":{}`},
296 ExpectedEvents: map[string]int{"*": 0},
297 },
298 {
299 Name: "authorized as superuser + nonexisting collection identifier",
300 Method: http.MethodDelete,
301 URL: "/api/collections/missing",
302 Headers: map[string]string{
303 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY",
304 },
305 ExpectedStatus: 404,
306 ExpectedContent: []string{`"data":{}`},
307 ExpectedEvents: map[string]int{"*": 0},
308 },
309 {
310 Name: "authorized as superuser + using the collection name",
311 Method: http.MethodDelete,
312 URL: "/api/collections/demo5",
313 Headers: map[string]string{
314 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY",
315 },
316 Delay: 100 * time.Millisecond,
317 ExpectedStatus: 204,
318 ExpectedEvents: map[string]int{
319 "*": 0,
320 "OnCollectionDeleteRequest": 1,
321 "OnCollectionDelete": 1,
322 "OnCollectionDeleteExecute": 1,
323 "OnCollectionAfterDeleteSuccess": 1,

Callers

nothing calls this directly

Calls 7

BadRequestErrorMethod · 0.80
TestMethod · 0.80
DataDirMethod · 0.65
RunInTransactionMethod · 0.65
NextMethod · 0.65
BindFuncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…