test child creation
This commit is contained in:
parent
416866a22c
commit
7c84eefe78
3 changed files with 213 additions and 0 deletions
|
|
@ -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='
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue