From 844813499ac1accbb2937255e1e61bdeff30cb15 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sat, 21 Mar 2026 20:00:14 +0200 Subject: [PATCH] test that only nodes which are not parents are scheduled --- tests/Fakes/FakeScheduledNodeRepository.php | 8 +++++++ tests/Unit/Plan/UseCases/CreatePlanTest.php | 25 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/Fakes/FakeScheduledNodeRepository.php b/tests/Fakes/FakeScheduledNodeRepository.php index f1ce59d..4241813 100644 --- a/tests/Fakes/FakeScheduledNodeRepository.php +++ b/tests/Fakes/FakeScheduledNodeRepository.php @@ -10,8 +10,11 @@ class FakeScheduledNodeRepository implements ScheduledNodeRepository { private array $existingScheduledNodes = []; + private int $numberOfTimesCreateCalled = 0; + public function create(CreateScheduledNodeDto $dto): ScheduledNode { + $this->numberOfTimesCreateCalled++; $id = $this->nextId(); $scheduledNode = new ScheduledNode( id: $id, @@ -33,6 +36,11 @@ class FakeScheduledNodeRepository implements ScheduledNodeRepository ); } + public function getNumberOfTimesCreateCalled(): int + { + return $this->numberOfTimesCreateCalled; + } + private function nextId(): int { return count($this->existingScheduledNodes); diff --git a/tests/Unit/Plan/UseCases/CreatePlanTest.php b/tests/Unit/Plan/UseCases/CreatePlanTest.php index 27e5eeb..a5bdf02 100644 --- a/tests/Unit/Plan/UseCases/CreatePlanTest.php +++ b/tests/Unit/Plan/UseCases/CreatePlanTest.php @@ -99,4 +99,29 @@ class CreatePlanTest extends TestCase )); $this->assertNotNull($this->scheduledNodeRepo->find(0)); } + + public function test_plan_only_schedules_nodes_which_arent_parents(): void + { + $text = $this->textRepo->create(new CreateTextDto( + name: 'testname', + )); + $rootNode = $this->nodeRepo->create(new CreateNodeDto( + text: $text, + title: 'root node', + parentNode: null, + )); + $this->nodeRepo->create(new CreateNodeDto( + text: $text, + title: 'child node', + parentNode: $rootNode, + )); + $plan = $this->useCase->execute(new CreatePlanRequest( + userId: 0, + name: 'testPlan', + textId: 0, + )); + $this->assertEquals( + 1, $this->scheduledNodeRepo->getNumberOfTimesCreateCalled() + ); + } }