Files
fotospiel-app/tests/Feature/DokployPlatformHealthWidgetTest.php
Codex Agent 87f348462b
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Load Dokploy project details for compose data
2026-01-29 11:00:53 +01:00

147 lines
4.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('project')
->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',
],
],
'compose' => [
[
'composeId' => 'cmp_1',
'name' => 'Main Compose',
'composeStatus' => 'done',
],
],
'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,
],
]);
$fakeClient->shouldReceive('composeStatus')
->with('cmp_1')
->andReturn([
'compose' => [
'name' => 'Main Compose',
'composeStatus' => 'done',
'updatedAt' => now()->toIso8601String(),
],
'services' => [
[
'serviceName' => 'web',
'status' => 'running',
],
],
]);
$fakeClient->shouldReceive('composeDeployments')
->with('cmp_1', 1)
->andReturn([
[
'createdAt' => now()->toIso8601String(),
],
]);
$this->app->instance(DokployClient::class, $fakeClient);
Livewire::test(DokployPlatformHealth::class)
->assertStatus(200)
->assertSee('Core')
->assertSee('API')
->assertSee('Main Compose')
->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');
}
}