test that nonexistant text will throw error

This commit is contained in:
Yisroel Baum 2026-04-23 20:20:53 +03:00
parent c32087c35d
commit f8a1c2616d
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 17 additions and 6 deletions

View file

@ -49,6 +49,9 @@ class CreatePlan
}
$textId = $request->textId;
$text = $this->textRepo->find($textId);
if ($text === null) {
throw new DomainException("Text with id: $textId doesnt exist");
}
$nodesOfText = $this->filterForNonParentNodes(
$this->nodeRepo->findByTextId($textId)
);

View file

@ -43,6 +43,7 @@ class CreatePlanTest extends TestCase
scheduledNodeRepo: $this->scheduledNodeRepo,
planRepo: $this->planRepo,
);
$this->textRepo->create(new CreateTextDto('testname'));
$this->useCase = new CreatePlan(
$this->planRepo,
$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
{
$text = $this->textRepo->create(new CreateTextDto(
name: 'testname',
));
$text = $this->textRepo->find(0);
$this->nodeRepo->create(new CreateNodeDto(
text: $text,
title: 'testtitle',
@ -103,9 +113,7 @@ class CreatePlanTest extends TestCase
public function test_plan_only_schedules_nodes_which_arent_parents(): void
{
$text = $this->textRepo->create(new CreateTextDto(
name: 'testname',
));
$text = $this->textRepo->find(0);
$rootNode = $this->nodeRepo->create(new CreateNodeDto(
text: $text,
title: 'root node',