Changes to make possible implement api endpoint
Update documentation Start implementing getSystems route Code to route getSystems Controller to board import Change return Increase coverage Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
committed by
Julius Härtl
parent
39a927de18
commit
4138953208
@@ -22,25 +22,69 @@
|
||||
*/
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\AssignmentMapper;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class BoardImportServiceTest extends \Test\TestCase {
|
||||
/** @var TrelloImportService */
|
||||
private $trelloImportService;
|
||||
/** @var IDBConnection */
|
||||
protected $dbConn;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var BoardMapper */
|
||||
private $boardMapper;
|
||||
/** @var AclMapper */
|
||||
private $aclMapper;
|
||||
/** @var LabelMapper */
|
||||
private $labelMapper;
|
||||
/** @var StackMapper */
|
||||
private $stackMapper;
|
||||
/** @var CardMapper */
|
||||
private $cardMapper;
|
||||
/** @var AssignmentMapper */
|
||||
private $assignmentMapper;
|
||||
/** @var ICommentsManager */
|
||||
private $commentsManager;
|
||||
/** @var BoardImportService */
|
||||
private $boardImportService;
|
||||
public function setUp(): void {
|
||||
$this->trelloImportService = $this->createMock(TrelloImportService::class);
|
||||
$this->dbConn = $this->createMock(IDBConnection::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->boardMapper = $this->createMock(BoardMapper::class);
|
||||
$this->aclMapper = $this->createMock(AclMapper::class);
|
||||
$this->labelMapper = $this->createMock(LabelMapper::class);
|
||||
$this->stackMapper = $this->createMock(StackMapper::class);
|
||||
$this->cardMapper = $this->createMock(AssignmentMapper::class);
|
||||
$this->assignmentMapper = $this->createMock(CardMapper::class);
|
||||
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
||||
$this->boardImportService = new BoardImportService(
|
||||
$this->trelloImportService
|
||||
$this->dbConn,
|
||||
$this->userManager,
|
||||
$this->boardMapper,
|
||||
$this->aclMapper,
|
||||
$this->labelMapper,
|
||||
$this->stackMapper,
|
||||
$this->cardMapper,
|
||||
$this->assignmentMapper,
|
||||
$this->commentsManager
|
||||
);
|
||||
}
|
||||
|
||||
public function testImportSuccess() {
|
||||
$config = json_decode(file_get_contents(__DIR__ . '/../../data/config-trello.json'));
|
||||
$data = json_decode(file_get_contents(__DIR__ . '/../../data/data-trello.json'));
|
||||
$actual = $this->boardImportService->import(
|
||||
'trello',
|
||||
$config,
|
||||
$data
|
||||
);
|
||||
$importService = $this->createMock(ABoardImportService::class);
|
||||
$board = new Board();
|
||||
$importService
|
||||
->method('getBoard')
|
||||
->willReturn($board);
|
||||
$this->boardImportService->setImportSystem($importService);
|
||||
$actual = $this->boardImportService->import();
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
}
|
||||
|
||||
169
tests/unit/Service/BoardImportTrelloServiceTest.php
Normal file
169
tests/unit/Service/BoardImportTrelloServiceTest.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Vitor Mattos <vitor@php.rio>
|
||||
*
|
||||
* @author Vitor Mattos <vitor@php.rio>
|
||||
*
|
||||
* @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\Service;
|
||||
|
||||
use OCP\IL10N;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class BoardImportTrelloServiceTest extends \Test\TestCase {
|
||||
/** @var BoardImportTrelloService */
|
||||
private $service;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
public function setUp(): void {
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->service = new BoardImportTrelloService(
|
||||
$this->userManager,
|
||||
$this->l10n
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidateUsersWithoutUsers() {
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
}
|
||||
|
||||
public function testValidateUsersWithInvalidUser() {
|
||||
$this->expectErrorMessage('Trello user trello_user not found in property "members" of json data');
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$importService
|
||||
->method('getConfig')
|
||||
->willReturn([
|
||||
'trello_user' => 'nextcloud_user'
|
||||
]);
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"username": "othre_trello_user"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
}
|
||||
|
||||
public function testValidateUsersWithNotStringNextcloud() {
|
||||
$this->expectErrorMessage('User on setting uidRelation is invalid');
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$importService
|
||||
->method('getConfig')
|
||||
->willReturn([
|
||||
'trello_user' => []
|
||||
]);
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"username": "trello_user"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
}
|
||||
|
||||
public function testValidateUsersWithNotFoundUser() {
|
||||
$this->expectErrorMessage('User on setting uidRelation not found: nextcloud_user');
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$importService
|
||||
->method('getConfig')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"trello_user": "nextcloud_user"
|
||||
}
|
||||
JSON
|
||||
));
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"username": "trello_user"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
}
|
||||
|
||||
public function testValidateUsersWithValidUsers() {
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$importService
|
||||
->method('getConfig')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"trello_user": "nextcloud_user"
|
||||
}
|
||||
JSON
|
||||
));
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"id": "fakeid",
|
||||
"username": "trello_user"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
$fakeUser = $this->createMock(IUser::class);
|
||||
$this->userManager
|
||||
// ->expects($this->once())
|
||||
->method('get')
|
||||
->with('nextcloud_user')
|
||||
->willReturn($fakeUser);
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
}
|
||||
}
|
||||
@@ -73,8 +73,6 @@ class BoardServiceTest extends TestCase {
|
||||
private $changeHelper;
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
/** @var TrelloImportService */
|
||||
private $trelloImportService;
|
||||
private $userId = 'admin';
|
||||
|
||||
public function setUp(): void {
|
||||
@@ -93,7 +91,6 @@ class BoardServiceTest extends TestCase {
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->trelloImportService = $this->createMock(TrelloImportService::class);
|
||||
|
||||
$this->service = new BoardService(
|
||||
$this->boardMapper,
|
||||
@@ -110,7 +107,6 @@ class BoardServiceTest extends TestCase {
|
||||
$this->activityManager,
|
||||
$this->eventDispatcher,
|
||||
$this->changeHelper,
|
||||
$this->trelloImportService,
|
||||
$this->userId
|
||||
);
|
||||
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Vitor Mattos <vitor@php.rio>
|
||||
*
|
||||
* @author Vitor Mattos <vitor@php.rio>
|
||||
*
|
||||
* @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\Service;
|
||||
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\AssignmentMapper;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class TrelloImportServiceTest extends \Test\TestCase {
|
||||
/** @var TrelloImportService */
|
||||
private $trelloImportService;
|
||||
/** @var BoardService */
|
||||
private $boardService;
|
||||
/** @var LabelService */
|
||||
private $labelService;
|
||||
/** @var StackMapper */
|
||||
private $stackMapper;
|
||||
/** @var CardMapper */
|
||||
private $cardMapper;
|
||||
/** @var AssignmentMapper */
|
||||
private $assignmentMapper;
|
||||
/** @var AclMapper */
|
||||
private $aclMapper;
|
||||
/** @var IDBConnection */
|
||||
private $connection;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->boardService = $this->createMock(BoardService::class);
|
||||
$this->labelService = $this->createMock(LabelService::class);
|
||||
$this->stackMapper = $this->createMock(StackMapper::class);
|
||||
$this->cardMapper = $this->createMock(CardMapper::class);
|
||||
$this->assignmentMapper = $this->createMock(AssignmentMapper::class);
|
||||
$this->aclMapper = $this->createMock(AclMapper::class);
|
||||
$this->connection = $this->createMock(IDBConnection::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->trelloImportService = new TrelloImportService(
|
||||
$this->boardService,
|
||||
$this->labelService,
|
||||
$this->stackMapper,
|
||||
$this->cardMapper,
|
||||
$this->assignmentMapper,
|
||||
$this->aclMapper,
|
||||
$this->connection,
|
||||
$this->userManager,
|
||||
$this->l10n
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidateOwnerWithFaliure() {
|
||||
$owner = $this->createMock(\OCP\IUser::class);
|
||||
$owner
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
$this->trelloImportService->setConfig('owner', $owner);
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->willReturn(null);
|
||||
$this->expectErrorMessage('Owner "admin" not found on Nextcloud. Check setting json.');
|
||||
$this->trelloImportService->validateOwner();
|
||||
}
|
||||
|
||||
public function testValidateOwnerWithSuccess() {
|
||||
$owner = $this->createMock(\OCP\IUser::class);
|
||||
$owner
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
$this->trelloImportService->setConfig('owner', $owner);
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->willReturn($owner);
|
||||
$actual = $this->trelloImportService->validateOwner();
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user