test nonexistant parent node id throws exception
This commit is contained in:
parent
021a2a6f15
commit
143a4ffe39
2 changed files with 20 additions and 4 deletions
|
|
@ -17,10 +17,10 @@ class CreateNode
|
||||||
|
|
||||||
public function execute(CreateNodeRequest $request): Node
|
public function execute(CreateNodeRequest $request): Node
|
||||||
{
|
{
|
||||||
$id = $request->textId;
|
$textId = $request->textId;
|
||||||
$text = $this->textRepo->find($id);
|
$text = $this->textRepo->find($textId);
|
||||||
if ($text === null) {
|
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) {
|
if ($request->parentNodeId === null) {
|
||||||
return $this->nodeRepo->create(new CreateNodeDto(
|
return $this->nodeRepo->create(new CreateNodeDto(
|
||||||
|
|
@ -29,7 +29,11 @@ class CreateNode
|
||||||
parentNode: null,
|
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(
|
return $this->nodeRepo->create(new CreateNodeDto(
|
||||||
text: $text,
|
text: $text,
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ class CreateNodeTest extends TestCase
|
||||||
public function test_throws_if_text_doesnt_exist(): void
|
public function test_throws_if_text_doesnt_exist(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DomainException::class);
|
$this->expectException(DomainException::class);
|
||||||
|
$this->expectExceptionMessage("Text with id: 1 doesnt exist");
|
||||||
$node = $this->useCase->execute(new CreateNodeRequest(
|
$node = $this->useCase->execute(new CreateNodeRequest(
|
||||||
textId: 1,
|
textId: 1,
|
||||||
title: 'test',
|
title: 'test',
|
||||||
|
|
@ -83,4 +84,15 @@ class CreateNodeTest extends TestCase
|
||||||
$node2->getParentNode()->getId()
|
$node2->getParentNode()->getId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_nonexistant_parent_id_throws(): void
|
||||||
|
{
|
||||||
|
$this->expectException(DomainException::class);
|
||||||
|
$this->expectExceptionMessage("Node with id: 0 doesnt exist");
|
||||||
|
$node = $this->useCase->execute(new CreateNodeRequest(
|
||||||
|
textId: 0,
|
||||||
|
title: 'test',
|
||||||
|
parentNodeId: 0,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue