@@ -59,10 +59,20 @@ public static function getProtectedEndpoints(): iterable
5959 '/webservice-keys/1 ' ,
6060 ];
6161
62+ yield 'delete endpoint ' => [
63+ 'DELETE ' ,
64+ '/webservice-keys/1 ' ,
65+ ];
66+
6267 yield 'list endpoint ' => [
6368 'GET ' ,
6469 '/webservice-keys ' ,
6570 ];
71+
72+ yield 'bulk delete endpoint ' => [
73+ 'PUT ' ,
74+ '/webservice-keys/bulk-delete ' ,
75+ ];
6676 }
6777
6878 public function testAddWebserviceKey (): int
@@ -100,10 +110,6 @@ public function testAddWebserviceKey(): int
100110
101111 /**
102112 * @depends testAddWebserviceKey
103- *
104- * @param int $webserviceKeyId
105- *
106- * @return int
107113 */
108114 public function testGetWebserviceKey (int $ webserviceKeyId ): int
109115 {
@@ -144,10 +150,6 @@ public function testGetWebserviceKey(int $webserviceKeyId): int
144150
145151 /**
146152 * @depends testGetWebserviceKey
147- *
148- * @param int $webserviceKeyId
149- *
150- * @return int
151153 */
152154 public function testUpdateWebserviceKey (int $ webserviceKeyId ): int
153155 {
@@ -302,10 +304,6 @@ public function testUpdateWebserviceKey(int $webserviceKeyId): int
302304
303305 /**
304306 * @depends testUpdateWebserviceKey
305- *
306- * @param int $webserviceKeyId
307- *
308- * @return int
309307 */
310308 public function testGetUpdatedWebserviceKey (int $ webserviceKeyId ): int
311309 {
@@ -346,10 +344,6 @@ public function testGetUpdatedWebserviceKey(int $webserviceKeyId): int
346344
347345 /**
348346 * @depends testGetUpdatedWebserviceKey
349- *
350- * @param int $webserviceKeyId
351- *
352- * @return int
353347 */
354348 public function testListWebserviceKeys (int $ webserviceKeyId ): int
355349 {
@@ -378,6 +372,83 @@ public function testListWebserviceKeys(int $webserviceKeyId): int
378372 return $ webserviceKeyId ;
379373 }
380374
375+ /**
376+ * @depends testListWebserviceKeys
377+ */
378+ public function testDelete (int $ webserviceKeyId ): void
379+ {
380+ $ return = $ this ->deleteItem ('/webservice-keys/ ' . $ webserviceKeyId , ['webservice_key_write ' ]);
381+ // This endpoint return empty response and 204 HTTP code
382+ $ this ->assertNull ($ return );
383+
384+ // Getting the item should result in a 404 now
385+ $ this ->getItem ('/webservice-keys/ ' . $ webserviceKeyId , ['webservice_key_read ' ], Response::HTTP_NOT_FOUND );
386+ }
387+
388+ /**
389+ * @depends testListWebserviceKeys
390+ */
391+ public function testBulkDelete (): void
392+ {
393+ $ itemsCount = $ this ->countItems ('/webservice-keys ' , ['webservice_key_read ' ]);
394+ $ this ->assertEquals (0 , $ itemsCount );
395+
396+ $ webserviceKey1 = $ this ->createItem ('/webservice-keys ' , [
397+ 'key ' => 'AZERTYUIOPAZERTYUIOPAZERTYUIOPAZ ' ,
398+ 'description ' => 'Webservice Key test ' ,
399+ 'enabled ' => false ,
400+ 'permissions ' => [
401+ 'DELETE ' => ['addresses ' ],
402+ 'GET ' => ['addresses ' ],
403+ 'HEAD ' => ['addresses ' , 'carriers ' ],
404+ 'PATCH ' => ['addresses ' , 'carriers ' ],
405+ 'PUT ' => ['addresses ' , 'carriers ' , 'carts ' ],
406+ 'POST ' => ['addresses ' , 'carriers ' , 'carts ' ],
407+ ],
408+ 'shopIds ' => [1 ],
409+ ], ['webservice_key_write ' ]);
410+ $ this ->assertArrayHasKey ('webserviceKeyId ' , $ webserviceKey1 );
411+ $ webserviceKeyId1 = $ webserviceKey1 ['webserviceKeyId ' ];
412+
413+ $ webserviceKey2 = $ this ->createItem ('/webservice-keys ' , [
414+ 'key ' => 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ' ,
415+ 'description ' => 'Webservice Key test ' ,
416+ 'enabled ' => false ,
417+ 'permissions ' => [
418+ 'DELETE ' => ['addresses ' ],
419+ 'GET ' => ['addresses ' ],
420+ 'HEAD ' => ['addresses ' , 'carriers ' ],
421+ 'PATCH ' => ['addresses ' , 'carriers ' ],
422+ 'PUT ' => ['addresses ' , 'carriers ' , 'carts ' ],
423+ 'POST ' => ['addresses ' , 'carriers ' , 'carts ' ],
424+ ],
425+ 'shopIds ' => [1 ],
426+ ], ['webservice_key_write ' ]);
427+ $ this ->assertArrayHasKey ('webserviceKeyId ' , $ webserviceKey2 );
428+ $ webserviceKeyId2 = $ webserviceKey2 ['webserviceKeyId ' ];
429+
430+ $ itemsCount = $ this ->countItems ('/webservice-keys ' , ['webservice_key_read ' ]);
431+ $ this ->assertEquals (2 , $ itemsCount );
432+
433+ // We remove the two webservice keys
434+ $ bulkWebserviceKeyIds = [
435+ $ webserviceKeyId1 ,
436+ $ webserviceKeyId2 ,
437+ ];
438+
439+ $ this ->updateItem ('/webservice-keys/bulk-delete ' , [
440+ 'webserviceKeyIds ' => $ bulkWebserviceKeyIds ,
441+ ], ['webservice_key_write ' ], Response::HTTP_NO_CONTENT );
442+
443+ // Assert the provided webservice keys have been removed
444+ foreach ($ bulkWebserviceKeyIds as $ webserviceKeyId ) {
445+ $ this ->getItem ('/webservice-keys/ ' . $ webserviceKeyId , ['webservice_key_read ' ], Response::HTTP_NOT_FOUND );
446+ }
447+
448+ $ itemsCount = $ this ->countItems ('/webservice-keys ' , ['webservice_key_read ' ]);
449+ $ this ->assertEquals (0 , $ itemsCount );
450+ }
451+
381452 public function testCreateInvalidWebserviceKey (): void
382453 {
383454 // Creating with invalid data should return a response with invalid constraint messages and use an http code 422
0 commit comments