70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?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', 1, '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();
|
|
}
|
|
}
|