test element descriptions

This commit is contained in:
Yisroel Baum 2026-05-26 21:10:42 +03:00
parent a317f24976
commit f2dc1483dd
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
6 changed files with 80 additions and 1 deletions

View file

@ -25,16 +25,19 @@ class ElementsEndpointTest extends TestCase
$element = $elementRepository->create(new CreateElementDto( $element = $elementRepository->create(new CreateElementDto(
set: $set, set: $set,
title: 'Baderech HaAvodah', title: 'Baderech HaAvodah',
description: 'A structured path for growth',
parentElement: null, parentElement: null,
)); ));
$firstChildElement = $elementRepository->create(new CreateElementDto( $firstChildElement = $elementRepository->create(new CreateElementDto(
set: $set, set: $set,
title: 'Avodah Foundations', title: 'Avodah Foundations',
description: 'Foundations for steady avodah',
parentElement: $element, parentElement: $element,
)); ));
$secondChildElement = $elementRepository->create(new CreateElementDto( $secondChildElement = $elementRepository->create(new CreateElementDto(
set: $set, set: $set,
title: 'Daily Practice', title: 'Daily Practice',
description: 'Daily practices for growth',
parentElement: $element, parentElement: $element,
)); ));
@ -46,15 +49,18 @@ class ElementsEndpointTest extends TestCase
[ [
'id' => $firstChildElement->getId(), 'id' => $firstChildElement->getId(),
'title' => 'Avodah Foundations', 'title' => 'Avodah Foundations',
'description' => 'Foundations for steady avodah',
], ],
[ [
'id' => $secondChildElement->getId(), 'id' => $secondChildElement->getId(),
'title' => 'Daily Practice', 'title' => 'Daily Practice',
'description' => 'Daily practices for growth',
], ],
], ],
'element' => [ 'element' => [
'id' => $element->getId(), 'id' => $element->getId(),
'title' => 'Baderech HaAvodah', 'title' => 'Baderech HaAvodah',
'description' => 'A structured path for growth',
], ],
]); ]);
} }

View file

@ -31,6 +31,7 @@ class SetsEndpointTest extends TestCase
new CreateElementDto( new CreateElementDto(
set: $baderechSet, set: $baderechSet,
title: $baderechSet->getName(), title: $baderechSet->getName(),
description: $baderechSet->getDescription(),
parentElement: null, parentElement: null,
) )
); );

View file

@ -26,15 +26,22 @@ class ElementControllerTest extends TestCase
public function testShowReturnsElementPayload(): void public function testShowReturnsElementPayload(): void
{ {
$set = $this->createSet(1, 'Baderech'); $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( $firstChildElement = $this->createElement(
$set, $set,
'Avodah Foundations', 'Avodah Foundations',
'Foundations for steady avodah',
$element, $element,
); );
$secondChildElement = $this->createElement( $secondChildElement = $this->createElement(
$set, $set,
'Daily Practice', 'Daily Practice',
'Daily practices for growth',
$element, $element,
); );
@ -44,14 +51,20 @@ class ElementControllerTest extends TestCase
$body = json_decode($response->getContent(), true); $body = json_decode($response->getContent(), true);
$this->assertSame($element->getId(), $body['element']['id']); $this->assertSame($element->getId(), $body['element']['id']);
$this->assertSame('Baderech HaAvodah', $body['element']['title']); $this->assertSame('Baderech HaAvodah', $body['element']['title']);
$this->assertSame(
'A structured path for growth',
$body['element']['description'],
);
$this->assertSame([ $this->assertSame([
[ [
'id' => $firstChildElement->getId(), 'id' => $firstChildElement->getId(),
'title' => 'Avodah Foundations', 'title' => 'Avodah Foundations',
'description' => 'Foundations for steady avodah',
], ],
[ [
'id' => $secondChildElement->getId(), 'id' => $secondChildElement->getId(),
'title' => 'Daily Practice', 'title' => 'Daily Practice',
'description' => 'Daily practices for growth',
], ],
], $body['childElements']); ], $body['childElements']);
} }
@ -91,11 +104,13 @@ class ElementControllerTest extends TestCase
private function createElement( private function createElement(
DomainSet $set, DomainSet $set,
string $title, string $title,
string $description,
?Element $parentElement, ?Element $parentElement,
): Element { ): Element {
return $this->elementRepo->create(new CreateElementDto( return $this->elementRepo->create(new CreateElementDto(
set: $set, set: $set,
title: $title, title: $title,
description: $description,
parentElement: $parentElement, parentElement: $parentElement,
)); ));
} }

View file

