Initialer Laravel Commit für BetiX
This commit is contained in:
116
tests/Feature/Gateway/SupportChatControllerTest.php
Normal file
116
tests/Feature/Gateway/SupportChatControllerTest.php
Normal 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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user