60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Gateway;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class AdminSupportAdminControllerTest extends TestCase
|
|
{
|
|
private function base(): string { return rtrim((string) config('services.backend.base'), '/'); }
|
|
|
|
private function adminUser()
|
|
{
|
|
if (class_exists(User::class) && method_exists(User::class, 'factory')) {
|
|
return User::factory()->make(['id' => 1201, 'username' => 'admin', 'role' => 'Admin', 'email_verified_at' => now()]);
|
|
}
|
|
return new class { public $id=1201; public $username='admin'; public $role='Admin'; };
|
|
}
|
|
|
|
public function test_index_renders_with_threads()
|
|
{
|
|
Http::fake([
|
|
$this->base() . '/admin/support' => Http::response([
|
|
'enabled' => true,
|
|
'threads' => [ ['id' => 't-1', 'status' => 'ai'] ],
|
|
'ollama' => ['healthy' => true],
|
|
], 200),
|
|
]);
|
|
|
|
$res = $this->actingAs($this->adminUser())->get('/admin/support');
|
|
$res->assertStatus(200);
|
|
}
|
|
|
|
public function test_settings_success_sets_flash()
|
|
{
|
|
Http::fake([
|
|
$this->base() . '/admin/support/settings' => Http::response(['message' => 'OK'], 200),
|
|
]);
|
|
$res = $this->actingAs($this->adminUser())->post('/admin/support/settings', ['enabled' => true]);
|
|
$res->assertSessionHas('success');
|
|
}
|
|
|
|
public function test_reply_and_close_success_set_flash()
|
|
{
|
|
Http::fake([
|
|
$this->base() . '/admin/support/threads/t-1/message' => Http::response(['message' => 'Sent'], 200),
|
|
$this->base() . '/admin/support/threads/t-1/close' => Http::response(['message' => 'Closed'], 200),
|
|
]);
|
|
|
|
$this->actingAs($this->adminUser())
|
|
->post('/admin/support/threads/t-1/message', ['text' => 'hi'])
|
|
->assertSessionHas('success');
|
|
|
|
$this->actingAs($this->adminUser())
|
|
->post('/admin/support/threads/t-1/close')
|
|
->assertSessionHas('success');
|
|
}
|
|
}
|