Wrote tests for CardApiControllerTest.php
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
committed by
Julius Härtl
parent
5bc8a363b9
commit
9c81584b02
@@ -43,7 +43,6 @@ class CardApiController extends ApiController {
|
|||||||
private $boardService;
|
private $boardService;
|
||||||
private $stackService;
|
private $stackService;
|
||||||
private $userId;
|
private $userId;
|
||||||
private $apiHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
@@ -51,13 +50,10 @@ class CardApiController extends ApiController {
|
|||||||
* @param CardService $service
|
* @param CardService $service
|
||||||
* @param $userId
|
* @param $userId
|
||||||
*/
|
*/
|
||||||
public function __construct($appName, IRequest $request, CardService $cardService, BoardService $boardService, StackService $stackService, $userId) {
|
public function __construct($appName, IRequest $request, CardService $cardService, $userId) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->boardService = $boardService;
|
|
||||||
$this->cardService = $cardService;
|
$this->cardService = $cardService;
|
||||||
$this->stackService = $stackService;
|
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->apiHelper = new ApiHelper();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,7 +64,7 @@ class CardApiController extends ApiController {
|
|||||||
* Get a specific card.
|
* Get a specific card.
|
||||||
*/
|
*/
|
||||||
public function get() {
|
public function get() {
|
||||||
$card = $this->cardService->find($this->request->params['cardId']);
|
$card = $this->cardService->find($this->request->getParam('cardId'));
|
||||||
return new DataResponse($card, HTTP::STATUS_OK);
|
return new DataResponse($card, HTTP::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +80,7 @@ class CardApiController extends ApiController {
|
|||||||
* Get a specific card.
|
* Get a specific card.
|
||||||
*/
|
*/
|
||||||
public function create($title, $type = 'plain', $order = 999) {
|
public function create($title, $type = 'plain', $order = 999) {
|
||||||
$card = $this->cardService->create($title, $this->request->params['stackId'], $type, $order, $this->userId);
|
$card = $this->cardService->create($title, $this->request->getParam('stackId'), $type, $order, $this->userId);
|
||||||
return new DataResponse($card, HTTP::STATUS_OK);
|
return new DataResponse($card, HTTP::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,20 +92,11 @@ class CardApiController extends ApiController {
|
|||||||
*
|
*
|
||||||
* Update a card
|
* Update a card
|
||||||
*/
|
*/
|
||||||
public function update($cardId, $title, $stackId, $type, $order = 0, $description = '', $owner, $duedate = null) {
|
public function update($title, $type, $order = 0, $description = '', $owner, $duedate = null) {
|
||||||
$card = $this->cardService->update($this->request->getParam('cardId'), $title, $this->request->getParam('stackId'), $type, $order, $description, $owner, $duedate);
|
$card = $this->cardService->update($this->request->getParam('cardId'), $title, $this->request->getParam('stackId'), $type, $order, $description, $owner, $duedate);
|
||||||
return new DataResponse($card, HTTP::STATUS_OK);
|
return new DataResponse($card, HTTP::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function assignUser() {
|
|
||||||
throw new Exception('Not Implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function unassignUser() {
|
|
||||||
throw new Exception('Not Implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @CORS
|
* @CORS
|
||||||
@@ -118,7 +105,7 @@ class CardApiController extends ApiController {
|
|||||||
* Delete a specific card.
|
* Delete a specific card.
|
||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete() {
|
||||||
$card = $this->cardService->delete($this->request->params['cardId']);
|
$card = $this->cardService->delete($this->request->getParam('cardId'));
|
||||||
return new DataResponse($card, HTTP::STATUS_OK);
|
return new DataResponse($card, HTTP::STATUS_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,6 @@ use OCP\IRequest;
|
|||||||
use OCA\Deck\StatusException;
|
use OCA\Deck\StatusException;
|
||||||
use OCA\Deck\Service\StackService;
|
use OCA\Deck\Service\StackService;
|
||||||
use OCA\Deck\Service\BoardService;
|
use OCA\Deck\Service\BoardService;
|
||||||
use OCA\Deck\Controller\Helper\ApiHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class StackApiController
|
* Class StackApiController
|
||||||
@@ -43,7 +42,6 @@ class StackApiController extends ApiController {
|
|||||||
|
|
||||||
private $boardService;
|
private $boardService;
|
||||||
private $stackService;
|
private $stackService;
|
||||||
private $apiHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
@@ -54,7 +52,6 @@ class StackApiController extends ApiController {
|
|||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->stackService = $stackService;
|
$this->stackService = $stackService;
|
||||||
$this->boardService = $boardService;
|
$this->boardService = $boardService;
|
||||||
$this->apiHelper = new ApiHelper();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
138
tests/unit/controller/CardApiControllerTest.php
Normal file
138
tests/unit/controller/CardApiControllerTest.php
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2018 Ryan Fletcher <ryan.fletcher@codepassion.ca>
|
||||||
|
*
|
||||||
|
* @author Ryan Fletcher <ryan.fletcher@codepassion.ca>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
namespace OCA\Deck\Controller;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http;
|
||||||
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
use OCP\IRequest;
|
||||||
|
|
||||||
|
use OCA\Deck\Db\Card;
|
||||||
|
use OCA\Deck\Service\CardService;
|
||||||
|
|
||||||
|
class CardApiControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
|
private $controller;
|
||||||
|
private $request;
|
||||||
|
private $cardService;
|
||||||
|
private $userId = 'admin';
|
||||||
|
private $cardExample;
|
||||||
|
private $stackExample;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->request = $this->createMock(IRequest::class);
|
||||||
|
$this->cardService = $this->createMock(CardService::class);
|
||||||
|
|
||||||
|
$this->cardExample['id'] = 1;
|
||||||
|
$this->stackExample['id'] = 1;
|
||||||
|
|
||||||
|
$this->controller = new CardApiController (
|
||||||
|
$appName = 'deck',
|
||||||
|
$this->request,
|
||||||
|
$this->cardService,
|
||||||
|
$this->userId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGet() {
|
||||||
|
$card = new Card();
|
||||||
|
$card->setId($this->cardExample['id']);
|
||||||
|
|
||||||
|
$this->request->expects($this->once())
|
||||||
|
->method('getParam')
|
||||||
|
->with('cardId')
|
||||||
|
->will($this->returnValue($this->cardExample['id']));
|
||||||
|
|
||||||
|
$this->cardService->expects($this->once())
|
||||||
|
->method('find')
|
||||||
|
->willReturn($card);
|
||||||
|
|
||||||
|
$expected = new DataResponse($card, HTTP::STATUS_OK);
|
||||||
|
$actual = $this->controller->get();
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreate() {
|
||||||
|
|
||||||
|
$card = new Card();
|
||||||
|
$card->setId($this->cardExample['id']);
|
||||||
|
$card->setStackId($this->stackExample['id']);
|
||||||
|
|
||||||
|
$this->request->expects($this->once())
|
||||||
|
->method('getParam')
|
||||||
|
->with('stackId')
|
||||||
|
->willReturn($this->stackExample['id']);
|
||||||
|
|
||||||
|
$this->cardService->expects($this->once())
|
||||||
|
->method('create')
|
||||||
|
->willReturn($card);
|
||||||
|
|
||||||
|
$expected = new DataResponse($card, HTTP::STATUS_OK);
|
||||||
|
$actual = $this->controller->create('title');
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdate() {
|
||||||
|
$card = new Card();
|
||||||
|
$card->setId($this->cardExample['id']);
|
||||||
|
$card->setStackId($this->stackExample['id']);
|
||||||
|
|
||||||
|
$this->request->expects($this->exactly(2))
|
||||||
|
->method('getParam')
|
||||||
|
->withConsecutive(
|
||||||
|
['cardId'],
|
||||||
|
['stackId']
|
||||||
|
)->willReturnonConsecutiveCalls(
|
||||||
|
$this->cardExample['id'],
|
||||||
|
$this->stackExample['id']);
|
||||||
|
|
||||||
|
$this->cardService->expects($this->once())
|
||||||
|
->method('update')
|
||||||
|
->willReturn($card);
|
||||||
|
|
||||||
|
$expected = new DataResponse($card, HTTP::STATUS_OK);
|
||||||
|
$actual = $this->controller->update('title', 'plain', 0, 'description', $this->userId, null);
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDelete() {
|
||||||
|
|
||||||
|
$card = new Card();
|
||||||
|
$card->setId($this->cardExample['id']);
|
||||||
|
|
||||||
|
$this->request->expects($this->once())
|
||||||
|
->method('getParam')
|
||||||
|
->with('cardId')
|
||||||
|
->will($this->returnValue($this->cardExample['id']));
|
||||||
|
|
||||||
|
$this->cardService->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->willReturn($card);
|
||||||
|
|
||||||
|
$expected = new DataResponse($card, HTTP::STATUS_OK);
|
||||||
|
$actual = $this->controller->delete();
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user