test element siblings
This commit is contained in:
parent
90d28deffb
commit
eb868679c8
3 changed files with 258 additions and 0 deletions
|
|
@ -94,6 +94,74 @@ class ElementsEndpointTest extends TestCase
|
|||
'longPdfPath' => '/assets/pdfs/baderech-long.pdf',
|
||||
'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',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,6 +150,68 @@ class ElementControllerTest extends TestCase
|
|||
'description' => 'Daily practices for growth',
|
||||
],
|
||||
], $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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue