Use Dokploy projects in dashboard widget
This commit is contained in:
114
tests/Feature/DokployPlatformHealthWidgetTest.php
Normal file
114
tests/Feature/DokployPlatformHealthWidgetTest.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user