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:
SitiWeb
2026-04-30 02:10:15 +02:00
parent 39bdba2dfb
commit c94d3f85e8
36 changed files with 7445 additions and 467 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace Tests\Feature;
use App\Models\Article;
use App\Models\QuickReply;
use App\Models\Ticket;
use App\Models\TicketToolCall;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class TicketAndArticleModelTest extends TestCase
{
use RefreshDatabase;
public function test_article_quick_reply_pivot_and_cascade_delete(): void
{
$article = Article::query()->create(['title' => 'DNS', 'content' => 'x']);
$reply = QuickReply::query()->create(['title' => 'Quick', 'content' => 'y', 'is_active' => true]);
$article->quickReplies()->sync([$reply->id]);
$this->assertCount(1, $article->quickReplies);
$article->delete();
$pivotCount = DB::table('article_quick_reply')->count();
$this->assertSame(0, $pivotCount);
}
public function test_ticket_credentials_are_stored_encrypted_and_decrypted_via_cast(): void
{
$ticket = Ticket::query()->create([
'message' => 'vraag',
'api_credentials' => ['apiuser' => 'demo', 'apipassword' => 'secret'],
]);
$this->assertSame('demo', $ticket->api_credentials['apiuser']);
$raw = DB::table('tickets')->where('id', $ticket->id)->value('api_credentials');
$this->assertIsString($raw);
$this->assertStringNotContainsString('secret', $raw);
}
public function test_ticket_tool_call_casts_arrays(): void
{
$ticket = Ticket::query()->create(['message' => 'vraag']);
$article = Article::query()->create(['title' => 'DNS', 'content' => 'x']);
$toolCall = TicketToolCall::query()->create([
'ticket_id' => $ticket->id,
'article_id' => $article->id,
'action' => 'domain_inf',
'status' => 'success',
'parameters' => ['sld' => 'example', 'tld' => 'nl'],
'response' => ['ok' => true],
]);
$toolCall->refresh();
$this->assertSame('example', $toolCall->parameters['sld']);
$this->assertTrue($toolCall->response['ok']);
}
}