Files
Mangarr/tests/Feature/Reader/GetChapterContextTest.php
ext.jeremy.guillot@maxicoffee.domains 55945adc53 feat: Reader beginning
2025-02-16 16:15:42 +01:00

76 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Feature\Reader;
use App\Factory\ChapterFactory;
use App\Factory\MangaFactory;
use App\Tests\Feature\AbstractApiTestCase;
use Zenstruck\Foundry\Test\ResetDatabase;
final class GetChapterContextTest extends AbstractApiTestCase
{
use ResetDatabase;
public function testItReturnsChapterContext(): void
{
// Arrange
$manga = MangaFactory::createOne([
'slug' => 'manga-1',
]);
$chapter1 = ChapterFactory::createOne([
'manga' => $manga,
'title' => 'Chapter 1',
'number' => 1,
]);
$chapter2 = ChapterFactory::createOne([
'manga' => $manga,
'title' => 'Chapter 2',
'number' => 2,
]);
$chapter3 = ChapterFactory::createOne([
'manga' => $manga,
'title' => 'Chapter 3',
'number' => 3,
]);
// Act
static::createClient()->request('GET', '/api/reader/chapter/' . $chapter1->getId());
// Assert
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'id' => (string)$chapter1->getId(),
'title' => 'Chapter 1',
'number' => 1,
'totalPages' => 0,
'navigation' => [
'hydra:member' => [
null, (string)$chapter2->getId(),
],
]
]);
}
public function testItReturns404ForNonExistentChapter(): void
{
// Act
static::createClient()->request('GET', '/api/reader/chapter/0');
// Assert
$this->assertResponseStatusCodeSame(404);
$this->assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
$this->assertJsonContains([
'hydra:title' => 'An error occurred',
'hydra:description' => 'Le chapitre 0 n\'existe pas',
]);
}
}