test child element ordering
This commit is contained in:
parent
14de828b4b
commit
7323925319
3 changed files with 505 additions and 0 deletions
|
|
@ -297,6 +297,234 @@ class ElementsEndpointTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testReorderChildElementsRequiresAuthentication(): 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,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$firstChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'First child',
|
||||
'First child description',
|
||||
null,
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$parentElement,
|
||||
);
|
||||
|
||||
$response = $this->putJson(
|
||||
"/api/elements/{$parentElement->getId()}/children/order",
|
||||
[
|
||||
'childElementIds' => [$firstChildElement->getId()],
|
||||
],
|
||||
);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
$response->assertExactJson([
|
||||
'error' => 'unauthenticated',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAuthenticatedReorderChildElementsPersistsOrder(): 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,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$firstChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'First child',
|
||||
'First child description',
|
||||
null,
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$parentElement,
|
||||
);
|
||||
$secondChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Second child',
|
||||
'Second child description',
|
||||
null,
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$parentElement,
|
||||
);
|
||||
$thirdChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Third child',
|
||||
'Third child description',
|
||||
null,
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$parentElement,
|
||||
);
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||
->putJson(
|
||||
"/api/elements/{$parentElement->getId()}/children/order",
|
||||
[
|
||||
'childElementIds' => [
|
||||
$thirdChildElement->getId(),
|
||||
$firstChildElement->getId(),
|
||||
$secondChildElement->getId(),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertExactJson([
|
||||
'childElements' => [
|
||||
[
|
||||
'id' => $thirdChildElement->getId(),
|
||||
'title' => 'Third child',
|
||||
'description' => 'Third child description',
|
||||
],
|
||||
[
|
||||
'id' => $firstChildElement->getId(),
|
||||
'title' => 'First child',
|
||||
'description' => 'First child description',
|
||||
],
|
||||
[
|
||||
'id' => $secondChildElement->getId(),
|
||||
'title' => 'Second child',
|
||||
'description' => 'Second child description',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->getJson("/api/elements/{$parentElement->getId()}")
|
||||
->assertJsonPath('childElements.0.id', $thirdChildElement->getId())
|
||||
->assertJsonPath('childElements.1.id', $firstChildElement->getId())
|
||||
->assertJsonPath(
|
||||
'childElements.2.id',
|
||||
$secondChildElement->getId(),
|
||||
);
|
||||
$this->getJson("/api/elements/{$thirdChildElement->getId()}")
|
||||
->assertJsonPath(
|
||||
'siblingElements.0.id',
|
||||
$thirdChildElement->getId(),
|
||||
)
|
||||
->assertJsonPath(
|
||||
'siblingElements.1.id',
|
||||
$firstChildElement->getId(),
|
||||
)
|
||||
->assertJsonPath(
|
||||
'siblingElements.2.id',
|
||||
$secondChildElement->getId(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthenticatedReorderRejectsNestedChildElement(): 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,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$firstChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'First child',
|
||||
'First child description',
|
||||
null,
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$parentElement,
|
||||
);
|
||||
$secondChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Second child',
|
||||
'Second child description',
|
||||
null,
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$parentElement,
|
||||
);
|
||||
$nestedChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Nested child',
|
||||
'Nested child description',
|
||||
null,
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$firstChildElement,
|
||||
);
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||
->putJson(
|
||||
"/api/elements/{$parentElement->getId()}/children/order",
|
||||
[
|
||||
'childElementIds' => [
|
||||
$firstChildElement->getId(),
|
||||
$nestedChildElement->getId(),
|
||||
$secondChildElement->getId(),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
$response->assertBadRequest();
|
||||
$response->assertExactJson([
|
||||
'error' => 'Child order contains invalid child',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteChildRequiresAuthentication(): void
|
||||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue