diff --git a/backend/tests/Feature/ElementsEndpointTest.php b/backend/tests/Feature/ElementsEndpointTest.php index 40834f2..b4949e4 100644 --- a/backend/tests/Feature/ElementsEndpointTest.php +++ b/backend/tests/Feature/ElementsEndpointTest.php @@ -25,16 +25,19 @@ class ElementsEndpointTest extends TestCase $element = $elementRepository->create(new CreateElementDto( set: $set, title: 'Baderech HaAvodah', + description: 'A structured path for growth', parentElement: null, )); $firstChildElement = $elementRepository->create(new CreateElementDto( set: $set, title: 'Avodah Foundations', + description: 'Foundations for steady avodah', parentElement: $element, )); $secondChildElement = $elementRepository->create(new CreateElementDto( set: $set, title: 'Daily Practice', + description: 'Daily practices for growth', parentElement: $element, )); @@ -46,15 +49,18 @@ class ElementsEndpointTest extends TestCase [ 'id' => $firstChildElement->getId(), 'title' => 'Avodah Foundations', + 'description' => 'Foundations for steady avodah', ], [ 'id' => $secondChildElement->getId(), 'title' => 'Daily Practice', + 'description' => 'Daily practices for growth', ], ], 'element' => [ 'id' => $element->getId(), 'title' => 'Baderech HaAvodah', + 'description' => 'A structured path for growth', ], ]); } diff --git a/backend/tests/Feature/SetsEndpointTest.php b/backend/tests/Feature/SetsEndpointTest.php index 6b79a7a..a1c3ce9 100644 --- a/backend/tests/Feature/SetsEndpointTest.php +++ b/backend/tests/Feature/SetsEndpointTest.php @@ -31,6 +31,7 @@ class SetsEndpointTest extends TestCase new CreateElementDto( set: $baderechSet, title: $baderechSet->getName(), + description: $baderechSet->getDescription(), parentElement: null, ) ); diff --git a/backend/tests/Unit/Controllers/ElementControllerTest.php b/backend/tests/Unit/Controllers/ElementControllerTest.php index 20a18dc..0d6e0f2 100644 --- a/backend/tests/Unit/Controllers/ElementControllerTest.php +++ b/backend/tests/Unit/Controllers/ElementControllerTest.php @@ -26,15 +26,22 @@ class ElementControllerTest extends TestCase public function testShowReturnsElementPayload(): void { $set = $this->createSet(1, 'Baderech'); - $element = $this->createElement($set, 'Baderech HaAvodah', null); + $element = $this->createElement( + $set, + 'Baderech HaAvodah', + 'A structured path for growth', + null, + ); $firstChildElement = $this->createElement( $set, 'Avodah Foundations', + 'Foundations for steady avodah', $element, ); $secondChildElement = $this->createElement( $set, 'Daily Practice', + 'Daily practices for growth', $element, ); @@ -44,14 +51,20 @@ class ElementControllerTest extends TestCase $body = json_decode($response->getContent(), true); $this->assertSame($element->getId(), $body['element']['id']); $this->assertSame('Baderech HaAvodah', $body['element']['title']); + $this->assertSame( + 'A structured path for growth', + $body['element']['description'], + ); $this->assertSame([ [ 'id' => $firstChildElement->getId(), 'title' => 'Avodah Foundations', + 'description' => 'Foundations for steady avodah', ], [ 'id' => $secondChildElement->getId(), 'title' => 'Daily Practice', + 'description' => 'Daily practices for growth', ], ], $body['childElements']); } @@ -91,11 +104,13 @@ class ElementControllerTest extends TestCase private function createElement( DomainSet $set, string $title, + string $description, ?Element $parentElement, ): Element { return $this->elementRepo->create(new CreateElementDto( set: $set, title: $title, + description: $description, parentElement: $parentElement, )); } diff --git a/backend/tests/Unit/Element/ElementTest.php b/backend/tests/Unit/Element/ElementTest.php index 5d7ded2..3a0cdce 100644 --- a/backend/tests/Unit/Element/ElementTest.php +++ b/backend/tests/Unit/Element/ElementTest.php @@ -19,18 +19,24 @@ class ElementTest extends TestCase $rootElement = new Element( id: 1, title: 'Root', + description: 'Root description', set: $set, parentElement: null, ); $childElement = new Element( id: 2, title: 'Child', + description: 'Child description', set: $set, parentElement: $rootElement, ); $this->assertSame(2, $childElement->getId()); $this->assertSame('Child', $childElement->getTitle()); + $this->assertSame( + 'Child description', + $childElement->getDescription(), + ); $this->assertSame($set, $childElement->getSet()); $this->assertSame($rootElement, $childElement->getParentElement()); $this->assertNull($rootElement->getParentElement()); diff --git a/backend/tests/Unit/Element/UseCases/CreateElementTest.php b/backend/tests/Unit/Element/UseCases/CreateElementTest.php index 340f49e..cef6aa4 100644 --- a/backend/tests/Unit/Element/UseCases/CreateElementTest.php +++ b/backend/tests/Unit/Element/UseCases/CreateElementTest.php @@ -47,11 +47,13 @@ class CreateElementTest extends TestCase $element = $this->createElement->execute(new CreateElementRequest( setId: $set->getId(), title: 'Root', + description: 'Root description', parentElementId: null, )); $this->assertInstanceOf(Element::class, $element); $this->assertSame('Root', $element->getTitle()); + $this->assertSame('Root description', $element->getDescription()); $this->assertSame($set->getId(), $element->getSet()->getId()); $this->assertNull($element->getParentElement()); } @@ -63,6 +65,7 @@ class CreateElementTest extends TestCase new CreateElementRequest( setId: $set->getId(), title: 'Root', + description: 'Root description', parentElementId: null, ) ); @@ -71,17 +74,36 @@ class CreateElementTest extends TestCase new CreateElementRequest( setId: $set->getId(), title: 'Child', + description: 'Child description', parentElementId: $rootElement->getId(), ) ); $this->assertSame('Child', $childElement->getTitle()); + $this->assertSame( + 'Child description', + $childElement->getDescription(), + ); $this->assertSame( $rootElement->getId(), $childElement->getParentElement()->getId(), ); } + public function testCreatesElementWithBlankDescriptionWhenMissing(): void + { + $set = $this->createSet('Daily learning'); + + $element = $this->createElement->execute(new CreateElementRequest( + setId: $set->getId(), + title: 'Root', + description: null, + parentElementId: null, + )); + + $this->assertSame('', $element->getDescription()); + } + public function testThrowsWhenSetIdMissing(): void { $this->expectException(BadRequestException::class); @@ -90,6 +112,7 @@ class CreateElementTest extends TestCase $this->createElement->execute(new CreateElementRequest( setId: null, title: 'Root', + description: 'Root description', parentElementId: null, )); } @@ -102,6 +125,7 @@ class CreateElementTest extends TestCase $this->createElement->execute(new CreateElementRequest( setId: 1, title: null, + description: 'Root description', parentElementId: null, )); } @@ -114,6 +138,7 @@ class CreateElementTest extends TestCase $this->createElement->execute(new CreateElementRequest( setId: 99, title: 'Root', + description: 'Root description', parentElementId: null, )); } @@ -130,6 +155,7 @@ class CreateElementTest extends TestCase $this->createElement->execute(new CreateElementRequest( setId: $set->getId(), title: 'Child', + description: 'Child description', parentElementId: 99, )); } @@ -140,6 +166,7 @@ class CreateElementTest extends TestCase $this->createElement->execute(new CreateElementRequest( setId: $set->getId(), title: 'Root', + description: 'Root description', parentElementId: null, )); @@ -151,6 +178,7 @@ class CreateElementTest extends TestCase $this->createElement->execute(new CreateElementRequest( setId: $set->getId(), title: 'Another root', + description: 'Another root description', parentElementId: null, )); } @@ -163,6 +191,7 @@ class CreateElementTest extends TestCase new CreateElementRequest( setId: $parentSet->getId(), title: 'Parent root', + description: 'Parent root description', parentElementId: null, ) ); @@ -175,6 +204,7 @@ class CreateElementTest extends TestCase $this->createElement->execute(new CreateElementRequest( setId: $childSet->getId(), title: 'Invalid child', + description: 'Invalid child description', parentElementId: $parentElement->getId(), )); } diff --git a/backend/tests/Unit/Element/UseCases/GetElementTest.php b/backend/tests/Unit/Element/UseCases/GetElementTest.php index fc665b0..9e398f4 100644 --- a/backend/tests/Unit/Element/UseCases/GetElementTest.php +++ b/backend/tests/Unit/Element/UseCases/GetElementTest.php @@ -30,6 +30,7 @@ class GetElementTest extends TestCase $element = $this->createElement( $set, 'Baderech HaAvodah', + 'A structured path for growth', null, ); @@ -41,6 +42,10 @@ class GetElementTest extends TestCase $this->assertInstanceOf(Element::class, $foundElement); $this->assertSame($element->getId(), $foundElement->getId()); $this->assertSame('Baderech HaAvodah', $foundElement->getTitle()); + $this->assertSame( + 'A structured path for growth', + $foundElement->getDescription(), + ); } public function testReturnsDirectChildElements(): void @@ -49,32 +54,38 @@ class GetElementTest extends TestCase $parentElement = $this->createElement( $set, 'Baderech HaAvodah', + 'A structured path for growth', null, ); $firstChildElement = $this->createElement( $set, 'Avodah Foundations', + 'Foundations for steady avodah', $parentElement, ); $secondChildElement = $this->createElement( $set, 'Daily Practice', + 'Daily practices for growth', $parentElement, ); $this->createElement( $set, 'Nested Practice', + 'Nested description', $firstChildElement, ); $otherSet = $this->createSet(2, 'Daily Learning'); $otherParentElement = $this->createElement( $otherSet, 'Other Parent', + 'Other parent description', null, ); $this->createElement( $otherSet, 'Other Child', + 'Other child description', $otherParentElement, ); @@ -89,11 +100,19 @@ class GetElementTest extends TestCase $childElements[0]->getId(), ); $this->assertSame('Avodah Foundations', $childElements[0]->getTitle()); + $this->assertSame( + 'Foundations for steady avodah', + $childElements[0]->getDescription(), + ); $this->assertSame( $secondChildElement->getId(), $childElements[1]->getId(), ); $this->assertSame('Daily Practice', $childElements[1]->getTitle()); + $this->assertSame( + 'Daily practices for growth', + $childElements[1]->getDescription(), + ); } public function testThrowsWhenIdMissing(): void @@ -125,11 +144,13 @@ class GetElementTest extends TestCase private function createElement( DomainSet $set, string $title, + string $description, ?Element $parentElement, ): Element { return $this->elementRepo->create(new CreateElementDto( set: $set, title: $title, + description: $description, parentElement: $parentElement, )); }