feat: firsts endpoints and firsts tests
This commit is contained in:
parent
89570ad951
commit
6bc3696190
71
tests/Feature/Scraping/ScrapeChapterTest.php
Normal file
71
tests/Feature/Scraping/ScrapeChapterTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Feature\Scraping;
|
||||
|
||||
use App\Domain\Scraping\Application\Command\ScrapeChapter;
|
||||
use App\Tests\Domain\Scraping\Adapter\InMemoryMessageBus;
|
||||
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::$messages;
|
||||
$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.',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user