Wrote unit tests for the BoardApiController -> create tests
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
committed by
Julius Härtl
parent
bd254fd261
commit
1fe70568cb
@@ -102,11 +102,11 @@ class BoardApiController extends ApiController {
|
|||||||
*/
|
*/
|
||||||
public function create($title, $color) {
|
public function create($title, $color) {
|
||||||
|
|
||||||
if ($title === false) {
|
if ($title === false || $title === null) {
|
||||||
return new DataResponse('title must be provided', HTTP::STATUS_BAD_REQUEST);
|
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);
|
return new DataResponse('color must be provided', HTTP::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OCA\Deck\Controller;
|
namespace OCA\Deck\Controller;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
@@ -36,6 +35,7 @@ class BoardApiControllerTest extends \Test\TestCase {
|
|||||||
private $userId = 'admin';
|
private $userId = 'admin';
|
||||||
private $controller;
|
private $controller;
|
||||||
private $boardService;
|
private $boardService;
|
||||||
|
private $exampleBoard;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@@ -49,6 +49,9 @@ class BoardApiControllerTest extends \Test\TestCase {
|
|||||||
$this->userId
|
$this->userId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->exampleBoard['id'] = 1;
|
||||||
|
$this->exampleBoard['title'] = 'titled';
|
||||||
|
$this->exampleBoard['color'] = '000000';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIndex() {
|
public function testIndex() {
|
||||||
@@ -111,9 +114,30 @@ class BoardApiControllerTest extends \Test\TestCase {
|
|||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Write testCreate()
|
|
||||||
public function testCreate() {
|
public function testCreate() {
|
||||||
$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('create')
|
||||||
|
->willReturn($board);
|
||||||
|
|
||||||
|
$expected = new DataResponse($board, HTTP::STATUS_OK);
|
||||||
|
$actual = $this->controller->create($this->exampleBoard['title'], $this->exampleBoard['color']);
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateBadTitle() {
|
||||||
|
$expected = new DataResponse('title must be provided', HTTP::STATUS_BAD_REQUEST);
|
||||||
|
$actual = $this->controller->create(null, $this->exampleBoard['color']);
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateBadColor() {
|
||||||
|
$expected = new DataResponse('color must be provided', HTTP::STATUS_BAD_REQUEST);
|
||||||
|
$actual = $this->controller->create($this->exampleBoard['title'], null);
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Write testUpdate()
|
// TODO: Write testUpdate()
|
||||||
|
|||||||
Reference in New Issue
Block a user