feat: GetPage endpoint
This commit is contained in:
parent
55945adc53
commit
33f5a5568a
85
tests/Feature/Reader/GetChapterPageTest.php
Normal file
85
tests/Feature/Reader/GetChapterPageTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Feature\Reader;
|
||||
|
||||
use App\Factory\ChapterFactory;
|
||||
use App\Factory\MangaFactory;
|
||||
use App\Tests\Feature\AbstractApiTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Zenstruck\Foundry\Test\ResetDatabase;
|
||||
|
||||
final class GetChapterPageTest extends AbstractApiTestCase
|
||||
{
|
||||
use ResetDatabase;
|
||||
|
||||
private int $chapterId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Création d'un manga et d'un chapitre avec les factories
|
||||
$manga = MangaFactory::createOne([
|
||||
'title' => 'Test Manga',
|
||||
'slug' => 'test-manga'
|
||||
]);
|
||||
|
||||
$chapter = ChapterFactory::createOne([
|
||||
'manga' => $manga,
|
||||
'title' => 'Chapter 1',
|
||||
'number' => 1.0,
|
||||
'volume' => 1,
|
||||
'visible' => true,
|
||||
'cbzPath' => __DIR__ . '/../../Fixtures/chapter.cbz'
|
||||
]);
|
||||
|
||||
$this->chapterId = $chapter->getId();
|
||||
}
|
||||
|
||||
public function testItReturnsNotFoundWhenChapterDoesNotExist(): void
|
||||
{
|
||||
$response = static::createClient()->request('GET', '/api/reader/chapter/999/page/1');
|
||||
|
||||
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
||||
$this->assertJsonContains([
|
||||
'detail' => 'Le chapitre 999 n\'existe pas'
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItReturnsNotFoundWhenPageDoesNotExist(): void
|
||||
{
|
||||
$response = static::createClient()->request('GET', sprintf('/api/reader/chapter/%d/page/999', $this->chapterId));
|
||||
|
||||
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
||||
$this->assertJsonContains([
|
||||
'detail' => sprintf('La page 999 du chapitre %d n\'existe pas', $this->chapterId)
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItReturnsPageContentSuccessfully(): void
|
||||
{
|
||||
$response = static::createClient()->request('GET', sprintf('/api/reader/chapter/%d/page/1', $this->chapterId));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
|
||||
// $this->assertJsonContains([
|
||||
// 'id' => '01.jpg',
|
||||
// 'pageNumber' => 1,
|
||||
// 'mimeType' => 'image/jpeg',
|
||||
// 'dimensions' => [
|
||||
// 'hydra:member' => [
|
||||
// 800,
|
||||
// 1169
|
||||
// ]
|
||||
// ]
|
||||
// ]);
|
||||
|
||||
$content = $response->toArray();
|
||||
$this->assertArrayHasKey('base64Content', $content);
|
||||
$this->assertNotEmpty($content['base64Content']);
|
||||
$this->assertTrue(base64_decode($content['base64Content'], true) !== false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user