test for date end being before date start
This commit is contained in:
parent
a752ff9ba5
commit
858f2e075f
2 changed files with 21 additions and 0 deletions
|
|
@ -50,6 +50,13 @@ class CreatePlan
|
||||||
throw new BadRequestException('date end is required');
|
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;
|
$userId = $request->userId;
|
||||||
$user = $this->userRepo->find($userId);
|
$user = $this->userRepo->find($userId);
|
||||||
if ($user === null) {
|
if ($user === null) {
|
||||||
|
|
|
||||||
|
|
@ -216,4 +216,18 @@ class CreatePlanTest extends TestCase
|
||||||
dateEnd: null,
|
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',
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue