Add unit and feature tests for ticket processing and article management
- Implement Fake repositories and services for testing purposes. - Create tests for Article API including creation, validation, and listing. - Develop ProcessTicketJobFlowTest to validate ticket processing logic. - Add QuickReplyAdminTest for creating and updating quick replies. - Implement TicketAndArticleModelTest to ensure proper cascading deletes and credential encryption. - Create TicketIngestionTest for ticket creation and job dispatching. - Add TicketShowPageTest to verify rendering of quick replies and tool calls. - Implement unit tests for ClassifierPromptBuilder, EmbeddingService, LlmJsonDecoder, QuickReplyResolver, SupportReplyService, TicketResultPayloadBuilder, TicketToolCallService, and ToolCallRequestValidator.
This commit is contained in:
17
tests/Fakes/FakeArticleRepository.php
Normal file
17
tests/Fakes/FakeArticleRepository.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\DTOs\ArticleCandidateDTO;
|
||||
use App\Repositories\Contracts\ArticleRepositoryInterface;
|
||||
|
||||
class FakeArticleRepository implements ArticleRepositoryInterface
|
||||
{
|
||||
/** @var array<int, ArticleCandidateDTO> */
|
||||
public array $candidates = [];
|
||||
|
||||
public function findSimilarByEmbedding(array $embedding, int $limit = 5, array $embeddingContext = []): array
|
||||
{
|
||||
return array_slice($this->candidates, 0, $limit);
|
||||
}
|
||||
}
|
||||
29
tests/Fakes/FakeDomainInfoTool.php
Normal file
29
tests/Fakes/FakeDomainInfoTool.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Services\Tools\DomainInfoTool;
|
||||
use App\Services\Tools\OxxaClient;
|
||||
|
||||
class FakeDomainInfoTool extends DomainInfoTool
|
||||
{
|
||||
/** @var array<int, array{parameters:array,credentials:array}> */
|
||||
public array $calls = [];
|
||||
|
||||
public array $response = ['ok' => true, 'data' => ['domain' => 'example.nl']];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new OxxaClient);
|
||||
}
|
||||
|
||||
public function execute(array $parameters, array $credentials): array
|
||||
{
|
||||
$this->calls[] = [
|
||||
'parameters' => $parameters,
|
||||
'credentials' => $credentials,
|
||||
];
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
}
|
||||
32
tests/Fakes/FakeLlmClient.php
Normal file
32
tests/Fakes/FakeLlmClient.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Services\Llm\LlmClientInterface;
|
||||
|
||||
class FakeLlmClient implements LlmClientInterface
|
||||
{
|
||||
/** @var array<string, array<int, float>> */
|
||||
public array $embeddings = [];
|
||||
|
||||
/** @var array<int, string> */
|
||||
public array $responses = [];
|
||||
|
||||
/** @var array<int, array{prompt:string, options:array}> */
|
||||
public array $generatedPrompts = [];
|
||||
|
||||
public function embed(string $text): array
|
||||
{
|
||||
return $this->embeddings[$text] ?? [0.1, 0.2, 0.3];
|
||||
}
|
||||
|
||||
public function generate(string $prompt, array $options = []): string
|
||||
{
|
||||
$this->generatedPrompts[] = [
|
||||
'prompt' => $prompt,
|
||||
'options' => $options,
|
||||
];
|
||||
|
||||
return array_shift($this->responses) ?? '{}';
|
||||
}
|
||||
}
|
||||
22
tests/Fakes/FakeTicketProcessingLoggerService.php
Normal file
22
tests/Fakes/FakeTicketProcessingLoggerService.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use App\Services\TicketProcessingLoggerService;
|
||||
|
||||
class FakeTicketProcessingLoggerService extends TicketProcessingLoggerService
|
||||
{
|
||||
/** @var array<int, array{step:string,status:string,message:string|null,context:array}> */
|
||||
public array $logs = [];
|
||||
|
||||
public function log(Ticket $ticket, string $step, string $status = 'info', ?string $message = null, array $context = []): void
|
||||
{
|
||||
$this->logs[] = [
|
||||
'step' => $step,
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'context' => $context,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user