Skip to content

Commit 2ea825e

Browse files
author
Oliver Klee
committed
[FEATURE] REST action for deleting a list
1 parent 76c7811 commit 2ea825e

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
77
## x.y.z
88

99
### Added
10+
- REST API endpoint for deleting a list (#98)
1011
- REST API endpoint for getting list details (#89)
1112
- System tests for the test and dev environment (#81)
1213
- REST action for getting all subscribers for a list (#83)

docs/Api/RestApi.apib

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,30 @@ provided as basic auth password. (The basic auth user name can be any string.)
148148
"id": 1
149149
}
150150

151+
+ Response 403 (application/json)
152+
153+
+ Body
154+
155+
{
156+
"code": 403,
157+
"message": "No valid session key was provided as basic auth password."
158+
}
159+
160+
+ Response 404 (application/json)
161+
162+
+ Body
163+
164+
{
165+
"code": 404,
166+
"message": "There is no list with that ID."
167+
}
168+
169+
### Delete a the list [DELETE]
170+
171+
+ Request (application/json)
172+
173+
+ Response 204 (application/json)
174+
151175
+ Response 403 (application/json)
152176

153177
+ Body

src/Controller/ListController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ public function getAction(Request $request, SubscriberList $list): View
6565
return View::create()->setData($list);
6666
}
6767

68+
/**
69+
* Deletes a subscriber list.
70+
*
71+
* @param Request $request
72+
* @param SubscriberList $list
73+
*
74+
* @return View
75+
*/
76+
public function deleteAction(Request $request, SubscriberList $list): View
77+
{
78+
$this->requireAuthentication($request);
79+
80+
$this->subscriberListRepository->remove($list);
81+
82+
return View::create();
83+
}
84+
6885
/**
6986
* Gets a list of all subscribers (members) of a subscriber list.
7087
*

tests/Integration/Controller/AbstractControllerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ protected function assertHttpCreated()
149149
$this->assertHttpStatusWithJsonContentType(Response::HTTP_CREATED);
150150
}
151151

152+
/**
153+
* Asserts that the current client response has a HTTP NO CONTENT status.
154+
*
155+
* @return void
156+
*/
157+
protected function assertHttpNoContent()
158+
{
159+
$response = $this->client->getResponse();
160+
161+
static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode());
162+
}
163+
152164
/**
153165
* Asserts that the current client response has a HTTP BAD REQUEST status (and the application/json content type).
154166
*

tests/Integration/Controller/ListControllerTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace PhpList\RestBundle\Tests\Integration\Controller;
55

6+
use PhpList\PhpList4\Domain\Repository\Messaging\SubscriberListRepository;
67
use PhpList\RestBundle\Controller\ListController;
78

89
/**
@@ -171,6 +172,56 @@ public function getListWithCurrentSessionKeyReturnsListData()
171172
);
172173
}
173174

175+
/**
176+
* @test
177+
*/
178+
public function deleteListWithoutSessionKeyForExistingListReturnsForbiddenStatus()
179+
{
180+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
181+
$this->applyDatabaseChanges();
182+
183+
$this->client->request('delete', '/api/v2/lists/1');
184+
185+
$this->assertHttpForbidden();
186+
}
187+
188+
/**
189+
* @test
190+
*/
191+
public function deleteListWithCurrentSessionKeyForExistingListReturnsNoContentStatus()
192+
{
193+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
194+
$this->applyDatabaseChanges();
195+
196+
$this->authenticatedJsonRequest('delete', '/api/v2/lists/1');
197+
198+
$this->assertHttpNoContent();
199+
}
200+
201+
/**
202+
* @test
203+
*/
204+
public function deleteListWithCurrentSessionKeyForInexistentListReturnsNotFoundStatus()
205+
{
206+
$this->authenticatedJsonRequest('delete', '/api/v2/lists/999');
207+
208+
$this->assertHttpNotFound();
209+
}
210+
211+
/**
212+
* @test
213+
*/
214+
public function deleteListWithCurrentSessionKeyDeletesList()
215+
{
216+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
217+
$this->applyDatabaseChanges();
218+
219+
$this->authenticatedJsonRequest('delete', '/api/v2/lists/1');
220+
221+
$listRepository = $this->container->get(SubscriberListRepository::class);
222+
static::assertNull($listRepository->find(1));
223+
}
224+
174225
/**
175226
* @test
176227
*/

0 commit comments

Comments
 (0)