BoardApiControllerTest wrote delete tests

Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
Ryan Fletcher
2018-07-15 07:48:57 -04:00
committed by Julius Härtl
parent 8dd732631a
commit 6d57b1081a
3 changed files with 97 additions and 18 deletions

View File

@@ -86,7 +86,7 @@ return [
['name' => 'board_api#undo_delete', 'url' => '/api/v1.0/boards/{boardId}/undo_delete', 'verb' => 'POST'], ['name' => 'board_api#undo_delete', 'url' => '/api/v1.0/boards/{boardId}/undo_delete', 'verb' => 'POST'],
['name' => 'stack_api#index', 'url' => '/api/v1.0/boards/{boardId}/stacks', 'verb' => 'GET'], ['name' => 'stack_api#index', 'url' => '/api/v1.0/boards/{boardId}/stacks', 'verb' => 'GET'],
['name' => 'stack_api#index', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'GET'], ['name' => 'stack_api#get', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'GET'],
['name' => 'stack_api#create', 'url' => '/api/v1.0/boards/{boardId}/stacks', 'verb' => 'POST'], ['name' => 'stack_api#create', 'url' => '/api/v1.0/boards/{boardId}/stacks', 'verb' => 'POST'],
['name' => 'stack_api#update', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'PUT'], ['name' => 'stack_api#update', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'PUT'],
['name' => 'stack_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'DELETE'], ['name' => 'stack_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'DELETE'],

View File

@@ -73,7 +73,7 @@ class BoardApiController extends ApiController {
* @NoCSRFRequired * @NoCSRFRequired
* *
* *
* Return the board specified by $this->request->params['boardId']. * Return the board specified by $this->request->getParam('boardId').
*/ */
public function get() { public function get() {
@@ -151,7 +151,7 @@ class BoardApiController extends ApiController {
$board = $this->service->update($this->request->getParam('boardId'), $title, $color, $archived); $board = $this->service->update($this->request->getParam('boardId'), $title, $color, $archived);
if ($board === false || $board === null) { if ($board === false || $board === null) {
return new DataResponse('Board not found', HTTP::STATUS_NOT_FOUND); return new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
} }
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
@@ -167,14 +167,14 @@ class BoardApiController extends ApiController {
*/ */
public function delete() { public function delete() {
if (is_numeric($this->request->params['boardId']) === false) { if (is_numeric($this->request->getParam('boardId')) === false) {
return new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST); return new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
} }
$board = $this->service->delete($this->request->params['boardId']); $board = $this->service->delete($this->request->getParam('boardId'));
if ($board === false || $board === null) { if ($board === false || $board === null) {
return new DataResponse('Board not found', HTTP::STATUS_NOT_FOUND); return new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
} }
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
@@ -190,16 +190,14 @@ class BoardApiController extends ApiController {
*/ */
public function undoDelete() { public function undoDelete() {
if (is_numeric($this->request->params['boardId']) === false) { if (is_numeric($this->request->getParam('boardId')) === false) {
return new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST); return new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
} }
$board = $this->service->find($this->request->params['boardId']); $board = $this->service->deleteUndo($this->request->getParam('boardId'));
if ($board === false || $board === null) { if ($board === false || $board === null) {
return new DataResponse('Board not found', HTTP::STATUS_NOT_FOUND); return new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
} else {
$board = $this->service->deleteUndo($id);
} }
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);

View File

@@ -204,18 +204,99 @@ class BoardApiControllerTest extends \Test\TestCase {
->with('boardId') ->with('boardId')
->will($this->returnValue($this->exampleBoard['id'])); ->will($this->returnValue($this->exampleBoard['id']));
$expected = new DataResponse('Board not found', HTTP::STATUS_NOT_FOUND); $expected = new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
$actual = $this->controller->update($this->exampleBoard['title'], $this->exampleBoard['color']); $actual = $this->controller->update($this->exampleBoard['title'], $this->exampleBoard['color']);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
// TODO: Write testDelete() // TODO: Write testDelete()
public function testDelete() { public function testDelete() {
$this->assertEquals(false, true);
$board = new Board();
$board->setId($this->exampleBoard['id']);
$board->setTitle($this->exampleBoard['title']);
$board->setColor($this->exampleBoard['color']);
$this->boardService->expects($this->once())
->method('delete')
->willReturn($board);
$this->request->expects($this->any())
->method('getParam')
->with('boardId')
->will($this->returnValue($this->exampleBoard['id']));
$expected = new DataResponse($board, HTTP::STATUS_OK);
$actual = $this->controller->delete();
$this->assertEquals($expected, $actual);
}
public function testDeleteBadId() {
$this->request->expects($this->any())
->method('getParam')
->with('boardId')
->will($this->returnValue('bad id'));
$expected = new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
$actual = $this->controller->delete();
$this->assertEquals($expected, $actual);
}
public function testDeleteNotFound() {
$this->request->expects($this->any())
->method('getParam')
->with('boardId')
->will($this->returnValue('85'));
$expected = new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
$actual = $this->controller->delete();
$this->assertEquals($expected, $actual);
} }
// TODO: Write testUndoDelete()
public function testUndoDelete() { public function testUndoDelete() {
$this->assertEquals(false, true); $board = new board();
$board->setId($this->exampleBoard['id']);
$board->setTitle($this->exampleBoard['title']);
$board->setColor($this->exampleBoard['color']);
$this->boardService->expects($this->once())
->method('deleteUndo')
->willReturn($board);
$this->request->expects($this->any())
->method('getParam')
->with('boardId')
->will($this->returnValue($this->exampleBoard['id']));
$expected = new DataResponse($board, HTTP::STATUS_OK);
$actual = $this->controller->undoDelete();
$this->assertEquals($expected, $actual);
}
public function testUndoDeleteBadId() {
$this->request->expects($this->any())
->method('getParam')
->with('boardId')
->will($this->returnValue('bad id'));
$expected = new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
$actual = $this->controller->undoDelete();
$this->assertEquals($expected, $actual);
}
public function testUndoDeleteNotFound() {
$this->request->expects($this->any())
->method('getParam')
->with('boardId')
->will($this->returnValue(189));
$expected = new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
$actual = $this->controller->undoDelete();
$this->assertEquals($expected, $actual);
} }
} }