BoardApiController wrote update tests
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
committed by
Julius Härtl
parent
1fe70568cb
commit
8dd732631a
@@ -132,7 +132,7 @@ class BoardApiController extends ApiController {
|
||||
*/
|
||||
public function update($title, $color, $archived = false) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -140,15 +140,15 @@ class BoardApiController extends ApiController {
|
||||
return new DataResponse('archived must be a boolean', HTTP::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ($title === false) {
|
||||
if ($title === false || $title === null) {
|
||||
return new DataResponse('title must be provided', HTTP::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ($color === false) {
|
||||
if ($color === false || $color === null) {
|
||||
return new DataResponse('color must be provided', HTTP::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$board = $this->service->update($this->request->params['boardId'], $title, $color, $archived);
|
||||
$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);
|
||||
|
||||
@@ -139,10 +139,74 @@ class BoardApiControllerTest extends \Test\TestCase {
|
||||
$actual = $this->controller->create($this->exampleBoard['title'], null);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
// TODO: Write testUpdate()
|
||||
|
||||
public function testUpdate() {
|
||||
$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('update')
|
||||
->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->update($this->exampleBoard['title'], $this->exampleBoard['color']);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testUpdateBadId() {
|
||||
$expected = new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||
$actual = $this->controller->update($this->exampleBoard['title'], $this->exampleBoard['color']);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testUpdateBadArchived() {
|
||||
$this->request->expects($this->any())
|
||||
->method('getParam')
|
||||
->with('boardId')
|
||||
->will($this->returnValue($this->exampleBoard['id']));
|
||||
|
||||
$expected = new DataResponse('archived must be a boolean', HTTP::STATUS_BAD_REQUEST);
|
||||
$actual = $this->controller->update($this->exampleBoard['title'], $this->exampleBoard['color'], 'Not a boolean value');
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testUpdateBadTitle() {
|
||||
$this->request->expects($this->any())
|
||||
->method('getParam')
|
||||
->with('boardId')
|
||||
->will($this->returnValue($this->exampleBoard['id']));
|
||||
|
||||
$expected = new DataResponse('title must be provided', HTTP::STATUS_BAD_REQUEST);
|
||||
$actual = $this->controller->update(null, $this->exampleBoard['color']);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testUpdateBadColor() {
|
||||
$this->request->expects($this->any())
|
||||
->method('getParam')
|
||||
->with('boardId')
|
||||
->will($this->returnValue($this->exampleBoard['id']));
|
||||
|
||||
$expected = new DataResponse('color must be provided', HTTP::STATUS_BAD_REQUEST);
|
||||
$actual = $this->controller->update($this->exampleBoard['title'], null);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testUpdateBoardNotFound() {
|
||||
$this->request->expects($this->any())
|
||||
->method('getParam')
|
||||
->with('boardId')
|
||||
->will($this->returnValue($this->exampleBoard['id']));
|
||||
|
||||
$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()
|
||||
|
||||
Reference in New Issue
Block a user