Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Service/Importer/Systems/DeckJsonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function getCards(): array {
$boardOwner = $this->getBoard()->getOwner();
$card->setOwner($this->mapOwner(is_string($boardOwner) ? $boardOwner : $boardOwner->getUID()));
$card->setDuedate($cardSource->duedate);
$card->setDone($cardSource->done ?? null);
$cards[$cardSource->id] = $card;
}
return $cards;
Expand Down
1 change: 1 addition & 0 deletions tests/data/deck.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
},
"order": 999,
"archived": false,
"done": "2023-07-18T10:00:00+00:00",
"duedate": "2050-07-24T22:00:00+00:00",
"deletedAt": 0,
"commentsUnread": 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/base-query-count.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
84323
84627
1 change: 1 addition & 0 deletions tests/integration/import/ImportExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ public function assertDatabase(string $owner = 'admin') {
'lastModified' => 1689667779,
'createdAt' => 1689667569,
'owner' => $owner,
'done' => new \DateTime('2023-07-18T10:00:00+00:00'),
'duedate' => new \DateTime('2050-07-24T22:00:00.000000+0000'),
'order' => 999,
'stackId' => $stacks[0]->getId(),
Expand Down
70 changes: 54 additions & 16 deletions tests/unit/Service/Importer/Systems/DeckJsonServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
namespace OCA\Deck\Service\Importer\Systems;

use OCA\Deck\Service\Importer\BoardImportService;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Server;
Expand All @@ -36,20 +34,12 @@
*/
class DeckJsonServiceTest extends \Test\TestCase {
private DeckJsonService $service;
/** @var IURLGenerator|MockObject */
private $urlGenerator;
/** @var IUserManager|MockObject */
private $userManager;
/** @var IL10N */
private $l10n;
public function setUp(): void {
$this->userManager = $this->createMock(IUserManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10n = $this->createMock(IL10N::class);
$this->service = new DeckJsonService(
$this->userManager,
$this->urlGenerator,
$this->l10n
);
}

Expand All @@ -61,6 +51,59 @@ public function testGetBoardWithNoName() {
}

public function testGetBoardWithSuccess() {
$importService = $this->setUpImportService();

$boards = $this->service->getBoards();
$importService->setData($boards[0]);
$actual = $this->service->getBoard();
$this->assertEquals('My test board', $actual->getTitle());
$this->assertEquals('admin', $actual->getOwner());
$this->assertEquals('e0ed31', $actual->getColor());
}

public function testGetCards() {
$importService = $this->setUpImportService();

$boards = $this->service->getBoards();
$importService->setData($boards[0]);

$importService->getBoard()->setId(1);

$this->service->getLabels();

$stacks = $this->service->getStacks();
$stackId = 1;
foreach ($stacks as $code => $stack) {
$stack->setId($stackId++);
$this->service->updateStack($code, $stack);
}

$cards = $this->service->getCards();

$this->assertCount(6, $cards);

// Card 114 (title "1") has a done value set in the fixture
$card114 = $cards[114];
$this->assertEquals('1', $card114->getTitle());
$this->assertInstanceOf(\DateTime::class, $card114->getDone());
$this->assertEquals('2023-07-18T10:00:00+00:00', $card114->getDone()->format(\DateTime::ATOM));
$this->assertEquals('2050-07-24T22:00:00+00:00', $card114->getDuedate()->format(\DateTime::ATOM));
$this->assertFalse($card114->getArchived());
$this->assertEquals('admin', $card114->getOwner());

// Card 115 (title "2") has no done value in the fixture
$card115 = $cards[115];
$this->assertEquals('2', $card115->getTitle());
$this->assertNull($card115->getDone());

// Card 119 (title "6") — from stack B, no done value
$card119 = $cards[119];
$this->assertEquals('6', $card119->getTitle());
$this->assertNull($card119->getDone());
$this->assertEquals('# Test description' . "\n\n" . 'Hello world', $card119->getDescription());
}

private function setUpImportService(): BoardImportService {
$importService = Server::get(BoardImportService::class);

$data = json_decode(file_get_contents(__DIR__ . '/../../../../data/deck.json'));
Expand All @@ -77,11 +120,6 @@ public function testGetBoardWithSuccess() {

$this->service->setImportService($importService);

$boards = $this->service->getBoards();
$importService->setData($boards[0]);
$actual = $this->service->getBoard();
$this->assertEquals('My test board', $actual->getTitle());
$this->assertEquals('admin', $actual->getOwner());
$this->assertEquals('e0ed31', $actual->getColor());
return $importService;
}
}