added the create tests in StackApiControllerTest

Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
Ryan Fletcher
2018-07-15 21:11:49 -04:00
committed by Julius Härtl
parent 5719e9f134
commit 570ac81848
2 changed files with 96 additions and 47 deletions

View File

@@ -85,15 +85,15 @@ class StackApiController extends ApiController {
* Return all of the stacks in the specified board.
*/
public function get() {
if (is_numeric($this->request->getParam('stackId')) === false) {
return new DataResponse('stack id must be a number', HTTP::STATUS_BAD_REQUEST);
}
$boardError = $this->apiHelper->entityHasError($this->request->getParam('boardId'), 'board', $this->boardService);
if ($boardError) {
return new DataResponse($boardError['message'], $boardError['status']);
}
if (is_numeric($this->request->getParam('stackId')) === false) {
return new DataResponse('stack id must be a number', HTTP::STATUS_BAD_REQUEST);
}
}
$stack = $this->service->find($this->request->getParam('stackId'));
@@ -116,22 +116,21 @@ class StackApiController extends ApiController {
*/
public function create($title, $order) {
$boardError = $this->apiHelper->entityHasError( $this->request->getParam('boardId'), 'board', $this->boardService );
if ($boardError) {
return new DataResponse($boardError['message'], $boardError['status']);
if ($title === false || $title === null) {
return new DataResponse('title must be provided', HTTP::STATUS_BAD_REQUEST);
}
if (is_numeric($order) === false) {
return new DataResponse('order must be a number', HTTP::STATUS_BAD_REQUEST);
}
try {
$stack = $this->service->create($title, $this->request->getParam('boardId'), $order);
} catch (StatusException $e) {
$errorMessage['error'] = $e->getMessage();
return new DataResponse($errorMessage, HTTP::STATUS_INTERNAL_SERVER_ERROR);
}
$boardError = $this->apiHelper->entityHasError( $this->request->getParam('boardId'), 'board', $this->boardService );
if ($boardError) {
return new DataResponse($boardError['message'], $boardError['status']);
}
$stack = $this->service->create($title, $this->request->getParam('boardId'), $order);
return new DataResponse($stack, HTTP::STATUS_OK);
}