diff --git a/src/Domain/Manga/Application/CommandHandler/FetchMangaChaptersHandler.php b/src/Domain/Manga/Application/CommandHandler/FetchMangaChaptersHandler.php index 3f5b076..b7b4d4e 100644 --- a/src/Domain/Manga/Application/CommandHandler/FetchMangaChaptersHandler.php +++ b/src/Domain/Manga/Application/CommandHandler/FetchMangaChaptersHandler.php @@ -44,6 +44,7 @@ readonly class FetchMangaChaptersHandler $chapterData['attributes']['title'], isset($chapterData['attributes']['volume']) ? (int) $chapterData['attributes']['volume'] : null, true, + false, new \DateTimeImmutable() ); diff --git a/src/Domain/Manga/Application/QueryHandler/GetMangaBySlugHandler.php b/src/Domain/Manga/Application/QueryHandler/GetMangaBySlugHandler.php index b41e7b7..bb20740 100644 --- a/src/Domain/Manga/Application/QueryHandler/GetMangaBySlugHandler.php +++ b/src/Domain/Manga/Application/QueryHandler/GetMangaBySlugHandler.php @@ -33,6 +33,7 @@ readonly class GetMangaBySlugHandler status: $manga->getStatus(), externalId: $manga->getExternalId()?->getValue(), imageUrl: $manga->getImageUrl(), + thumbnailUrl: $manga->getImageUrls()?->getThumbnail(), rating: $manga->getRating() ); } diff --git a/src/Domain/Manga/Application/QueryHandler/SearchMangaHandler.php b/src/Domain/Manga/Application/QueryHandler/SearchMangaHandler.php index 4686ece..060a1ff 100644 --- a/src/Domain/Manga/Application/QueryHandler/SearchMangaHandler.php +++ b/src/Domain/Manga/Application/QueryHandler/SearchMangaHandler.php @@ -6,6 +6,7 @@ use App\Domain\Manga\Application\Query\SearchManga; use App\Domain\Manga\Application\Response\MangaSearchItem; use App\Domain\Manga\Application\Response\MangaSearchResponse; use App\Domain\Manga\Domain\Contract\Provider\MangaProviderInterface; +use App\Domain\Manga\Domain\Model\Manga; readonly class SearchMangaHandler { @@ -19,7 +20,8 @@ readonly class SearchMangaHandler return new MangaSearchResponse( array_map( - fn ($manga) => new MangaSearchItem( + fn (Manga$manga) => new MangaSearchItem( + id: $manga->getId()->getValue(), externalId: $manga->getExternalId()->getValue(), title: $manga->getTitle()->getValue(), slug: $manga->getSlug()->getValue(), @@ -29,6 +31,7 @@ readonly class SearchMangaHandler genres: $manga->getGenres(), status: $manga->getStatus(), imageUrl: $manga->getImageUrl(), + thumbnailUrl: $manga->getImageUrls()?->getThumbnail(), rating: $manga->getRating() ), $mangaCollection->getItems() diff --git a/tests/Domain/Manga/Application/QueryHandler/GetMangaByIdHandlerTest.php b/tests/Domain/Manga/Application/QueryHandler/GetMangaByIdHandlerTest.php index 93d2b5a..2945052 100644 --- a/tests/Domain/Manga/Application/QueryHandler/GetMangaByIdHandlerTest.php +++ b/tests/Domain/Manga/Application/QueryHandler/GetMangaByIdHandlerTest.php @@ -7,6 +7,7 @@ use App\Domain\Manga\Application\QueryHandler\GetMangaByIdHandler; use App\Domain\Manga\Domain\Exception\MangaNotFoundException; use App\Domain\Manga\Domain\Model\Manga; use App\Domain\Manga\Domain\Model\ValueObject\ExternalId; +use App\Domain\Manga\Domain\Model\ValueObject\ImageUrls; use App\Domain\Manga\Domain\Model\ValueObject\MangaId; use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug; use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle; @@ -36,17 +37,19 @@ class GetMangaByIdHandlerTest extends TestCase { // Arrange $manga = new Manga( - new MangaId('123'), - new MangaTitle('One Piece'), - new MangaSlug('one-piece'), - 'Description test', - 'Eiichiro Oda', - 1997, - ['action', 'adventure'], - 'ongoing', - new ExternalId('external-123'), - 'http://example.com/image.jpg', - 4.5 + id: new MangaId('123'), + title: new MangaTitle('One Piece'), + slug: new MangaSlug('one-piece'), + description: 'Description test', + author: 'Eiichiro Oda', + publicationYear: 1997, + genres: ['action', 'adventure'], + status: 'ongoing', + externalId: new ExternalId('external-123'), + imageUrl: 'http://example.com/image.jpg', + rating: 4.5, + imageUrls: new ImageUrls('http://example.com/image.jpg', 'http://example.com/thumbnail.jpg'), + createdAt: new \DateTimeImmutable() ); $this->repository->save($manga); diff --git a/tests/Domain/Manga/Application/QueryHandler/GetMangaBySlugHandlerTest.php b/tests/Domain/Manga/Application/QueryHandler/GetMangaBySlugHandlerTest.php index eb98ebd..c7f93ee 100644 --- a/tests/Domain/Manga/Application/QueryHandler/GetMangaBySlugHandlerTest.php +++ b/tests/Domain/Manga/Application/QueryHandler/GetMangaBySlugHandlerTest.php @@ -6,6 +6,7 @@ use App\Domain\Manga\Application\Query\GetMangaBySlug; use App\Domain\Manga\Application\QueryHandler\GetMangaBySlugHandler; use App\Domain\Manga\Domain\Exception\MangaNotFoundException; use App\Domain\Manga\Domain\Model\Manga; +use App\Domain\Manga\Domain\Model\ValueObject\ImageUrls; use App\Domain\Manga\Domain\Model\ValueObject\MangaId; use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug; use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle; @@ -37,6 +38,8 @@ class GetMangaBySlugHandlerTest extends TestCase status: 'ongoing', externalId: null, imageUrl: 'https://example.com/image.jpg', + imageUrls: new ImageUrls('https://example.com/image.jpg', 'https://example.com/thumbnail.jpg'), + rating: 4.5 ); $this->repository->save($manga); diff --git a/tests/Feature/Manga/GetMangaBySlugTest.php b/tests/Feature/Manga/GetMangaBySlugTest.php index bd4aa3e..85149aa 100644 --- a/tests/Feature/Manga/GetMangaBySlugTest.php +++ b/tests/Feature/Manga/GetMangaBySlugTest.php @@ -25,6 +25,7 @@ class GetMangaBySlugTest extends AbstractApiTestCase 'genres' => ['Action', 'Adventure'], 'status' => 'ongoing', 'imageUrl' => 'https://example.com/image.jpg', + 'thumbnailUrl' => 'https://example.com/thumbnail.jpg', 'rating' => 4.5, 'monitored' => true ]); @@ -44,7 +45,8 @@ class GetMangaBySlugTest extends AbstractApiTestCase 'genres' => ['Action', 'Adventure'], 'status' => 'ongoing', 'imageUrl' => 'https://example.com/image.jpg', - 'rating' => 4.5 + 'rating' => 4.5, + 'imageUrl' => 'https://example.com/image.jpg', ]); } @@ -52,8 +54,8 @@ class GetMangaBySlugTest extends AbstractApiTestCase { // Act static::createClient()->request('GET', '/api/mangas/by-slug/non-existent-manga'); - + // Assert $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/Feature/Manga/GetMangaListTest.php b/tests/Feature/Manga/GetMangaListTest.php index 962a968..7acc48f 100644 --- a/tests/Feature/Manga/GetMangaListTest.php +++ b/tests/Feature/Manga/GetMangaListTest.php @@ -45,7 +45,7 @@ class GetMangaListTest extends AbstractApiTestCase // Then $this->assertResponseIsSuccessful(); $data = $response->toArray(); - + $this->assertCount(10, $data['items']); $this->assertEquals(25, $data['total']); $this->assertEquals(2, $data['page']); @@ -73,7 +73,7 @@ class GetMangaListTest extends AbstractApiTestCase // Then $this->assertResponseIsSuccessful(); $data = $response->toArray(); - + $this->assertCount(3, $data['items']); $this->assertEquals('Manga A', $data['items'][0]['title']); $this->assertEquals('Manga B', $data['items'][1]['title']); @@ -99,7 +99,9 @@ class GetMangaListTest extends AbstractApiTestCase ->setStatus('ongoing') ->setRating(4.5) ->setMonitored(false) - ; + ->setImageUrl('https://via.placeholder.com/150') + ->setThumbnailUrl('https://via.placeholder.com/150') + ->setCreatedAt(new \DateTimeImmutable('2020-01-01')); $this->entityManager->persist($manga); $this->entityManager->flush(); diff --git a/tests/Feature/Manga/GetMangaTest.php b/tests/Feature/Manga/GetMangaTest.php index 0b584ae..72e9a1e 100644 --- a/tests/Feature/Manga/GetMangaTest.php +++ b/tests/Feature/Manga/GetMangaTest.php @@ -33,6 +33,7 @@ class GetMangaTest extends AbstractApiTestCase ->setStatus('ongoing') ->setExternalId('external-123') ->setImageUrl('http://example.com/image.jpg') + ->setThumbnailUrl('http://example.com/thumbnail.jpg') ->setRating(4.5) ->setMonitored(true); @@ -60,4 +61,4 @@ class GetMangaTest extends AbstractApiTestCase 'rating' => 4.5 ]); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/Feature/Manga/SearchMangaTest.php b/tests/Feature/Manga/SearchMangaTest.php index b59cc22..3c73e5a 100644 --- a/tests/Feature/Manga/SearchMangaTest.php +++ b/tests/Feature/Manga/SearchMangaTest.php @@ -63,10 +63,12 @@ class SearchMangaTest extends AbstractApiTestCase // Then $this->assertResponseIsSuccessful(); + $data = $response->toArray(); - - $this->assertCount(2, $data['items']); - $titles = array_map(fn($item) => $item['title'], $data['items']); + + + $this->assertCount(2, $data['items']['hydra:member']); + $titles = array_map(fn($item) => $item['title'], $data['items']['hydra:member']); $this->assertContains('One Piece', $titles); $this->assertContains('One Punch Man', $titles); } @@ -88,10 +90,10 @@ class SearchMangaTest extends AbstractApiTestCase // Then $this->assertResponseIsSuccessful(); $data = $response->toArray(); - - $this->assertCount(1, $data['items']); - $this->assertEquals('Dragon Ball', $data['items'][0]['title']); - $this->assertEquals('dragon-ball', $data['items'][0]['slug']); + + $this->assertCount(1, $data['items']['hydra:member']); + $this->assertEquals('Dragon Ball', $data['items']['hydra:member'][0]['title']); + $this->assertEquals('dragon-ball', $data['items']['hydra:member'][0]['slug']); } // public function testSearchMangaWithPagination(): void @@ -114,7 +116,7 @@ class SearchMangaTest extends AbstractApiTestCase // // Then // $this->assertResponseIsSuccessful(); // $data = $response->toArray(); - + // $this->assertCount(1, $data['items']); // $this->assertTrue($data['hasNextPage']); // $this->assertTrue($data['hasPreviousPage']); @@ -131,9 +133,12 @@ class SearchMangaTest extends AbstractApiTestCase ->setGenres(['action']) ->setStatus('ongoing') ->setRating(4.5) - ->setMonitored(false); + ->setMonitored(false) + ->setImageUrl('https://via.placeholder.com/150') + ->setThumbnailUrl('https://via.placeholder.com/150') + ->setCreatedAt(new \DateTimeImmutable('2020-01-01')); $this->entityManager->persist($manga); $this->entityManager->flush(); } -} \ No newline at end of file +} \ No newline at end of file