test element siblings

This commit is contained in:
Yisroel Baum 2026-06-21 22:36:29 +03:00
parent 90d28deffb
commit eb868679c8
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 258 additions and 0 deletions

View file

@ -94,6 +94,74 @@ class ElementsEndpointTest extends TestCase
'longPdfPath' => '/assets/pdfs/baderech-long.pdf', 'longPdfPath' => '/assets/pdfs/baderech-long.pdf',
'youtubeUrl' => $sampleYoutubeUrl, 'youtubeUrl' => $sampleYoutubeUrl,
], ],
'siblingElements' => [
[
'id' => $element->getId(),
'title' => 'Baderech HaAvodah',
'description' => 'A structured path for growth',
],
],
]);
}
public function testReturnsSameParentSiblingElements(): void
{
$setRepository = app(SetRepository::class);
$elementRepository = app(ElementRepository::class);
$set = $this->createSet($setRepository);
$parentElement = $this->createElement(
$elementRepository,
$set,
'Baderech HaAvodah',
'A structured path for growth',
null,
'',
null,
null,
null,
null,
);
$firstChildElement = $this->createElement(
$elementRepository,
$set,
'Avodah Foundations',
'Foundations for steady avodah',
null,
'<p>Foundations rich text</p>',
null,
null,
null,
$parentElement,
);
$secondChildElement = $this->createElement(
$elementRepository,
$set,
'Daily Practice',
'Daily practices for growth',
null,
'',
null,
null,
null,
$parentElement,
);
$response = $this->getJson(
"/api/elements/{$firstChildElement->getId()}"
);
$response->assertOk();
$response->assertJsonPath('siblingElements', [
[
'id' => $firstChildElement->getId(),
'title' => 'Avodah Foundations',
'description' => 'Foundations for steady avodah',
],
[
'id' => $secondChildElement->getId(),
'title' => 'Daily Practice',
'description' => 'Daily practices for growth',
],
]); ]);
} }

View file

@ -150,6 +150,68 @@ class ElementControllerTest extends TestCase
'description' => 'Daily practices for growth', 'description' => 'Daily practices for growth',
], ],
], $body['childElements']); ], $body['childElements']);
$this->assertSame([
[
'id' => $element->getId(),
'title' => 'Baderech HaAvodah',
'description' => 'A structured path for growth',
],
], $body['siblingElements']);
}
public function testShowReturnsSameParentSiblingPayload(): void
{
$set = $this->createSet(1, 'Baderech');
$parentElement = $this->createElement(
$set,
'Baderech HaAvodah',
'A structured path for growth',
null,
'',
null,
null,
null,
null,
);
$firstChildElement = $this->createElement(
$set,
'Avodah Foundations',
'Foundations for steady avodah',
null,
'<p>Foundations rich text</p>',
null,
null,
null,
$parentElement,
);
$secondChildElement = $this->createElement(
$set,
'Daily Practice',
'Daily practices for growth',
null,
'',
null,
null,
null,
$parentElement,
);
$response = $this->controller->show($firstChildElement->getId());
$this->assertEquals(200, $response->getStatusCode());
$body = json_decode($response->getContent(), true);
$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['siblingElements']);
} }
public function testShowReturns400WhenIdMissing(): void public function testShowReturns400WhenIdMissing(): void

View file

@ -159,6 +159,134 @@ class GetElementTest extends TestCase
); );
} }
public function testReturnsSiblingElementsWithSameParent(): void
{
$set = $this->createSet(1, 'Baderech');
$parentElement = $this->createElement(
$set,
'Baderech HaAvodah',
'A structured path for growth',
null,
'<p>A structured path for growth</p>',
'/assets/pdfs/baderech.pdf',
null,
null,
);
$firstChildElement = $this->createElement(
$set,
'Avodah Foundations',
'Foundations for steady avodah',
null,
'<p>Foundations rich text</p>',
'/assets/pdfs/foundations.pdf',
null,
$parentElement,
);
$secondChildElement = $this->createElement(
$set,
'Daily Practice',
'Daily practices for growth',
null,
'<p>Daily practice rich text</p>',
null,
null,
$parentElement,
);
$this->createElement(
$set,
'Nested Practice',
'Nested description',
null,
'<p>Nested rich text</p>',
null,
null,
$firstChildElement,
);
$otherSet = $this->createSet(2, 'Daily Learning');
$otherParentElement = $this->createElement(
$otherSet,
'Other Parent',
'Other parent description',
null,
'<p>Other parent rich text</p>',
null,
null,
null,
);
$this->createElement(
$otherSet,
'Other Child',
'Other child description',
null,
'<p>Other child rich text</p>',
null,
null,
$otherParentElement,
);
$result = $this->getElement->execute(new GetElementRequest(
id: $firstChildElement->getId(),
));
$siblingElements = $result->getSiblingElements();
$this->assertCount(2, $siblingElements);
$this->assertSame(
$firstChildElement->getId(),
$siblingElements[0]->getId(),
);
$this->assertSame(
'Avodah Foundations',
$siblingElements[0]->getTitle(),
);
$this->assertSame(
'Foundations for steady avodah',
$siblingElements[0]->getDescription(),
);
$this->assertSame(
$secondChildElement->getId(),
$siblingElements[1]->getId(),
);
$this->assertSame('Daily Practice', $siblingElements[1]->getTitle());
$this->assertSame(
'Daily practices for growth',
$siblingElements[1]->getDescription(),
);
}
public function testReturnsRootElementAsOnlySibling(): void
{
$set = $this->createSet(1, 'Baderech');
$rootElement = $this->createElement(
$set,
'Baderech HaAvodah',
'A structured path for growth',
null,
'<p>A structured path for growth</p>',
'/assets/pdfs/baderech.pdf',
null,
null,
);
$this->createElement(
$set,
'Avodah Foundations',
'Foundations for steady avodah',
null,
'<p>Foundations rich text</p>',
'/assets/pdfs/foundations.pdf',
null,
$rootElement,
);
$result = $this->getElement->execute(new GetElementRequest(
id: $rootElement->getId(),
));
$siblingElements = $result->getSiblingElements();
$this->assertCount(1, $siblingElements);
$this->assertSame($rootElement->getId(), $siblingElements[0]->getId());
$this->assertSame('Baderech HaAvodah', $siblingElements[0]->getTitle());
}
public function testThrowsWhenIdMissing(): void public function testThrowsWhenIdMissing(): void
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);