Messages and handlers for the full AI pipeline: DraftArticle → Validation → SpecsResearch → PhotoUpload → EbayText → JsonCoding → PublishToChannel / DeactivateListingMessage / TrackingPush / UpdateStockOnChannels / OrderReceived. OllamaClient and OllamaClientInterface provide the base LLM backend. AI agents (EbayTextAgent, JsonCodingAgent, OllamaVisionAgent, SpecsResearchAgent) wrap the client with task-specific prompts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
85 lines
3.1 KiB
PHP
85 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Infrastructure\Messenger\Handler;
|
|
|
|
use App\Domain\Article\ArticleType;
|
|
use App\Domain\Article\AttributeDefinition;
|
|
use App\Domain\Article\AttributeType;
|
|
use App\Domain\Pipeline\AIPipelineJob;
|
|
use App\Domain\Pipeline\AIPipelineJobType;
|
|
use App\Domain\Pipeline\Repository\AIPipelineJobRepositoryInterface;
|
|
use App\Infrastructure\Messenger\Handler\ValidationHandler;
|
|
use App\Infrastructure\Messenger\Message\DraftArticleMessage;
|
|
use App\Infrastructure\Messenger\Message\JsonCodingMessage;
|
|
use App\Infrastructure\Messenger\Message\ValidationMessage;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Messenger\Envelope;
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
|
final class ValidationHandlerTest extends TestCase
|
|
{
|
|
private AIPipelineJobRepositoryInterface&MockObject $jobRepo;
|
|
private MessageBusInterface&MockObject $bus;
|
|
private AIPipelineJob $job;
|
|
private ValidationHandler $handler;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->jobRepo = $this->createMock(AIPipelineJobRepositoryInterface::class);
|
|
$this->bus = $this->createMock(MessageBusInterface::class);
|
|
$this->handler = new ValidationHandler($this->jobRepo, $this->bus);
|
|
|
|
$this->job = new AIPipelineJob(AIPipelineJobType::Photo, ['test' => true]);
|
|
}
|
|
|
|
public function testDispatchesDraftMessageWhenAllAttributesPresent(): void
|
|
{
|
|
$this->jobRepo->method('findById')->willReturn($this->job);
|
|
|
|
$type = new ArticleType('Notebook');
|
|
$ramDef = new AttributeDefinition('RAM', AttributeType::String);
|
|
$cpuDef = new AttributeDefinition('CPU', AttributeType::String);
|
|
$type->addAttributeDefinition($ramDef);
|
|
$type->addAttributeDefinition($cpuDef);
|
|
|
|
$attributes = [
|
|
$ramDef->getId()->toRfc4122() => '16 GB',
|
|
$cpuDef->getId()->toRfc4122() => 'Intel i7',
|
|
];
|
|
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::isInstanceOf(DraftArticleMessage::class))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
($this->handler)(new ValidationMessage(
|
|
jobId: $this->job->getId()->toRfc4122(),
|
|
articleTypeId: $type->getId()->toRfc4122(),
|
|
specsText: 'some specs',
|
|
attributes: $attributes,
|
|
));
|
|
}
|
|
|
|
public function testRetriesJsonCodingWhenFieldsMissingAndUnderLimit(): void
|
|
{
|
|
$this->jobRepo->method('findById')->willReturn($this->job);
|
|
|
|
$type = new ArticleType('Notebook');
|
|
$type->addAttributeDefinition(new AttributeDefinition('RAM', AttributeType::String));
|
|
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::isInstanceOf(JsonCodingMessage::class))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
($this->handler)(new ValidationMessage(
|
|
jobId: $this->job->getId()->toRfc4122(),
|
|
articleTypeId: $type->getId()->toRfc4122(),
|
|
specsText: 'some specs',
|
|
attributes: [],
|
|
));
|
|
}
|
|
}
|