diff --git a/app/ScheduledNode/UseCases/GetTodaysSchedule.php b/app/ScheduledNode/UseCases/GetTodaysSchedule.php new file mode 100644 index 0000000..1745fd3 --- /dev/null +++ b/app/ScheduledNode/UseCases/GetTodaysSchedule.php @@ -0,0 +1,35 @@ +date); + $userId = $request->userId; + $user = $this->userRepo->find($userId); + $scheduledNodes = $this->scheduledNodeRepo->findByUser($user); + + return array_filter( + $scheduledNodes, + function (ScheduledNode $node) use ($date) { + return $node->getDate()->format('Y-m-d') + === $date->format('Y-m-d'); + } + ); + } +} diff --git a/app/ScheduledNode/UseCases/GetTodaysScheduleRequest.php b/app/ScheduledNode/UseCases/GetTodaysScheduleRequest.php new file mode 100644 index 0000000..ccb38b8 --- /dev/null +++ b/app/ScheduledNode/UseCases/GetTodaysScheduleRequest.php @@ -0,0 +1,11 @@ +userRepo = new FakeUserRepository; + $this->scheduledNodeRepo = new FakeScheduledNodeRepository; + $this->planRepo = new FakePlanRepository; + $user = $this->userRepo->create(new CreateUserDto( + email: new EmailAddress('email@email.com'), + passwordHash: 'hash', + isAdmin: false, + )); + $plan = $this->planRepo->create(new CreatePlanDto( + name: 'test plan', + user: $user, + )); + $this->scheduledNodeRepo->create(new CreateScheduledNodeDto( + date: new DateTimeImmutable('2025-01-01'), + plan: $plan, + node: new Node( + id: 0, + title: 'test node', + text: new Text(id: 0, name: 'test text'), + parentNode: null, + ), + )); + + $this->useCase = new GetTodaysSchedule( + userRepo: $this->userRepo, + scheduledNodeRepo: $this->scheduledNodeRepo, + ); + } + + public function test_returns_array_of_scheduled_nodes(): void + { + $result = $this->useCase->execute(new GetTodaysScheduleRequest( + date: '2025-01-01', + userId: 0, + )); + + $this->assertIsArray($result); + $this->assertInstanceOf(ScheduledNode::class, $result[0]); + } +}