@ -19,18 +19,24 @@ class ElementTest extends TestCase
$rootElement = new Element( $rootElement = new Element(
id: 1, id: 1,
title: 'Root', title: 'Root',
description: 'Root description',
set: $set, set: $set,
parentElement: null, parentElement: null,
); );
$childElement = new Element( $childElement = new Element(
id: 2, id: 2,
title: 'Child', title: 'Child',
description: 'Child description',
set: $set, set: $set,
parentElement: $rootElement, parentElement: $rootElement,
); );
$this->assertSame(2, $childElement->getId()); $this->assertSame(2, $childElement->getId());
$this->assertSame('Child', $childElement->getTitle()); $this->assertSame('Child', $childElement->getTitle());
$this->assertSame(
'Child description',
$childElement->getDescription(),
);
$this->assertSame($set, $childElement->getSet()); $this->assertSame($set, $childElement->getSet());
$this->assertSame($rootElement, $childElement->getParentElement()); $this->assertSame($rootElement, $childElement->getParentElement());
$this->assertNull($rootElement->getParentElement()); $this->assertNull($rootElement->getParentElement());

View file

@ -47,11 +47,13 @@ class CreateElementTest extends TestCase
$element = $this->createElement->execute(new CreateElementRequest( $element = $this->createElement->execute(new CreateElementRequest(
setId: $set->getId(), setId: $set->getId(),
title: 'Root', title: 'Root',
description: 'Root description',
parentElementId: null, parentElementId: null,
)); ));
$this->assertInstanceOf(Element::class, $element); $this->assertInstanceOf(Element::class, $element);
$this->assertSame('Root', $element->getTitle()); $this->assertSame('Root', $element->getTitle());
$this->assertSame('Root description', $element->getDescription());
$this->assertSame($set->getId(), $element->getSet()->getId()); $this->assertSame($set->getId(), $element->getSet()->getId());
$this->assertNull($element->getParentElement()); $this->assertNull($element->getParentElement());
} }
@ -63,6 +65,7 @@ class CreateElementTest extends TestCase
new CreateElementRequest( new CreateElementRequest(
setId: $set->getId(), setId: $set->getId(),
title: 'Root', title: 'Root',
description: 'Root description',
parentElementId: null, parentElementId: null,
) )
); );
@ -71,17 +74,36 @@ class CreateElementTest extends TestCase
new CreateElementRequest( new CreateElementRequest(
setId: $set->getId(), setId: $set->getId(),
title: 'Child', title: 'Child',
description: 'Child description',
parentElementId: $rootElement->getId(), parentElementId: $rootElement->getId(),
) )
); );
$this->assertSame('Child', $childElement->getTitle()); $this->assertSame('Child', $childElement->getTitle());
$this->assertSame(
'Child description',
$childElement->getDescription(),
);
$this->assertSame( $this->assertSame(
$rootElement->getId(), $rootElement->getId(),
$childElement->getParentElement()->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 public function testThrowsWhenSetIdMissing(): void
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
@ -90,6 +112,7 @@ class CreateElementTest extends TestCase
$this->createElement->execute(new CreateElementRequest( $this->createElement->execute(new CreateElementRequest(
setId: null, setId: null,
title: 'Root', title: 'Root',
description: 'Root description',
parentElementId: null, parentElementId: null,
)); ));
} }
@ -102,6 +125,7 @@ class CreateElementTest extends TestCase
$this->createElement->execute(new CreateElementRequest( $this->createElement->execute(new CreateElementRequest(
setId: 1, setId: 1,
title: null, title: null,
description: 'Root description',
parentElementId: null, parentElementId: null,
)); ));
} }
@ -114,6 +138,7 @@ class CreateElementTest extends TestCase
$this->createElement->execute(new CreateElementRequest( $this->createElement->execute(new CreateElementRequest(
setId: 99, setId: 99,
title: 'Root', title: 'Root',
description: 'Root description',
parentElementId: null, parentElementId: null,
)); ));
} }
@ -130,6 +155,7 @@ class CreateElementTest extends TestCase
$this->createElement->execute(new CreateElementRequest( $this->createElement->execute(new CreateElementRequest(
setId: $set->getId(), setId: $set->getId(),
title: 'Child', title: 'Child',
description: 'Child description',
parentElementId: 99, parentElementId: 99,
)); ));
} }
@ -140,6 +166,7 @@ class CreateElementTest extends TestCase
$this->createElement->execute(new CreateElementRequest( $this->createElement->execute(new CreateElementRequest(
setId: $set->getId(), setId: $set->getId(),
title: 'Root', title: 'Root',
description: 'Root description',
parentElementId: null, parentElementId: null,
)); ));
@ -151,6 +178,7 @@ class CreateElementTest extends TestCase
$this->createElement->execute(new CreateElementRequest( $this->createElement->execute(new CreateElementRequest(
setId: $set->getId(), setId: $set->getId(),
title: 'Another root', title: 'Another root',
description: 'Another root description',
parentElementId: null, parentElementId: null,
)); ));
} }
@ -163,6 +191,7 @@ class CreateElementTest extends TestCase
new CreateElementRequest( new CreateElementRequest(
setId: $parentSet->getId(), setId: $parentSet->getId(),
title: 'Parent root', title: 'Parent root',
description: 'Parent root description',
parentElementId: null, parentElementId: null,
) )
); );
@ -175,6 +204,7 @@ class CreateElementTest extends TestCase
$this->createElement->execute(new CreateElementRequest( $this->createElement->execute(new CreateElementRequest(
setId: $childSet->getId(), setId: $childSet->getId(),
title: 'Invalid child', title: 'Invalid child',
description: 'Invalid child description',
parentElementId: $parentElement->getId(), parentElementId: $parentElement->getId(),
)); ));
} }

