test for date end being before date start

This commit is contained in:
Yisroel Baum 2026-04-23 20:50:26 +03:00
parent a752ff9ba5
commit 858f2e075f
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 21 additions and 0 deletions

View file

@ -50,6 +50,13 @@ class CreatePlan
throw new BadRequestException('date end is required');
}
$startDate = new DateTimeImmutable($request->dateStart);
$endDate = new DateTimeImmutable($request->dateEnd);
if ($endDate < $startDate) {
throw new BadRequestException('date end cannot be before date start');
}
$userId = $request->userId;
$user = $this->userRepo->find($userId);
if ($user === null) {

View file

@ -216,4 +216,18 @@ class CreatePlanTest extends TestCase
dateEnd: null,
));
}
public function test_throws_if_date_end_is_before_date_start(): void
{
$this->expectException(BadRequestException::class);
$this->expectExceptionMessage('date end cannot be before date start');
$this->useCase->execute(new CreatePlanRequest(
userId: 0,
name: 'test',
textId: 0,
dateStart: '2025-01-02',
dateEnd: '2025-01-01',
));
}
}