From 4bf0f33234d0366b48a22347ecb207069b340e71 Mon Sep 17 00:00:00 2001 From: Elizabeth Danzberger Date: Fri, 24 Jan 2025 14:01:34 -0500 Subject: [PATCH] fix: skip exporting a deleted card Signed-off-by: Elizabeth Danzberger --- lib/Command/UserExport.php | 6 +- tests/unit/Command/UserExportTest.php | 96 ++++++++++++++++++++++++--- 2 files changed, 90 insertions(+), 12 deletions(-) diff --git a/lib/Command/UserExport.php b/lib/Command/UserExport.php index fc65d81f8..02dd2e288 100644 --- a/lib/Command/UserExport.php +++ b/lib/Command/UserExport.php @@ -61,6 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($board->getDeletedAt() > 0) { continue; } + $fullBoard = $this->boardMapper->find($board->getId(), true, true); $data[$board->getId()] = $fullBoard->jsonSerialize(); $stacks = $this->stackMapper->findAll($board->getId()); @@ -68,13 +69,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $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); $cardDetails = new CardDetails($fullCard, $fullBoard); $comments = $this->commentService->list($card->getId()); - $cardDetails->setCommentsCount(count($comments->getData())); $cardJson = $cardDetails->jsonSerialize(); diff --git a/tests/unit/Command/UserExportTest.php b/tests/unit/Command/UserExportTest.php index 80907ca72..efc6e77a1 100644 --- a/tests/unit/Command/UserExportTest.php +++ b/tests/unit/Command/UserExportTest.php @@ -73,16 +73,23 @@ 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; } @@ -92,6 +99,7 @@ public function getComment($id) { $comment->setMessage("fake comment" . $id); return $comment; } + public function testExecute() { $input = $this->createMock(InputInterface::class); $input->expects($this->once())->method('getArgument')->with('user-id')->willReturn('admin'); @@ -101,19 +109,12 @@ 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), @@ -125,16 +126,89 @@ public function testExecute() { $this->getComment(2), $this->getComment(3), ]; - $this->commentService->expects($this->exactly(count($cards) * count($stacks) * count($boards)))->method('list')->willReturn(new DataResponse($comments)); + + $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->commentService->expects($this->exactly(count($cards) * count($stacks) * count($boards))) + ->method('list') + ->willReturn(new DataResponse($comments)); + $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), + ]; + + $comments = [ + $this->getComment(1), + ]; + + $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->commentService->expects($this->exactly(count($stacks) * count($boards))) + ->method('list') + ->willReturn(new DataResponse($comments)); + + $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); }