test that error is thrown if plan doesnt exist for creating scheduled node
This commit is contained in:
parent
449df516ae
commit
2affd2a84e
2 changed files with 20 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ use App\Plan\PlanRepository;
|
||||||
use App\ScheduledNode\ScheduledNode;
|
use App\ScheduledNode\ScheduledNode;
|
||||||
use App\ScheduledNode\CreateScheduledNodeDto;
|
use App\ScheduledNode\CreateScheduledNodeDto;
|
||||||
use App\ScheduledNode\ScheduledNodeRepository;
|
use App\ScheduledNode\ScheduledNodeRepository;
|
||||||
|
use DomainException;
|
||||||
|
|
||||||
class CreateScheduledNode
|
class CreateScheduledNode
|
||||||
{
|
{
|
||||||
|
|
@ -17,7 +18,12 @@ class CreateScheduledNode
|
||||||
public function execute(
|
public function execute(
|
||||||
CreateScheduledNodeRequest $request
|
CreateScheduledNodeRequest $request
|
||||||
): ScheduledNode {
|
): ScheduledNode {
|
||||||
$plan = $this->planRepo->find($request->planId);
|
$id = $request->planId;
|
||||||
|
$plan = $this->planRepo->find($id);
|
||||||
|
if ($plan === null) {
|
||||||
|
throw new DomainException("Plan with id: $id doesnt exist");
|
||||||
|
}
|
||||||
|
|
||||||
return $this->scheduledNodeRepo->create(
|
return $this->scheduledNodeRepo->create(
|
||||||
new CreateScheduledNodeDto(
|
new CreateScheduledNodeDto(
|
||||||
date: $request->date,
|
date: $request->date,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use App\ScheduledNode\UseCases\CreateScheduledNodeRequest;
|
||||||
use App\User\User;
|
use App\User\User;
|
||||||
use App\ValueObjects\EmailAddress;
|
use App\ValueObjects\EmailAddress;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use DomainException;
|
||||||
use Tests\Fakes\FakePlanRepository;
|
use Tests\Fakes\FakePlanRepository;
|
||||||
use Tests\Fakes\FakeScheduledNodeRepository;
|
use Tests\Fakes\FakeScheduledNodeRepository;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
@ -62,4 +63,16 @@ class CreateScheduledNodeTest extends TestCase
|
||||||
);
|
);
|
||||||
$this->assertInstanceOf(Plan::class, $scheduledNode->getPlan());
|
$this->assertInstanceOf(Plan::class, $scheduledNode->getPlan());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_nonexistant_plan_throws(): void
|
||||||
|
{
|
||||||
|
$this->expectException(DomainException::class);
|
||||||
|
$this->expectExceptionMessage('Plan with id: 1 doesnt exist');
|
||||||
|
$this->useCase->execute(
|
||||||
|
new CreateScheduledNodeRequest(
|
||||||
|
date: new DateTimeImmutable('now'),
|
||||||
|
planId: 1,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue