Skip to content

[FEATURE] REST action for deleting a list #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## x.y.z

### Added
- REST API endpoint for deleting a list (#98)
- REST API endpoint for getting list details (#89)
- System tests for the test and dev environment (#81)
- REST action for getting all subscribers for a list (#83)
Expand Down
24 changes: 24 additions & 0 deletions docs/Api/RestApi.apib
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ provided as basic auth password. (The basic auth user name can be any string.)
"id": 1
}

+ Response 403 (application/json)

+ Body

{
"code": 403,
"message": "No valid session key was provided as basic auth password."
}

+ Response 404 (application/json)

+ Body

{
"code": 404,
"message": "There is no list with that ID."
}

### Delete a the list [DELETE]

+ Request (application/json)

+ Response 204 (application/json)

+ Response 403 (application/json)

+ Body
Expand Down
17 changes: 17 additions & 0 deletions src/Controller/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ public function getAction(Request $request, SubscriberList $list): View
return View::create()->setData($list);
}

/**
* Deletes a subscriber list.
*
* @param Request $request
* @param SubscriberList $list
*
* @return View
*/
public function deleteAction(Request $request, SubscriberList $list): View
{
$this->requireAuthentication($request);

$this->subscriberListRepository->remove($list);

return View::create();
}

/**
* Gets a list of all subscribers (members) of a subscriber list.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Integration/Controller/AbstractControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ protected function assertHttpCreated()
$this->assertHttpStatusWithJsonContentType(Response::HTTP_CREATED);
}

/**
* Asserts that the current client response has a HTTP NO CONTENT status.
*
* @return void
*/
protected function assertHttpNoContent()
{
$response = $this->client->getResponse();

static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode());
}

/**
* Asserts that the current client response has a HTTP BAD REQUEST status (and the application/json content type).
*
Expand Down
51 changes: 51 additions & 0 deletions tests/Integration/Controller/ListControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace PhpList\RestBundle\Tests\Integration\Controller;

use PhpList\PhpList4\Domain\Repository\Messaging\SubscriberListRepository;
use PhpList\RestBundle\Controller\ListController;

/**
Expand Down Expand Up @@ -171,6 +172,56 @@ public function getListWithCurrentSessionKeyReturnsListData()
);
}

/**
* @test
*/
public function deleteListWithoutSessionKeyForExistingListReturnsForbiddenStatus()
{
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
$this->applyDatabaseChanges();

$this->client->request('delete', '/api/v2/lists/1');

$this->assertHttpForbidden();
}

/**
* @test
*/
public function deleteListWithCurrentSessionKeyForExistingListReturnsNoContentStatus()
{
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
$this->applyDatabaseChanges();

$this->authenticatedJsonRequest('delete', '/api/v2/lists/1');

$this->assertHttpNoContent();
}

/**
* @test
*/
public function deleteListWithCurrentSessionKeyForInexistentListReturnsNotFoundStatus()
{
$this->authenticatedJsonRequest('delete', '/api/v2/lists/999');

$this->assertHttpNotFound();
}

/**
* @test
*/
public function deleteListWithCurrentSessionKeyDeletesList()
{
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
$this->applyDatabaseChanges();

$this->authenticatedJsonRequest('delete', '/api/v2/lists/1');

$listRepository = $this->container->get(SubscriberListRepository::class);
static::assertNull($listRepository->find(1));
}

/**
* @test
*/
Expand Down