diff --git a/backend/tests/Unit/Element/UseCases/GetElementTest.php b/backend/tests/Unit/Element/UseCases/GetElementTest.php new file mode 100644 index 0000000..a301af6 --- /dev/null +++ b/backend/tests/Unit/Element/UseCases/GetElementTest.php @@ -0,0 +1,71 @@ +elementRepo = new FakeElementRepository(); + $this->getElement = new GetElement($this->elementRepo); + } + + public function testReturnsElementWhenFound(): void + { + $element = $this->createElement('Baderech HaAvodah'); + + $foundElement = $this->getElement->execute(new GetElementRequest( + id: $element->getId(), + )); + + $this->assertInstanceOf(Element::class, $foundElement); + $this->assertSame($element->getId(), $foundElement->getId()); + $this->assertSame('Baderech HaAvodah', $foundElement->getTitle()); + } + + public function testThrowsWhenIdMissing(): void + { + $this->expectException(BadRequestException::class); + $this->expectExceptionMessage('id is required'); + + $this->getElement->execute(new GetElementRequest(id: null)); + } + + public function testThrowsWhenElementDoesNotExist(): void + { + $this->expectException(NotFoundException::class); + $this->expectExceptionMessage('Element not found'); + + $this->getElement->execute(new GetElementRequest(id: 999)); + } + + private function createElement(string $title): Element + { + $set = new DomainSet( + id: 1, + name: 'Baderech', + description: 'Baderech description', + iconImageUrl: '/assets/baderech-icon.png', + ); + + return $this->elementRepo->create(new CreateElementDto( + set: $set, + title: $title, + parentElement: null, + )); + } +}