Skip to content
Open
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
7 changes: 5 additions & 2 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,11 @@ public function cloneCard(int $id, ?int $targetStackId = null):Card {
}
$this->assignmentService->assignUser($newCard->getId(), $assignement->getParticipant());
}
$newCard->setDescription($originCard->getDescription());
$card = $this->enrichCards([$this->cardMapper->update($newCard)]);

$freshCard = $this->cardMapper->find($newCard->getId());
$freshCard->setDescription($originCard->getDescription());
$card = $this->enrichCards([$this->cardMapper->update($freshCard)]);

return $card[0];
}

Expand Down
36 changes: 8 additions & 28 deletions lib/Service/LabelService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,13 @@

class LabelService {

/** @var LabelMapper */
private $labelMapper;
/** @var PermissionService */
private $permissionService;
/** @var BoardService */
private $boardService;
/** @var ChangeHelper */
private $changeHelper;
/** @var LabelServiceValidator */
private LabelServiceValidator $labelServiceValidator;

public function __construct(
LabelMapper $labelMapper,
PermissionService $permissionService,
BoardService $boardService,
ChangeHelper $changeHelper,
LabelServiceValidator $labelServiceValidator,
private LabelMapper $labelMapper,
private PermissionService $permissionService,
private BoardService $boardService,
private ChangeHelper $changeHelper,
private LabelServiceValidator $labelServiceValidator,
) {
$this->labelMapper = $labelMapper;
$this->permissionService = $permissionService;
$this->boardService = $boardService;
$this->changeHelper = $changeHelper;
$this->labelServiceValidator = $labelServiceValidator;
}

/**
Expand All @@ -59,10 +43,6 @@ public function find($labelId) {
}

/**
* @param $title
* @param $color
* @param $boardId
* @return \OCP\AppFramework\Db\Entity
* @throws StatusException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\DoesNotExistException
Expand Down Expand Up @@ -99,10 +79,10 @@ public function cloneLabelIfNotExists(int $labelId, int $targetBoardId): Label {
$originLabel = $this->find($labelId);
$filteredValues = array_values(array_filter($boardLabels, fn ($item) => $item->getTitle() === $originLabel->getTitle()));
if (empty($filteredValues)) {
$label = $this->create($originLabel->getTitle(), $originLabel->getColor(), $targetBoardId);
return $label;
return $this->create($originLabel->getTitle(), $originLabel->getColor(), $targetBoardId);
}
return $originLabel;

return $filteredValues[0];
}

/**
Expand Down
27 changes: 25 additions & 2 deletions tests/unit/Service/CardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,22 @@ public function testClone() {
$card->setTitle('Card title');
$card->setOwner('admin');
$card->setStackId(12345);
$card->setDescription('A test description');

$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))

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

$this->cardMapper->expects($this->any())
->method('findBoardId')
Expand All @@ -282,6 +286,10 @@ public function testClone() {
->with(1)
->willReturn([$a1]);

$this->assignedUsersMapper->expects($this->any())
->method('findIn')
->willReturn([]);

// check if labels get cloned
$label = new Label();
$label->setId(1);
Expand All @@ -293,16 +301,31 @@ public function testClone() {
->with($clonedCard->getId(), $label->getId())
->willReturn($label);

$labelForClone = Label::fromRow([
'id' => 1,
'boardId' => 1234,
'cardId' => 2,
]);
$this->labelMapper->expects($this->any())
->method('findAssignedLabelsForCards')
->willReturn([$labelForClone]);

$stackMock = new Stack();
$stackMock->setBoardId(1234);
$this->stackMapper->expects($this->any())
->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());

$this->assertEquals('A test description', $c->getDescription());

$this->assertCount(1, $c->getLabels());
$this->assertEquals($label->getId(), $c->getLabels()[0]->getId());
}

public function testDelete() {
Expand Down
Loading