feat: scraping endpoints, job persistence, firsts unit tests, legacy entities usage

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-07 11:56:51 +01:00
parent c55cd62ec7
commit 0374ab0e46
34 changed files with 348 additions and 326 deletions

View File

@@ -8,21 +8,8 @@ use Ramsey\Uuid\Uuid;
class InMemoryScraperAdapter implements ScraperInterface
{
private array $jobs = [];
private ?\Exception $shouldThrowException = null;
public function createScrapingJob(string $mangaId, string $chapterId, string $sourceId): ScrapingJob
{
if ($this->shouldThrowException) {
throw $this->shouldThrowException;
}
$job = new ScrapingJob(Uuid::uuid4(), $mangaId, $chapterId, $sourceId);
$this->jobs[] = $job;
return $job;
}
public function scrape(ScrapingJob $job): void
{
if ($this->shouldThrowException) {
@@ -35,11 +22,6 @@ class InMemoryScraperAdapter implements ScraperInterface
$this->shouldThrowException = $exception;
}
public function getJobs(): array
{
return $this->jobs;
}
public function supports(string $sourceType): bool
{
return true;

View File

@@ -33,14 +33,14 @@ class ScrapeChapterHandlerTest extends TestCase
public function testHandleSuccessfully(): void
{
$command = new ScrapeChapter(
chapterId: 2,
mangaId: 1,
chapterNumber: 2,
sourceId: 3,
mangaId: 1
);
$this->handler->handle($command);
$scrapingJobs = $this->scraper->getJobs();
$scrapingJobs = $this->repository->getJobs();
$this->assertCount(1, $scrapingJobs);
$job = $scrapingJobs[0];
@@ -57,9 +57,9 @@ class ScrapeChapterHandlerTest extends TestCase
public function testHandleThrowsException(): void
{
$command = new ScrapeChapter(
chapterId: 2,
mangaId: 1,
chapterNumber: 2,
sourceId: 3,
mangaId: 1
);
$exception = new \Exception('Scraping failed');
@@ -72,10 +72,11 @@ class ScrapeChapterHandlerTest extends TestCase
$this->handler->handle($command);
} finally {
$dispatchedMessages = $this->eventBus->getDispatchedMessages();
$this->assertCount(1, $dispatchedMessages);
$this->assertInstanceOf(ChapterScrapingFailed::class, $dispatchedMessages[0]);
$this->assertEquals(2, $dispatchedMessages[0]->getChapterId());
$this->assertEquals('Scraping failed', $dispatchedMessages[0]->getReason());
$this->assertCount(2, $dispatchedMessages);
$this->assertInstanceOf(ChapterScrapingStarted::class, $dispatchedMessages[0]);
$this->assertInstanceOf(ChapterScrapingFailed::class, $dispatchedMessages[1]);
$this->assertEquals(2, $dispatchedMessages[1]->getChapterNumber());
$this->assertEquals('Scraping failed', $dispatchedMessages[1]->getReason());
}
}
}