Skip to content

Commit 79fc19f

Browse files
authored
Merge pull request #7735 from nextcloud/fix/7536/set-done-value-on-import
fix(import): done state is not kept on importing a board
2 parents b23ce62 + 40e36d9 commit 79fc19f

5 files changed

Lines changed: 58 additions & 17 deletions

File tree

lib/Service/Importer/Systems/DeckJsonService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public function getCards(): array {
211211
$boardOwner = $this->getBoard()->getOwner();
212212
$card->setOwner($this->mapOwner(is_string($boardOwner) ? $boardOwner : $boardOwner->getUID()));
213213
$card->setDuedate($cardSource->duedate);
214+
$card->setDone($cardSource->done ?? null);
214215
$cards[$cardSource->id] = $card;
215216
}
216217
return $cards;

tests/data/deck.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
},
101101
"order": 999,
102102
"archived": false,
103+
"done": "2023-07-18T10:00:00+00:00",
103104
"duedate": "2050-07-24T22:00:00+00:00",
104105
"deletedAt": 0,
105106
"commentsUnread": 0,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
84323
1+
84627

tests/integration/import/ImportExportTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ public function assertDatabase(string $owner = 'admin') {
328328
'lastModified' => 1689667779,
329329
'createdAt' => 1689667569,
330330
'owner' => $owner,
331+
'done' => new \DateTime('2023-07-18T10:00:00+00:00'),
331332
'duedate' => new \DateTime('2050-07-24T22:00:00.000000+0000'),
332333
'order' => 999,
333334
'stackId' => $stacks[0]->getId(),

tests/unit/Service/Importer/Systems/DeckJsonServiceTest.php

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
namespace OCA\Deck\Service\Importer\Systems;
2525

2626
use OCA\Deck\Service\Importer\BoardImportService;
27-
use OCP\IL10N;
28-
use OCP\IURLGenerator;
2927
use OCP\IUser;
3028
use OCP\IUserManager;
3129
use OCP\Server;
@@ -36,20 +34,12 @@
3634
*/
3735
class DeckJsonServiceTest extends \Test\TestCase {
3836
private DeckJsonService $service;
39-
/** @var IURLGenerator|MockObject */
40-
private $urlGenerator;
4137
/** @var IUserManager|MockObject */
4238
private $userManager;
43-
/** @var IL10N */
44-
private $l10n;
4539
public function setUp(): void {
4640
$this->userManager = $this->createMock(IUserManager::class);
47-
$this->urlGenerator = $this->createMock(IURLGenerator::class);
48-
$this->l10n = $this->createMock(IL10N::class);
4941
$this->service = new DeckJsonService(
5042
$this->userManager,
51-
$this->urlGenerator,
52-
$this->l10n
5343
);
5444
}
5545

@@ -61,6 +51,59 @@ public function testGetBoardWithNoName() {
6151
}
6252

6353
public function testGetBoardWithSuccess() {
54+
$importService = $this->setUpImportService();
55+
56+
$boards = $this->service->getBoards();
57+
$importService->setData($boards[0]);
58+
$actual = $this->service->getBoard();
59+
$this->assertEquals('My test board', $actual->getTitle());
60+
$this->assertEquals('admin', $actual->getOwner());
61+
$this->assertEquals('e0ed31', $actual->getColor());
62+
}
63+
64+
public function testGetCards() {
65+
$importService = $this->setUpImportService();
66+
67+
$boards = $this->service->getBoards();
68+
$importService->setData($boards[0]);
69+
70+
$importService->getBoard()->setId(1);
71+
72+
$this->service->getLabels();
73+
74+
$stacks = $this->service->getStacks();
75+
$stackId = 1;
76+
foreach ($stacks as $code => $stack) {
77+
$stack->setId($stackId++);
78+
$this->service->updateStack($code, $stack);
79+
}
80+
81+
$cards = $this->service->getCards();
82+
83+
$this->assertCount(6, $cards);
84+
85+
// Card 114 (title "1") has a done value set in the fixture
86+
$card114 = $cards[114];
87+
$this->assertEquals('1', $card114->getTitle());
88+
$this->assertInstanceOf(\DateTime::class, $card114->getDone());
89+
$this->assertEquals('2023-07-18T10:00:00+00:00', $card114->getDone()->format(\DateTime::ATOM));
90+
$this->assertEquals('2050-07-24T22:00:00+00:00', $card114->getDuedate()->format(\DateTime::ATOM));
91+
$this->assertFalse($card114->getArchived());
92+
$this->assertEquals('admin', $card114->getOwner());
93+
94+
// Card 115 (title "2") has no done value in the fixture
95+
$card115 = $cards[115];
96+
$this->assertEquals('2', $card115->getTitle());
97+
$this->assertNull($card115->getDone());
98+
99+
// Card 119 (title "6") — from stack B, no done value
100+
$card119 = $cards[119];
101+
$this->assertEquals('6', $card119->getTitle());
102+
$this->assertNull($card119->getDone());
103+
$this->assertEquals('# Test description' . "\n\n" . 'Hello world', $card119->getDescription());
104+
}
105+
106+
private function setUpImportService(): BoardImportService {
64107
$importService = Server::get(BoardImportService::class);
65108

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

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

80-
$boards = $this->service->getBoards();
81-
$importService->setData($boards[0]);
82-
$actual = $this->service->getBoard();
83-
$this->assertEquals('My test board', $actual->getTitle());
84-
$this->assertEquals('admin', $actual->getOwner());
85-
$this->assertEquals('e0ed31', $actual->getColor());
123+
return $importService;
86124
}
87125
}

0 commit comments

Comments
 (0)