Initialer Laravel Commit für BetiX
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
2026-04-04 18:01:50 +02:00
commit 0280278978
374 changed files with 65210 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
<?php
namespace Tests\Feature\Gateway;
use App\Models\User;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class SupportChatControllerTest extends TestCase
{
private function base(): string
{
return rtrim((string) config('services.backend.base'), '/');
}
private function actingUser()
{
return User::factory()->create(['email_verified_at' => now()]);
}
public function test_status_success_passthrough()
{
$user = $this->actingUser();
Http::fake([
$this->base() . '/support/status' => Http::response([
'thread_id' => 't-1',
'status' => 'ai',
'messages' => [],
], 200),
]);
$res = $this->actingAs($user, 'web')->get('/api/support/status');
$res->assertStatus(200)
->assertJson([
'thread_id' => 't-1',
'status' => 'ai',
]);
}
public function test_status_client_error_maps_to_client_error()
{
Http::fake([
$this->base() . '/support/status' => Http::response(['message' => 'Invalid'], 400),
]);
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/support/status');
$res->assertStatus(400)
->assertJson([
'error' => 'client_error',
]);
}
public function test_status_server_error_maps_to_503()
{
Http::fake([
$this->base() . '/support/status' => Http::response(['message' => 'Oops'], 500),
]);
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/support/status');
$res->assertStatus(503)
->assertJson([
'error' => 'service_unavailable',
]);
}
public function test_start_success()
{
Http::fake([
$this->base() . '/support/start' => Http::response([
'thread_id' => 't-2',
'status' => 'ai',
], 200),
]);
$res = $this->actingAs($this->actingUser(), 'web')->postJson('/api/support/start', ['topic' => 'Konto']);
$res->assertStatus(200)->assertJson([
'thread_id' => 't-2',
'status' => 'ai',
]);
}
public function test_message_success()
{
Http::fake([
$this->base() . '/support/message' => Http::response(['ok' => true], 200),
]);
$res = $this->actingAs($this->actingUser(), 'web')->postJson('/api/support/message', ['text' => 'Hallo']);
$res->assertStatus(200);
}
public function test_stop_handoff_close_success()
{
Http::fake([
$this->base() . '/support/stop' => Http::response(['success' => true], 200),
$this->base() . '/support/handoff' => Http::response(['success' => true], 200),
$this->base() . '/support/close' => Http::response(['success' => true], 200),
]);
$this->actingAs($this->actingUser(), 'web')->postJson('/api/support/stop')->assertStatus(200);
$this->actingAs($this->actingUser(), 'web')->postJson('/api/support/handoff')->assertStatus(200);
$this->actingAs($this->actingUser(), 'web')->postJson('/api/support/close')->assertStatus(200);
}
public function test_stream_failure_maps_to_503()
{
Http::fake([
$this->base() . '/support/stream' => Http::response(['message' => 'Down'], 500),
]);
$res = $this->actingAs($this->actingUser(), 'web')->get('/api/support/stream');
$res->assertStatus(503)
->assertJson([
'error' => 'service_unavailable',
]);
}
}