View file

@ -30,6 +30,7 @@ class GetElementTest extends TestCase
$element = $this->createElement( $element = $this->createElement(
$set, $set,
'Baderech HaAvodah', 'Baderech HaAvodah',
'A structured path for growth',
null, null,
); );
@ -41,6 +42,10 @@ class GetElementTest extends TestCase
$this->assertInstanceOf(Element::class, $foundElement); $this->assertInstanceOf(Element::class, $foundElement);
$this->assertSame($element->getId(), $foundElement->getId()); $this->assertSame($element->getId(), $foundElement->getId());
$this->assertSame('Baderech HaAvodah', $foundElement->getTitle()); $this->assertSame('Baderech HaAvodah', $foundElement->getTitle());
$this->assertSame(
'A structured path for growth',
$foundElement->getDescription(),
);
} }
public function testReturnsDirectChildElements(): void public function testReturnsDirectChildElements(): void
@ -49,32 +54,38 @@ class GetElementTest extends TestCase
$parentElement = $this->createElement( $parentElement = $this->createElement(
$set, $set,
'Baderech HaAvodah', 'Baderech HaAvodah',
'A structured path for growth',
null, null,
); );
$firstChildElement = $this->createElement( $firstChildElement = $this->createElement(
$set, $set,
'Avodah Foundations', 'Avodah Foundations',
'Foundations for steady avodah',
$parentElement, $parentElement,
); );
$secondChildElement = $this->createElement( $secondChildElement = $this->createElement(
$set, $set,
'Daily Practice', 'Daily Practice',
'Daily practices for growth',
$parentElement, $parentElement,
); );
$this->createElement( $this->createElement(
$set, $set,
'Nested Practice', 'Nested Practice',
'Nested description',
$firstChildElement, $firstChildElement,
); );
$otherSet = $this->createSet(2, 'Daily Learning'); $otherSet = $this->createSet(2, 'Daily Learning');
$otherParentElement = $this->createElement( $otherParentElement = $this->createElement(
$otherSet, $otherSet,
'Other Parent', 'Other Parent',
'Other parent description',
null, null,
); );
$this->createElement( $this->createElement(
$otherSet, $otherSet,
'Other Child', 'Other Child',
'Other child description',
$otherParentElement, $otherParentElement,
); );
@ -89,11 +100,19 @@ class GetElementTest extends TestCase
$childElements[0]->getId(), $childElements[0]->getId(),
); );
$this->assertSame('Avodah Foundations', $childElements[0]->getTitle()); $this->assertSame('Avodah Foundations', $childElements[0]->getTitle());
$this->assertSame(
'Foundations for steady avodah',
$childElements[0]->getDescription(),
);
$this->assertSame( $this->assertSame(
$secondChildElement->getId(), $secondChildElement->getId(),
$childElements[1]->getId(), $childElements[1]->getId(),
); );
$this->assertSame('Daily Practice', $childElements[1]->getTitle()); $this->assertSame('Daily Practice', $childElements[1]->getTitle());
$this->assertSame(
'Daily practices for growth',
$childElements[1]->getDescription(),
);
} }
public function testThrowsWhenIdMissing(): void public function testThrowsWhenIdMissing(): void
@ -125,11 +144,13 @@ class GetElementTest extends TestCase
private function createElement( private function createElement(
DomainSet $set, DomainSet $set,
string $title, string $title,
string $description,
?Element $parentElement, ?Element $parentElement,
): Element { ): Element {
return $this->elementRepo->create(new CreateElementDto( return $this->elementRepo->create(new CreateElementDto(
set: $set, set: $set,
title: $title, title: $title,
description: $description,
parentElement: $parentElement, parentElement: $parentElement,
)); ));
} }