Skip to content

Commit

Permalink
fix: skip exporting a deleted card
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Feb 4, 2025
1 parent 8597c84 commit 1b642c2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 10 deletions.
7 changes: 7 additions & 0 deletions lib/Command/UserExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$data = [];
foreach ($boards as $board) {
if ($board->getDeletedAt() > 0) {
continue;
}
$fullBoard = $this->boardMapper->find($board->getId(), true, true);
$data[$board->getId()] = $fullBoard->jsonSerialize();
$stacks = $this->stackMapper->findAll($board->getId());
foreach ($stacks as $stack) {
$data[$board->getId()]['stacks'][$stack->getId()] = $stack->jsonSerialize();
$cards = $this->cardMapper->findAllByStack($stack->getId());
foreach ($cards as $card) {
if ($card->getDeletedAt() > 0) {
continue;
}
$fullCard = $this->cardMapper->find($card->getId());

$assignedUsers = $this->assignedUsersMapper->findAll($card->getId());
$fullCard->setAssignedUsers($assignedUsers);

Expand Down
83 changes: 73 additions & 10 deletions tests/unit/Command/UserExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,26 @@ public function getBoard($id) {
$board->setTitle('Board ' . $id);
return $board;
}

public function getStack($id) {
$stack = new Stack();
$stack->setId($id);
$stack->setTitle('Stack ' . $id);
return $stack;
}
public function getCard($id) {

public function getCard($id, $deleted = false) {
$card = new Card();
$card->setId($id);
$card->setTitle('Card ' . $id);

if ($deleted) {
$card->setDeletedAt(time());
}

return $card;
}

public function testExecute() {
$input = $this->createMock(InputInterface::class);
$input->expects($this->once())->method('getArgument')->with('user-id')->willReturn('admin');
Expand All @@ -89,33 +97,88 @@ public function testExecute() {
$this->getBoard(1),
$this->getBoard(2),
];
$this->boardService->expects($this->once())
->method('findAll')
->willReturn($boards);
$this->boardMapper->expects($this->exactly(count($boards)))
->method('find')
->willReturn($boards[0]);

$stacks = [
$this->getStack(1),
$this->getStack(2)
];
$this->stackMapper->expects($this->exactly(count($boards)))
->method('findAll')
->willReturn($stacks);

$cards = [
$this->getCard(1),
$this->getCard(2),
$this->getCard(3),
];

$this->boardService->expects($this->once())
->method('findAll')
->willReturn($boards);

$this->boardMapper->expects($this->exactly(count($boards)))
->method('find')
->willReturn($boards[0]);

$this->stackMapper->expects($this->exactly(count($boards)))
->method('findAll')
->willReturn($stacks);

$this->cardMapper->expects($this->exactly(count($boards) * count($stacks)))
->method('findAllByStack')
->willReturn($cards);

$this->cardMapper->expects($this->exactly(count($boards) * count($stacks) * count($cards)))
->method('find')
->willReturn($cards[0]);

$this->assignedUserMapper->expects($this->exactly(count($boards) * count($stacks) * count($cards)))
->method('findAll')
->willReturn([]);

$result = $this->invokePrivate($this->userExport, 'execute', [$input, $output]);
self::assertEquals(0, $result);
}

public function testExecuteWithDeletedCard() {
$input = $this->createMock(InputInterface::class);
$input->expects($this->once())->method('getArgument')->with('user-id')->willReturn('admin');
$output = $this->createMock(OutputInterface::class);

$boards = [
$this->getBoard(1),
];

$stacks = [
$this->getStack(1),
];

$cards = [
$this->getCard(1),
$this->getCard(2, true),
];

$this->boardService->expects($this->once())
->method('findAll')
->willReturn($boards);

$this->boardMapper->expects($this->once())
->method('find')
->willReturn($boards[0]);

$this->stackMapper->expects($this->once())
->method('findAll')
->willReturn($stacks);

$this->cardMapper->expects($this->once())
->method('findAllByStack')
->willReturn($cards);

$this->cardMapper->expects($this->once())
->method('find')
->willReturn($cards[0]);

$this->assignedUserMapper->expects($this->once())
->method('findAll')
->willReturn([]);

$result = $this->invokePrivate($this->userExport, 'execute', [$input, $output]);
self::assertEquals(0, $result);
}
Expand Down

0 comments on commit 1b642c2

Please sign in to comment.