feat: firsts endpoints and firsts tests
This commit is contained in:
parent
89570ad951
commit
6bc3696190
69
tests/Feature/Scraping/ScrapingStatusTest.php
Normal file
69
tests/Feature/Scraping/ScrapingStatusTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Feature\Scraping;
|
||||
|
||||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||||
use App\Domain\Scraping\Domain\Model\ScrapingJob;
|
||||
use App\Domain\Scraping\Domain\Model\ScrapingStatus;
|
||||
use App\Domain\Scraping\Domain\Model\ValueObject\ImageUrl;
|
||||
use App\Domain\Scraping\Domain\Model\ValueObject\PageNumber;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use App\Domain\Scraping\Domain\Contract\Repository\ScrapingJobRepositoryInterface;
|
||||
|
||||
class ScrapingStatusTest extends ApiTestCase
|
||||
{
|
||||
private MessageBusInterface $messageBus;
|
||||
private ScrapingJobRepositoryInterface $repository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
self::bootKernel();
|
||||
|
||||
$this->messageBus = self::getContainer()->get(MessageBusInterface::class);
|
||||
$this->repository = self::getContainer()->get(ScrapingJobRepositoryInterface::class);
|
||||
}
|
||||
|
||||
public function testGetScrapingStatus(): void
|
||||
{
|
||||
// Given
|
||||
$jobId = Uuid::uuid4()->toString();
|
||||
$job = new ScrapingJob($jobId, 'manga-123', 'chapter-456', 'source-789');
|
||||
|
||||
$job->addPage(new PageNumber(1), new ImageUrl('http://example.com/page1.jpg'));
|
||||
$job->addPage(new PageNumber(2), new ImageUrl('http://example.com/page2.jpg'));
|
||||
|
||||
$this->repository->save($job);
|
||||
|
||||
// When
|
||||
$response = static::createClient()->request('GET', '/api/scraping/jobs/'.$jobId.'/status');
|
||||
|
||||
// Then
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertJsonContains([
|
||||
'jobId' => $jobId,
|
||||
'status' => ScrapingStatus::IN_PROGRESS->value,
|
||||
'progress' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetScrapingStatusForNonExistentJob(): void
|
||||
{
|
||||
// When
|
||||
$response = static::createClient()->request('GET', '/api/scraping/jobs/non-existent-id/status', [
|
||||
'headers' => ['Accept' => 'application/json']
|
||||
]);
|
||||
|
||||
// Then
|
||||
$this->assertResponseStatusCodeSame(404);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user