Files
Mangarr/tests/Feature/Scraping/ScrapeChapterTest.php
ext.jeremy.guillot@maxicoffee.domains e3d380eadd feat: GetMangaList endpoint + tests + test db
2025-02-10 19:21:14 +01:00

73 lines
2.1 KiB
PHP

<?php
namespace App\Tests\Feature\Scraping;
use App\Domain\Scraping\Application\Command\ScrapeChapter;
use App\Tests\Domain\Scraping\Adapter\InMemoryMessageBus;
use App\Tests\Feature\AbstractApiTestCase;
use Symfony\Component\Messenger\MessageBusInterface;
class ScrapeChapterTest extends AbstractApiTestCase
{
private MessageBusInterface|InMemoryMessageBus $messageBus;
protected function setUp(): void
{
parent::setUp();
$this->messageBus = self::getContainer()->get(MessageBusInterface::class);
}
public function testInitiateChapterScraping(): void
{
// Given
$payload = [
'chapterId' => 'chapter-123',
'sourceId' => 'source-456',
'mangaId' => 'manga-789',
];
// When
$response = static::createClient()->request('POST', '/api/scraping/chapters', [
'json' => $payload,
'headers' => ['Accept' => 'application/json'],
]);
// Then
$this->assertResponseStatusCodeSame(202);
$messages = $this->messageBus->getDispatchedMessages();
$this->assertCount(1, $messages, 'Un message devrait être dispatché');
/** @var ScrapeChapter $message */
$message = $messages[0];
$this->assertInstanceOf(ScrapeChapter::class, $message);
}
public function testInitiateChapterScrapingWithInvalidPayload(): void
{
// Given
$payload = [
'chapterId' => '',
'sourceId' => 'source-456',
'mangaId' => 'manga-789',
];
// When
$response = static::createClient()->request('POST', '/api/scraping/chapters', [
'json' => $payload,
'headers' => ['Accept' => 'application/json'],
]);
// Then
$this->assertResponseStatusCodeSame(422);
$this->assertJsonContains([
'violations' => [
[
'propertyPath' => 'chapterId',
'message' => 'This value should not be blank.',
],
],
]);
}
}