feat: Reader beginning
This commit is contained in:
parent
e90c0a140e
commit
55945adc53
75
tests/Feature/Reader/GetChapterContextTest.php
Normal file
75
tests/Feature/Reader/GetChapterContextTest.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class ScrapeChapterTest extends AbstractApiTestCase
|
||||
{
|
||||
// Given
|
||||
$payload = [
|
||||
'chapterId' => 'chapter-123',
|
||||
'chapterNumber' => 'chapter-123',
|
||||
'sourceId' => 'source-456',
|
||||
'mangaId' => 'manga-789',
|
||||
];
|
||||
@@ -49,7 +49,7 @@ class ScrapeChapterTest extends AbstractApiTestCase
|
||||
{
|
||||
// Given
|
||||
$payload = [
|
||||
'chapterId' => '',
|
||||
'chapterNumber' => '',
|
||||
'sourceId' => 'source-456',
|
||||
'mangaId' => 'manga-789',
|
||||
];
|
||||
@@ -65,7 +65,7 @@ class ScrapeChapterTest extends AbstractApiTestCase
|
||||
$this->assertJsonContains([
|
||||
'violations' => [
|
||||
[
|
||||
'propertyPath' => 'chapterId',
|
||||
'propertyPath' => 'chapterNumber',
|
||||
'message' => 'This value should not be blank.',
|
||||
],
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user