Create route to get json schema to validate config
Fix visibility Make compatible with php 7.2 Remove returing instance Increase coverage Reduce psalm info Throw exception if system not defined Increment coverage Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
@@ -31,6 +31,7 @@ use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class BoardImportServiceTest extends \Test\TestCase {
|
||||
@@ -83,8 +84,32 @@ class BoardImportServiceTest extends \Test\TestCase {
|
||||
$importService
|
||||
->method('getBoard')
|
||||
->willReturn($board);
|
||||
$this->boardImportService->setSystem('trello');
|
||||
$this->boardImportService->setImportSystem($importService);
|
||||
$actual = $this->boardImportService->import();
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
|
||||
public function testImportBoard() {
|
||||
$this->boardImportService->setSystem('trello');
|
||||
$data = json_decode(file_get_contents(__DIR__ . '/../../data/data-trello.json'));
|
||||
$this->boardImportService->setData($data);
|
||||
$configInstance = json_decode(file_get_contents(__DIR__ . '/../../data/config-trello.json'));
|
||||
$this->boardImportService->setConfigInstance($configInstance);
|
||||
|
||||
$owner = $this->createMock(IUser::class);
|
||||
$owner
|
||||
->method('getUID')
|
||||
->willReturn('owner');
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->willReturn($owner);
|
||||
$this->boardImportService->validateOwner();
|
||||
$actual = $this->boardImportService->importBoard();
|
||||
$this->assertNull($actual);
|
||||
$board = $this->boardImportService->getBoard();
|
||||
$this->assertEquals('Test Board Name', $board->getTitle());
|
||||
$this->assertEquals('owner', $board->getOwner());
|
||||
$this->assertEquals('0800fd', $board->getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
@@ -46,7 +47,7 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
|
||||
public function testValidateUsersWithInvalidUser() {
|
||||
@@ -59,17 +60,7 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
||||
]);
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"username": "othre_trello_user"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
->willReturn(json_decode('{"members": [{"username": "othre_trello_user"}]}'));
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
@@ -85,17 +76,7 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
||||
]);
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"username": "trello_user"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
->willReturn(json_decode('{"members": [{"username": "trello_user"}]}'));
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
@@ -106,26 +87,10 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$importService
|
||||
->method('getConfig')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"trello_user": "nextcloud_user"
|
||||
}
|
||||
JSON
|
||||
));
|
||||
->willReturn(json_decode('{"trello_user": "nextcloud_user"}'));
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"username": "trello_user"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
->willReturn(json_decode('{"members": [{"username": "trello_user"}]}'));
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->validateUsers();
|
||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||
@@ -135,35 +100,53 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$importService
|
||||
->method('getConfig')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"trello_user": "nextcloud_user"
|
||||
}
|
||||
JSON
|
||||
));
|
||||
->willReturn(json_decode('{"trello_user": "nextcloud_user"}'));
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode(
|
||||
<<<JSON
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"id": "fakeid",
|
||||
"username": "trello_user"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
->willReturn(json_decode('{"members": [{"id": "fakeid", "username": "trello_user"}]}'));
|
||||
$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);
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
|
||||
public function testGetBoardWithSuccess() {
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$owner = $this->createMock(IUser::class);
|
||||
$owner
|
||||
->method('getUID')
|
||||
->willReturn('owner');
|
||||
$importService
|
||||
->method('getConfig')
|
||||
->withConsecutive(
|
||||
['owner'],
|
||||
['color']
|
||||
)->willReturnonConsecutiveCalls(
|
||||
$owner,
|
||||
'000000'
|
||||
);
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(json_decode('{"name": "test"}'));
|
||||
$this->service->setImportService($importService);
|
||||
$actual = $this->service->getBoard();
|
||||
$this->assertInstanceOf(Board::class, $actual);
|
||||
$this->assertEquals('test', $actual->getTitle());
|
||||
$this->assertEquals('owner', $actual->getOwner());
|
||||
$this->assertEquals('000000', $actual->getColor());
|
||||
}
|
||||
|
||||
public function testGetBoardWithInvalidName() {
|
||||
$this->expectErrorMessage('Invalid name of board');
|
||||
$importService = $this->createMock(BoardImportService::class);
|
||||
$importService
|
||||
->method('getData')
|
||||
->willReturn(new \stdClass);
|
||||
$this->service->setImportService($importService);
|
||||
$this->service->getBoard();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user