115 lines
3.4 KiB
PHP
115 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Filament\Widgets\DokployPlatformHealth;
|
|
use App\Services\Dokploy\DokployClient;
|
|
use Livewire\Livewire;
|
|
use Mockery;
|
|
use Tests\TestCase;
|
|
|
|
class DokployPlatformHealthWidgetTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_widget_uses_projects_when_configured(): void
|
|
{
|
|
config()->set('dokploy.projects', [
|
|
'core' => 'proj_1',
|
|
]);
|
|
|
|
$fakeClient = Mockery::mock(DokployClient::class);
|
|
$fakeClient->shouldReceive('findProject')
|
|
->with('proj_1')
|
|
->andReturn([
|
|
'projectId' => 'proj_1',
|
|
'name' => 'Core',
|
|
'description' => 'Main stack',
|
|
'updatedAt' => now()->toIso8601String(),
|
|
'applications' => [
|
|
[
|
|
'applicationId' => 'app_1',
|
|
'name' => 'API',
|
|
'applicationStatus' => 'running',
|
|
'repository' => 'repo/api',
|
|
'branch' => 'main',
|
|
],
|
|
],
|
|
'redis' => [
|
|
[
|
|
'redisId' => 'redis_1',
|
|
'name' => 'Redis',
|
|
'applicationStatus' => 'done',
|
|
'externalPort' => 6379,
|
|
],
|
|
],
|
|
]);
|
|
|
|
$fakeClient->shouldReceive('applicationStatus')
|
|
->with('app_1')
|
|
->andReturn([
|
|
'application' => [
|
|
'name' => 'API',
|
|
'applicationStatus' => 'running',
|
|
'updatedAt' => now()->toIso8601String(),
|
|
],
|
|
'monitoring' => [
|
|
'cpuPercent' => 12,
|
|
],
|
|
]);
|
|
|
|
$this->app->instance(DokployClient::class, $fakeClient);
|
|
|
|
Livewire::test(DokployPlatformHealth::class)
|
|
->assertStatus(200)
|
|
->assertSee('Core')
|
|
->assertSee('API')
|
|
->assertSee('Redis');
|
|
}
|
|
|
|
public function test_widget_falls_back_to_compose_status_when_projects_missing(): void
|
|
{
|
|
config()->set('dokploy.projects', []);
|
|
config()->set('dokploy.composes', [
|
|
'stack' => 'cmp_main',
|
|
]);
|
|
|
|
$fakeClient = Mockery::mock(DokployClient::class);
|
|
$fakeClient->shouldReceive('composeStatus')
|
|
->with('cmp_main')
|
|
->andReturn([
|
|
'compose' => [
|
|
'name' => 'Main Stack',
|
|
'composeStatus' => 'done',
|
|
'updatedAt' => now()->toIso8601String(),
|
|
],
|
|
'services' => [
|
|
[
|
|
'serviceName' => 'web',
|
|
'status' => 'running',
|
|
],
|
|
],
|
|
]);
|
|
|
|
$fakeClient->shouldReceive('composeDeployments')
|
|
->with('cmp_main', 1)
|
|
->andReturn([
|
|
[
|
|
'createdAt' => now()->toIso8601String(),
|
|
],
|
|
]);
|
|
|
|
$this->app->instance(DokployClient::class, $fakeClient);
|
|
|
|
Livewire::test(DokployPlatformHealth::class)
|
|
->assertStatus(200)
|
|
->assertSee('Main Stack')
|
|
->assertSee('web');
|
|
}
|
|
}
|