feat: endpoint FetchMangaChapters et tests
This commit is contained in:
parent
3dc0a0b406
commit
879b8fa2dc
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Domain\Manga\Application\CommandHandler;
|
||||
|
||||
use App\Domain\Manga\Application\Command\FetchMangaChapters;
|
||||
use App\Domain\Manga\Application\CommandHandler\FetchMangaChaptersHandler;
|
||||
use App\Domain\Manga\Domain\Model\Manga;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ExternalId;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaId;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle;
|
||||
use App\Tests\Domain\Manga\Adapter\InMemoryMangadexClient;
|
||||
use App\Tests\Domain\Manga\Adapter\InMemoryMangaRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FetchMangaChaptersHandlerTest extends TestCase
|
||||
{
|
||||
private InMemoryMangadexClient $mangadexClient;
|
||||
private InMemoryMangaRepository $mangaRepository;
|
||||
private FetchMangaChaptersHandler $handler;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->mangadexClient = new InMemoryMangadexClient();
|
||||
$this->mangaRepository = new InMemoryMangaRepository();
|
||||
$this->handler = new FetchMangaChaptersHandler(
|
||||
$this->mangadexClient,
|
||||
$this->mangaRepository
|
||||
);
|
||||
}
|
||||
|
||||
public function testHandleWithExistingManga(): void
|
||||
{
|
||||
$externalId = 'manga-123';
|
||||
$manga = new Manga(
|
||||
new MangaId('manga-id'),
|
||||
new MangaTitle('Test Manga'),
|
||||
new MangaSlug('test-manga'),
|
||||
'Description',
|
||||
'Author',
|
||||
2024,
|
||||
[],
|
||||
'ongoing',
|
||||
new ExternalId($externalId)
|
||||
);
|
||||
|
||||
$this->mangaRepository->save($manga);
|
||||
|
||||
$this->mangadexClient->setMangaFeed($externalId, [
|
||||
'data' => [
|
||||
[
|
||||
'id' => 'chapter-1',
|
||||
'attributes' => [
|
||||
'chapter' => '1',
|
||||
'title' => 'Chapter 1',
|
||||
'volume' => '1'
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$command = new FetchMangaChapters($externalId);
|
||||
$this->handler->handle($command);
|
||||
|
||||
$this->assertCount(1, $this->mangaRepository->getSavedChapters());
|
||||
}
|
||||
|
||||
public function testHandleWithNonExistingManga(): void
|
||||
{
|
||||
$externalId = 'non-existing-manga';
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('Manga not found');
|
||||
|
||||
$command = new FetchMangaChapters($externalId);
|
||||
$this->handler->handle($command);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user