test nonexistant parent node id throws exception

This commit is contained in:
Yisroel Baum 2026-02-21 22:23:30 +02:00
parent 021a2a6f15
commit 143a4ffe39
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 20 additions and 4 deletions

View file

@ -17,10 +17,10 @@ class CreateNode
public function execute(CreateNodeRequest $request): Node
{
$id = $request->textId;
$text = $this->textRepo->find($id);
$textId = $request->textId;
$text = $this->textRepo->find($textId);
if ($text === null) {
throw new DomainException("Text with id: $id doesnt exist");
throw new DomainException("Text with id: $textId doesnt exist");
}
if ($request->parentNodeId === null) {
return $this->nodeRepo->create(new CreateNodeDto(
@ -29,7 +29,11 @@ class CreateNode
parentNode: null,
));
}
$parentNode = $this->nodeRepo->find($request->parentNodeId);
$parentNodeId = $request->parentNodeId;
$parentNode = $this->nodeRepo->find($parentNodeId);
if ($parentNode === null) {
throw new DomainException("Node with id: $parentNodeId doesnt exist");
}
return $this->nodeRepo->create(new CreateNodeDto(
text: $text,