diff --git a/appinfo/routes.php b/appinfo/routes.php index 69c7ca590..26a2a4460 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -86,7 +86,7 @@ return [ ['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/{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#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'], diff --git a/lib/Controller/BoardApiController.php b/lib/Controller/BoardApiController.php index c76b04057..7859ea9cd 100644 --- a/lib/Controller/BoardApiController.php +++ b/lib/Controller/BoardApiController.php @@ -73,7 +73,7 @@ class BoardApiController extends ApiController { * @NoCSRFRequired * * - * Return the board specified by $this->request->params['boardId']. + * Return the board specified by $this->request->getParam('boardId'). */ public function get() { @@ -151,7 +151,7 @@ class BoardApiController extends ApiController { $board = $this->service->update($this->request->getParam('boardId'), $title, $color, $archived); 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); @@ -167,14 +167,14 @@ class BoardApiController extends ApiController { */ 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); - } + } - $board = $this->service->delete($this->request->params['boardId']); + $board = $this->service->delete($this->request->getParam('boardId')); 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); @@ -190,16 +190,14 @@ class BoardApiController extends ApiController { */ 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); - } + } - $board = $this->service->find($this->request->params['boardId']); + $board = $this->service->deleteUndo($this->request->getParam('boardId')); if ($board === false || $board === null) { - return new DataResponse('Board not found', HTTP::STATUS_NOT_FOUND); - } else { - $board = $this->service->deleteUndo($id); + return new DataResponse('board not found', HTTP::STATUS_NOT_FOUND); } return new DataResponse($board, HTTP::STATUS_OK); diff --git a/tests/unit/controller/BoardApiControllerTest.php b/tests/unit/controller/BoardApiControllerTest.php index 440c332d0..0ed9915b7 100644 --- a/tests/unit/controller/BoardApiControllerTest.php +++ b/tests/unit/controller/BoardApiControllerTest.php @@ -204,18 +204,99 @@ class BoardApiControllerTest extends \Test\TestCase { ->with('boardId') ->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']); $this->assertEquals($expected, $actual); } // TODO: Write testDelete() - public function testDelete() { - $this->assertEquals(false, true); + public function testDelete() { + + $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); } - // TODO: Write testUndoDelete() + 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); + } + 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); } } \ No newline at end of file