71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Element\CreateElementDto;
|
|
use App\Element\ElementRepository;
|
|
use App\Set\CreateSetDto;
|
|
use App\Set\SetRepository;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class ElementsEndpointTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function testReturnsElementTitle(): void
|
|
{
|
|
$setRepository = app(SetRepository::class);
|
|
$elementRepository = app(ElementRepository::class);
|
|
$set = $setRepository->create(new CreateSetDto(
|
|
name: 'Baderech HaAvodah',
|
|
description: 'A structured path for growth',
|
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
|
));
|
|
$element = $elementRepository->create(new CreateElementDto(
|
|
set: $set,
|
|
title: 'Baderech HaAvodah',
|
|
parentElement: null,
|
|
));
|
|
$firstChildElement = $elementRepository->create(new CreateElementDto(
|
|
set: $set,
|
|
title: 'Avodah Foundations',
|
|
parentElement: $element,
|
|
));
|
|
$secondChildElement = $elementRepository->create(new CreateElementDto(
|
|
set: $set,
|
|
title: 'Daily Practice',
|
|
parentElement: $element,
|
|
));
|
|
|
|
$response = $this->getJson("/api/elements/{$element->getId()}");
|
|
|
|
$response->assertOk();
|
|
$response->assertExactJson([
|
|
'childElements' => [
|
|
[
|
|
'id' => $firstChildElement->getId(),
|
|
'title' => 'Avodah Foundations',
|
|
],
|
|
[
|
|
'id' => $secondChildElement->getId(),
|
|
'title' => 'Daily Practice',
|
|
],
|
|
],
|
|
'element' => [
|
|
'id' => $element->getId(),
|
|
'title' => 'Baderech HaAvodah',
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function testReturns404WhenElementDoesNotExist(): void
|
|
{
|
|
$response = $this->getJson('/api/elements/999');
|
|
|
|
$response->assertNotFound();
|
|
$response->assertExactJson([
|
|
'error' => 'Element not found',
|
|
]);
|
|
}
|
|
}
|