add start and end date and test for null entries

This commit is contained in:
Yisroel Baum 2026-04-23 20:44:14 +03:00
parent f8a1c2616d
commit a752ff9ba5
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 56 additions and 0 deletions

View file

@ -42,6 +42,14 @@ class CreatePlan
throw new BadRequestException('name is required'); 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; $userId = $request->userId;
$user = $this->userRepo->find($userId); $user = $this->userRepo->find($userId);
if ($user === null) { if ($user === null) {

View file

@ -8,5 +8,7 @@ class CreatePlanRequest
public ?int $userId, public ?int $userId,
public ?int $textId, public ?int $textId,
public ?string $name, public ?string $name,
public ?string $dateStart,
public ?string $dateEnd,
) {} ) {}
} }

View file

@ -59,6 +59,8 @@ class CreatePlanTest extends TestCase
userId: 0, userId: 0,
name: 'testPlan', name: 'testPlan',
textId: 0, textId: 0,
dateStart: '2025-01-01',
dateEnd: '2025-01-01',
)); ));
$this->assertEquals('testPlan', $plan->getName()); $this->assertEquals('testPlan', $plan->getName());
} }
@ -69,6 +71,8 @@ class CreatePlanTest extends TestCase
userId: 0, userId: 0,
name: 'testPlan', name: 'testPlan',
textId: 0, textId: 0,
dateStart: '2025-01-01',
dateEnd: '2025-01-01',
)); ));
$this->assertInstanceOf(User::class, $plan->getUser()); $this->assertInstanceOf(User::class, $plan->getUser());
} }
@ -81,6 +85,8 @@ class CreatePlanTest extends TestCase
userId: 1, userId: 1,
name: 'testPlan', name: 'testPlan',
textId: 0, textId: 0,
dateStart: '2025-01-01',
dateEnd: '2025-01-01',
)); ));
} }
@ -92,6 +98,8 @@ class CreatePlanTest extends TestCase
userId: 0, userId: 0,
name: 'testPlan', name: 'testPlan',
textId: 1, textId: 1,
dateStart: '2025-01-01',
dateEnd: '2025-01-01',
)); ));
} }
@ -107,6 +115,8 @@ class CreatePlanTest extends TestCase
userId: 0, userId: 0,
name: 'testPlan', name: 'testPlan',
textId: 0, textId: 0,
dateStart: '2025-01-01',
dateEnd: '2025-01-01',
)); ));
$this->assertNotNull($this->scheduledNodeRepo->find(0)); $this->assertNotNull($this->scheduledNodeRepo->find(0));
} }
@ -128,6 +138,8 @@ class CreatePlanTest extends TestCase
userId: 0, userId: 0,
name: 'testPlan', name: 'testPlan',
textId: 0, textId: 0,
dateStart: '2025-01-01',
dateEnd: '2025-01-01',
)); ));
$this->assertEquals( $this->assertEquals(
1, 1,
@ -144,6 +156,8 @@ class CreatePlanTest extends TestCase
userId: null, userId: null,
name: 'testPlan', name: 'testPlan',
textId: 0, textId: 0,
dateStart: '2025-01-01',
dateEnd: '2025-01-01',
)); ));
} }
@ -156,6 +170,8 @@ class CreatePlanTest extends TestCase
userId: 0, userId: 0,
name: 'testPlan', name: 'testPlan',
textId: null, textId: null,
dateStart: '2025-01-01',
dateEnd: '2025-01-01',
)); ));
} }
@ -168,6 +184,36 @@ class CreatePlanTest extends TestCase
userId: 0, userId: 0,
name: null, name: null,
textId: 0, 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,
)); ));
} }
} }