feat: activity page

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2026-03-11 20:54:55 +01:00
parent f418b36167
commit 19395b4869
21 changed files with 625 additions and 35 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Tests\Domain\Shared\Adapter;
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
use App\Domain\Shared\Domain\Exception\JobNotFoundException;
use App\Domain\Shared\Domain\Model\Job;
use App\Domain\Shared\Domain\Model\JobStatus;
@@ -97,6 +98,26 @@ class InMemoryJobRepository implements JobRepositoryInterface
return count($this->findByCriteria($criteria));
}
public function delete(string $id): void
{
if (!isset($this->jobs[$id])) {
throw JobNotFoundException::withId($id);
}
unset($this->jobs[$id]);
}
public function deleteByCriteria(array $criteria): int
{
$toDelete = $this->findByCriteria($criteria);
foreach ($toDelete as $job) {
unset($this->jobs[$job->id]);
}
return count($toDelete);
}
public function clear(): void
{
$this->jobs = [];

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace App\Tests\Domain\Shared\Application\CommandHandler;
use App\Domain\Scraping\Domain\Model\ScrapingJob;
use App\Domain\Shared\Application\Command\DeleteJob;
use App\Domain\Shared\Application\CommandHandler\DeleteJobHandler;
use App\Domain\Shared\Domain\Exception\JobNotFoundException;
use App\Tests\Domain\Shared\Adapter\InMemoryJobRepository;
use PHPUnit\Framework\TestCase;
class DeleteJobHandlerTest extends TestCase
{
private InMemoryJobRepository $repository;
private DeleteJobHandler $handler;
protected function setUp(): void
{
$this->repository = new InMemoryJobRepository();
$this->handler = new DeleteJobHandler($this->repository);
}
public function test_it_deletes_existing_job(): void
{
$job = new ScrapingJob('job-1', 'manga-1', 1.0, 'source-1');
$this->repository->save($job);
$this->handler->handle(new DeleteJob('job-1'));
$this->assertNull($this->repository->get('job-1'));
}
public function test_it_throws_when_job_not_found(): void
{
$this->expectException(JobNotFoundException::class);
$this->handler->handle(new DeleteJob('non-existent-id'));
}
}

View File

@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace App\Tests\Domain\Shared\Application\CommandHandler;
use App\Domain\Scraping\Domain\Model\ScrapingJob;
use App\Domain\Shared\Application\Command\DeleteJobsByCriteria;
use App\Domain\Shared\Application\CommandHandler\DeleteJobsByCriteriaHandler;
use App\Domain\Shared\Domain\Model\JobStatus;
use App\Tests\Domain\Shared\Adapter\InMemoryJobRepository;
use PHPUnit\Framework\TestCase;
class DeleteJobsByCriteriaHandlerTest extends TestCase
{
private InMemoryJobRepository $repository;
private DeleteJobsByCriteriaHandler $handler;
protected function setUp(): void
{
$this->repository = new InMemoryJobRepository();
$this->handler = new DeleteJobsByCriteriaHandler($this->repository);
}
public function test_it_deletes_jobs_by_status(): void
{
$job1 = new ScrapingJob('job-1', 'manga-1', 1.0, 'source-1');
$job2 = new ScrapingJob('job-2', 'manga-1', 2.0, 'source-1');
$job3 = new ScrapingJob('job-3', 'manga-1', 3.0, 'source-1');
$job2->complete();
$job3->complete();
$this->repository->save($job1);
$this->repository->save($job2);
$this->repository->save($job3);
$this->handler->handle(new DeleteJobsByCriteria(
statuses: [JobStatus::COMPLETED]
));
$this->assertNull($this->repository->get('job-2'));
$this->assertNull($this->repository->get('job-3'));
$this->assertNotNull($this->repository->get('job-1'));
}
public function test_it_deletes_jobs_by_type(): void
{
$job1 = new ScrapingJob('job-1', 'manga-1', 1.0, 'source-1');
$job2 = new ScrapingJob('job-2', 'manga-1', 2.0, 'source-1');
$this->repository->save($job1);
$this->repository->save($job2);
$this->handler->handle(new DeleteJobsByCriteria(
type: 'scraping_job'
));
$this->assertNull($this->repository->get('job-1'));
$this->assertNull($this->repository->get('job-2'));
}
public function test_it_does_nothing_when_no_criteria_match(): void
{
$job = new ScrapingJob('job-1', 'manga-1', 1.0, 'source-1');
$this->repository->save($job);
$this->handler->handle(new DeleteJobsByCriteria(
statuses: [JobStatus::FAILED]
));
$this->assertNotNull($this->repository->get('job-1'));
}
}