test that nonexistant text will throw error
This commit is contained in:
parent
c32087c35d
commit
f8a1c2616d
2 changed files with 17 additions and 6 deletions
|
|
@ -49,6 +49,9 @@ class CreatePlan
|
||||||
}
|
}
|
||||||
$textId = $request->textId;
|
$textId = $request->textId;
|
||||||
$text = $this->textRepo->find($textId);
|
$text = $this->textRepo->find($textId);
|
||||||
|
if ($text === null) {
|
||||||
|
throw new DomainException("Text with id: $textId doesnt exist");
|
||||||
|
}
|
||||||
$nodesOfText = $this->filterForNonParentNodes(
|
$nodesOfText = $this->filterForNonParentNodes(
|
||||||
$this->nodeRepo->findByTextId($textId)
|
$this->nodeRepo->findByTextId($textId)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ class CreatePlanTest extends TestCase
|
||||||
scheduledNodeRepo: $this->scheduledNodeRepo,
|
scheduledNodeRepo: $this->scheduledNodeRepo,
|
||||||
planRepo: $this->planRepo,
|
planRepo: $this->planRepo,
|
||||||
);
|
);
|
||||||
|
$this->textRepo->create(new CreateTextDto('testname'));
|
||||||
$this->useCase = new CreatePlan(
|
$this->useCase = new CreatePlan(
|
||||||
$this->planRepo,
|
$this->planRepo,
|
||||||
$this->userRepo,
|
$this->userRepo,
|
||||||
|
|
@ -83,11 +84,20 @@ class CreatePlanTest extends TestCase
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_nonexistant_text_id_throws(): void
|
||||||
|
{
|
||||||
|
$this->expectException(DomainException::class);
|
||||||
|
$this->expectExceptionMessage("Text with id: 1 doesnt exist");
|
||||||
|
$plan = $this->useCase->execute(new CreatePlanRequest(
|
||||||
|
userId: 0,
|
||||||
|
name: 'testPlan',
|
||||||
|
textId: 1,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public function test_plan_schedules_nodes_on_creation(): void
|
public function test_plan_schedules_nodes_on_creation(): void
|
||||||
{
|
{
|
||||||
$text = $this->textRepo->create(new CreateTextDto(
|
$text = $this->textRepo->find(0);
|
||||||
name: 'testname',
|
|
||||||
));
|
|
||||||
$this->nodeRepo->create(new CreateNodeDto(
|
$this->nodeRepo->create(new CreateNodeDto(
|
||||||
text: $text,
|
text: $text,
|
||||||
title: 'testtitle',
|
title: 'testtitle',
|
||||||
|
|
@ -103,9 +113,7 @@ class CreatePlanTest extends TestCase
|
||||||
|
|
||||||
public function test_plan_only_schedules_nodes_which_arent_parents(): void
|
public function test_plan_only_schedules_nodes_which_arent_parents(): void
|
||||||
{
|
{
|
||||||
$text = $this->textRepo->create(new CreateTextDto(
|
$text = $this->textRepo->find(0);
|
||||||
name: 'testname',
|
|
||||||
));
|
|
||||||
$rootNode = $this->nodeRepo->create(new CreateNodeDto(
|
$rootNode = $this->nodeRepo->create(new CreateNodeDto(
|
||||||
text: $text,
|
text: $text,
|
||||||
title: 'root node',
|
title: 'root node',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue