From a752ff9ba5b8173ac262270f4adc7096fc632002 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Thu, 23 Apr 2026 20:44:14 +0300 Subject: [PATCH] add start and end date and test for null entries --- app/Plan/UseCases/CreatePlan.php | 8 ++++ app/Plan/UseCases/CreatePlanRequest.php | 2 + tests/Unit/Plan/UseCases/CreatePlanTest.php | 46 +++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/app/Plan/UseCases/CreatePlan.php b/app/Plan/UseCases/CreatePlan.php index 0d0124c..7bad774 100644 --- a/app/Plan/UseCases/CreatePlan.php +++ b/app/Plan/UseCases/CreatePlan.php @@ -42,6 +42,14 @@ class CreatePlan throw new BadRequestException('name is required'); } + if ($request->dateStart === null) { + throw new BadRequestException('date start is required'); + } + + if ($request->dateEnd === null) { + throw new BadRequestException('date end is required'); + } + $userId = $request->userId; $user = $this->userRepo->find($userId); if ($user === null) { diff --git a/app/Plan/UseCases/CreatePlanRequest.php b/app/Plan/UseCases/CreatePlanRequest.php index d9e0669..300a7a9 100644 --- a/app/Plan/UseCases/CreatePlanRequest.php +++ b/app/Plan/UseCases/CreatePlanRequest.php @@ -8,5 +8,7 @@ class CreatePlanRequest public ?int $userId, public ?int $textId, public ?string $name, + public ?string $dateStart, + public ?string $dateEnd, ) {} } diff --git a/tests/Unit/Plan/UseCases/CreatePlanTest.php b/tests/Unit/Plan/UseCases/CreatePlanTest.php index cccc4ea..0cdad79 100644 --- a/tests/Unit/Plan/UseCases/CreatePlanTest.php +++ b/tests/Unit/Plan/UseCases/CreatePlanTest.php @@ -59,6 +59,8 @@ class CreatePlanTest extends TestCase userId: 0, name: 'testPlan', textId: 0, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', )); $this->assertEquals('testPlan', $plan->getName()); } @@ -69,6 +71,8 @@ class CreatePlanTest extends TestCase userId: 0, name: 'testPlan', textId: 0, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', )); $this->assertInstanceOf(User::class, $plan->getUser()); } @@ -81,6 +85,8 @@ class CreatePlanTest extends TestCase userId: 1, name: 'testPlan', textId: 0, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', )); } @@ -92,6 +98,8 @@ class CreatePlanTest extends TestCase userId: 0, name: 'testPlan', textId: 1, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', )); } @@ -107,6 +115,8 @@ class CreatePlanTest extends TestCase userId: 0, name: 'testPlan', textId: 0, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', )); $this->assertNotNull($this->scheduledNodeRepo->find(0)); } @@ -128,6 +138,8 @@ class CreatePlanTest extends TestCase userId: 0, name: 'testPlan', textId: 0, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', )); $this->assertEquals( 1, @@ -144,6 +156,8 @@ class CreatePlanTest extends TestCase userId: null, name: 'testPlan', textId: 0, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', )); } @@ -156,6 +170,8 @@ class CreatePlanTest extends TestCase userId: 0, name: 'testPlan', textId: null, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', )); } @@ -168,6 +184,36 @@ class CreatePlanTest extends TestCase userId: 0, name: null, textId: 0, + dateStart: '2025-01-01', + dateEnd: '2025-01-01', + )); + } + + public function test_throws_if_date_start_is_null(): void + { + $this->expectException(BadRequestException::class); + $this->expectExceptionMessage('date start is required'); + + $this->useCase->execute(new CreatePlanRequest( + userId: 0, + name: 'test', + textId: 0, + dateStart: null, + dateEnd: '2025-01-01', + )); + } + + public function test_throws_if_date_end_is_null(): void + { + $this->expectException(BadRequestException::class); + $this->expectExceptionMessage('date end is required'); + + $this->useCase->execute(new CreatePlanRequest( + userId: 0, + name: 'test', + textId: 0, + dateStart: '2025-01-01', + dateEnd: null, )); } }