Skip to content

Commit

Permalink
Merge pull request #4489 from nextcloud/tests/4483
Browse files Browse the repository at this point in the history
tests(integration): Add integration tests for due dates
  • Loading branch information
juliushaertl committed Apr 4, 2023
2 parents c1a16c9 + b79566d commit d067ac8
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
8 changes: 7 additions & 1 deletion lib/Service/CardService.php
Expand Up @@ -39,6 +39,7 @@
use OCA\Deck\Event\CardCreatedEvent;
use OCA\Deck\Event\CardDeletedEvent;
use OCA\Deck\Event\CardUpdatedEvent;
use OCA\Deck\Model\CardDetails;
use OCA\Deck\NoPermissionException;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\Db\BoardMapper;
Expand Down Expand Up @@ -155,7 +156,12 @@ public function enrichCards($cards) {
$card->setAssignedUsers($cardAssignedUsers);
}

return $cards;
return array_map(
function (Card $card): CardDetails {
return new CardDetails($card);
},
$cards
);
}
public function fetchDeleted($boardId) {
$this->cardServiceValidator->check(compact('boardId'));
Expand Down
10 changes: 1 addition & 9 deletions lib/Service/StackService.php
Expand Up @@ -99,15 +99,7 @@ private function enrichStackWithCards($stack, $since = -1) {
return;
}

$this->cardService->enrichCards($cards);
$cards = array_map(
function (Card $card): CardDetails {
return new CardDetails($card);
},
$cards
);

$stack->setCards($cards);
$stack->setCards($this->cardService->enrichCards($cards));
}

private function enrichStacksWithCards($stacks, $since = -1) {
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/features/bootstrap/BoardContext.php
Expand Up @@ -219,6 +219,17 @@ public function setCardAttribute($attribute, $value) {
$this->card = json_decode((string)$this->getResponse()->getBody(), true);
}

/**
* @Given /^get the card details$/
*/
public function getCard() {
$this->requestContext->sendJSONrequest('GET', '/index.php/apps/deck/cards/' . $this->card['id'], array_merge(
$this->card
));
$this->requestContext->getResponse()->getBody()->seek(0);
$this->card = json_decode((string)$this->getResponse()->getBody(), true);
}

/**
* @Given /^set the card duedate to "([^"]*)"$/
*/
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/features/decks.feature
Expand Up @@ -32,3 +32,29 @@ Feature: decks
And creates a board named "MyBoard" with color "000000"
And create a stack named "ToDo"
When create a card named "This is a very ong name that exceeds the maximum length of a deck board created which is longer than 255 characters This is a very ong name that exceeds the maximum length of a deck board created which is longer than 255 characters This is a very ong name that exceeds the maximum length of a deck board created which is longer than 255 characters"

Scenario: Setting a duedate on a card
Given acting as user "user0"
And creates a board named "MyBoard" with color "000000"
And create a stack named "ToDo"
And create a card named "Overdue task"
When get the card details
And the response should be a JSON array with the following mandatory values
|key|value|
|title|Overdue task|
|duedate||
|overdue|0|
And set the card attribute "duedate" to "2020-12-12 13:37:00"
When get the card details
And the response should be a JSON array with the following mandatory values
|key|value|
|title|Overdue task|
|duedate|2020-12-12T13:37:00+00:00|
|overdue|3|
And set the card attribute "duedate" to ""
When get the card details
And the response should be a JSON array with the following mandatory values
|key|value|
|title|Overdue task|
|duedate||
|overdue|0|
6 changes: 5 additions & 1 deletion tests/unit/Service/CardServiceTest.php
Expand Up @@ -34,6 +34,7 @@
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Model\CardDetails;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\StatusException;
use OCA\Deck\Validators\CardServiceValidator;
Expand Down Expand Up @@ -188,7 +189,10 @@ public function testFind() {
$cardExpected->setRelatedBoard($boardMock);
$cardExpected->setRelatedStack($stackMock);
$cardExpected->setLabels([]);
$this->assertEquals($cardExpected, $this->cardService->find(123));
$expected = new CardDetails($cardExpected);

$actual = $this->cardService->find(123);
$this->assertEquals($expected->jsonSerialize(), $actual->jsonSerialize());
}

public function testCreate() {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/Service/Importer/Systems/TrelloJsonServiceTest.php
Expand Up @@ -76,7 +76,7 @@ public function testValidateUsersWithInvalidUser() {
}

public function testValidateUsersWithNotStringNextcloud() {
$this->expectErrorMessage('User on setting uidRelation is invalid');
$this->expectExceptionMessage('User on setting uidRelation is invalid');
$importService = $this->createMock(BoardImportService::class);
$importService
->method('getConfig')
Expand All @@ -92,7 +92,7 @@ public function testValidateUsersWithNotStringNextcloud() {
}

public function testValidateUsersWithNotFoundUser() {
$this->expectErrorMessage('User on setting uidRelation not found: nextcloud_user');
$this->expectExceptionMessage('User on setting uidRelation not found: nextcloud_user');
$importService = $this->createMock(BoardImportService::class);
$importService
->method('getConfig')
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testValidateUsersWithValidUsers() {
}

public function testGetBoardWithNoName() {
$this->expectErrorMessage('Invalid name of board');
$this->expectExceptionMessage('Invalid name of board');
$importService = $this->createMock(BoardImportService::class);
$this->service->setImportService($importService);
$this->service->getBoard();
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Service/StackServiceTest.php
Expand Up @@ -33,6 +33,7 @@
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Model\CardDetails;
use OCA\Deck\Validators\StackServiceValidator;
use OCP\EventDispatcher\IEventDispatcher;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -121,6 +122,9 @@ function ($cards) {
foreach ($cards as $card) {
$card->setLabels($this->getLabels()[$card->getId()]);
}
return array_map(function ($card) {
return new CardDetails($card);
}, $cards);
}
)
);
Expand Down

0 comments on commit d067ac8

Please sign in to comment.