test child creation

This commit is contained in:
Yisroel Baum 2026-06-21 21:44:06 +03:00
parent 416866a22c
commit 7c84eefe78
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 213 additions and 0 deletions

View file

@ -142,6 +142,93 @@ class ElementsEndpointTest extends TestCase
]);
}
public function testCreateChildRequiresAuthentication(): 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,
);
$response = $this->postJson(
"/api/elements/{$parentElement->getId()}/children",
[
'title' => 'New child',
],
);
$response->assertUnauthorized();
$response->assertExactJson([
'error' => 'unauthenticated',
]);
}
public function testAuthenticatedCreateChildReturnsElementPayload(): 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,
);
$this->createSession('valid-token');
$response = $this->withCredentials()
->withUnencryptedCookie('auth_token', 'valid-token')
->postJson(
"/api/elements/{$parentElement->getId()}/children",
[
'title' => 'New admin child',
],
);
$response->assertCreated();
$body = $response->json();
$childElementId = $body['element']['id'];
$response->assertExactJson([
'element' => [
'id' => $childElementId,
'title' => 'New admin child',
'description' => '',
'iconImageUrl' => null,
'richText' => '',
'shortPdfPath' => null,
'longPdfPath' => null,
'youtubeUrl' => null,
],
]);
$createdElement = $elementRepository->find($childElementId);
$this->assertNotNull($createdElement);
$this->assertSame(
$parentElement->getId(),
$createdElement->getParentElement()->getId(),
);
$this->assertSame(
$parentElement->getSet()->getId(),
$createdElement->getSet()->getId(),
);
}
public function testAuthenticatedUpdateReturnsElementPayload(): void
{
$sampleYoutubeUrl = 'https://www.youtube.com/watch?v='