Skip to content

Commit

Permalink
feat(tests): add tests for labelService and cardService functions
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <[email protected]>
  • Loading branch information
grnd-alt committed Nov 14, 2024
1 parent ef9358b commit 3045c71
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/unit/Service/CardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
Expand Down Expand Up @@ -223,6 +224,61 @@ public function testCreate() {
$this->assertEquals($b->getStackId(), 123);
}

public function testClone() {
$card = new Card();
$card->setId(1);
$card->setTitle('Card title');
$card->setOwner('admin');
$card->setStackId(12345);
$clonedCard = clone $card;
$clonedCard->setId(2);
$clonedCard->setStackId(1234);
$this->cardMapper->expects($this->exactly(2))
->method('insert')
->willReturn($card, $clonedCard);

$this->cardMapper->expects($this->once())
->method('update')->willReturn($clonedCard);
$this->cardMapper->expects($this->exactly(2))
->method('find')
->willReturn($card, $clonedCard);

// check if users are assigned
$this->assignmentService->expects($this->once())
->method('assignUser')
->with(2, 'admin');
$a1 = new Assignment();
$a1->setCardId(2);
$a1->setType(0);
$a1->setParticipant('admin');
$this->assignedUsersMapper->expects($this->once())
->method('findAll')
->with(1)
->willReturn([$a1]);

// check if labels get cloned
$label = new Label();
$label->setId(1);
$this->labelMapper->expects($this->once())
->method('findAssignedLabelsForCard')
->willReturn([$label]);
$this->cardMapper->expects($this->once())
->method('assignLabel')
->with($clonedCard->getId(), $label->getId())
->willReturn($label);

$stackMock = new Stack();
$stackMock->setBoardId(1234);
$this->stackMapper->expects($this->once())
->method('find')
->willReturn($stackMock);
$b = $this->cardService->create('Card title', 123, 'text', 999, 'admin');
$c = $this->cardService->cloneCard($b->getId(), 1234);
$this->assertEquals($b->getTitle(), $c->getTitle());
$this->assertEquals($b->getOwner(), $c->getOwner());
$this->assertNotEquals($b->getStackId(), $c->getStackId());
}

public function testDelete() {
$cardToBeDeleted = new Card();
$this->cardMapper->expects($this->once())
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/Service/LabelServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Deck\Service;

use OCA\Deck\Db\Board;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
Expand Down Expand Up @@ -104,6 +105,53 @@ public function testUpdate() {
$this->assertEquals($b->getColor(), 'ffffff');
}

public function testCloneLabelIfNotExists() {
$label = new Label();
$label->setId(1);
$label->setTitle('title');
$label->setColor('00ff00');
$this->labelMapper->expects($this->once())
->method('find')
->willReturn($label);

$expectedLabel = new Label();
$expectedLabel->setTitle('title');
$expectedLabel->setColor('00ff00');
$expectedLabel->setBoardId(1);
$this->labelMapper->expects($this->once())
->method('insert')
->with($expectedLabel)
->willReturn($label);
$board = new Board();
$board->setLabels([]);
$this->boardService->expects($this->once())
->method('find')
->willReturn($board);

$this->labelService->cloneLabelIfNotExists(1, 1);
}

public function testCloneLabelIfExists() {
$label = new Label();
$label->setId(1);
$label->setTitle('title');
$label->setColor('00ff00');
$this->labelMapper->expects($this->once())
->method('find')
->willReturn($label);
$this->labelMapper->expects($this->never())
->method('insert')
->with($label);
$board = new Board();
$board->setLabels([$label]);
$this->boardService->expects($this->once())
->method('find')
->willReturn($board);

$this->labelService->cloneLabelIfNotExists(1, 1);

}

public function testDelete() {
$label = new Label();
$label->setId(1);
Expand Down

0 comments on commit 3045c71

Please sign in to comment.