Files
Mangarr/tests/Feature/Scraping/ScrapeChapterTest.php

78 lines
2.2 KiB
PHP

<?php
namespace App\Tests\Feature\Scraping;
use App\Domain\Scraping\Application\Command\ScrapeChapter;
use App\Tests\Feature\AbstractApiTestCase;
use App\Tests\Shared\Adapter\InMemoryMessageBus;
use Symfony\Component\Messenger\MessageBusInterface;
class ScrapeChapterTest extends AbstractApiTestCase
{
private MessageBusInterface|InMemoryMessageBus $messageBus;
protected function setUp(): void
{
parent::setUp();
$this->messageBus = new InMemoryMessageBus();
$this->container->set(MessageBusInterface::class, $this->messageBus);
$this->messageBus->clear();
}
public function testInitiateChapterScraping(): void
{
// Given
$payload = [
'chapterId' => 'chapter-123',
];
// 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);
$this->assertEquals('chapter-123', $message->chapterId);
}
public function testInitiateChapterScrapingWithInvalidPayload(): void
{
// Given
$payload = [
'chapterId' => '',
];
// 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.',
],
],
]);
}
protected function tearDown(): void
{
parent::tearDown();
$this->messageBus->clear();
}
}