Files
coolify/tests/Feature/Service/EditDomainPortValidationTest.php
T
Andras BacsaiandClaude Opus 5.5 a79ee909c6 chore: remove unused components and markup-only tests
- Delete Blade components, component classes, Livewire components and
  views that nothing uses after the redesign.
- Delete tests that only compare Blade/CSS source text; keep the source
  checks for authorization gates, stable wire:key values and escaping.
- Update stale tests to the current UI and behaviour.
- Update DESIGN.md to the current navigation and layout.
- Add a lesson: test behaviour, not source markup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 00:18:16 +02:00

155 lines
5.3 KiB
PHP

<?php
use App\Livewire\Project\Service\Domains;
use App\Livewire\Project\Service\Index;
use App\Models\Environment;
use App\Models\InstanceSettings;
use App\Models\Project;
use App\Models\Server;
use App\Models\Service;
use App\Models\ServiceApplication;
use App\Models\StandaloneDocker;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->withoutVite();
InstanceSettings::forceCreate(['id' => 0]);
// Create user and team
$this->user = User::factory()->create();
$this->team = Team::factory()->create();
$this->user->teams()->attach($this->team, ['role' => 'owner']);
$this->actingAs($this->user);
session(['currentTeam' => $this->team]);
// Create server
$this->server = Server::factory()->create([
'team_id' => $this->team->id,
]);
// Create standalone docker destination
$this->destination = StandaloneDocker::where('server_id', $this->server->id)->firstOrFail();
// Create project and environment
$this->project = Project::factory()->create([
'team_id' => $this->team->id,
]);
$this->environment = Environment::factory()->create([
'project_id' => $this->project->id,
]);
// Create service with a name that maps to a template with required port
$this->service = Service::factory()->create([
'name' => 'supabase-test123',
'service_type' => 'supabase',
'server_id' => $this->server->id,
'destination_id' => $this->destination->id,
'destination_type' => $this->destination->getMorphClass(),
'environment_id' => $this->environment->id,
]);
// Create service application
$this->serviceApplication = ServiceApplication::create([
'service_id' => $this->service->id,
'name' => 'web',
'image' => 'nginx:alpine',
'fqdn' => 'http://example.com:8000',
]);
// Mock get_service_templates to return a service with required port
if (! function_exists('get_service_templates_mock')) {
function get_service_templates_mock()
{
return collect([
'supabase' => [
'name' => 'Supabase',
'port' => '8000',
'documentation' => 'https://supabase.com',
],
]);
}
}
});
it('loads a persisted port override in the service application editor', function () {
$this->serviceApplication->update([
'fqdn' => 'https://web.example.com',
'domain_port_overrides' => [
'https://web.example.com' => 8080,
],
]);
Livewire::test(Index::class, [
'serviceApplication' => $this->serviceApplication->fresh(),
'parameters' => [
'project_uuid' => $this->project->uuid,
'environment_uuid' => $this->environment->uuid,
'service_uuid' => $this->service->uuid,
'stack_service_uuid' => $this->serviceApplication->uuid,
],
'query' => [],
])
->assertSet('fqdn', 'https://web.example.com:8080')
->assertOk();
});
it('preserves a legacy embedded port when only the description changes', function () {
ServiceApplication::query()->whereKey($this->serviceApplication->id)->update([
'fqdn' => 'http://example.com:8080',
'domain_port_overrides' => null,
]);
Livewire::test(Index::class, [
'serviceApplication' => $this->serviceApplication->fresh(),
])
->set('description', 'Updated description')
->call('submitApplication')
->assertHasNoErrors()
->assertSet('showPortWarningModal', false)
->assertSet('fqdn', 'http://example.com:8080');
expect($this->serviceApplication->fresh())
->description->toBe('Updated description')
->fqdn->toBe('http://example.com')
->domain_port_overrides->toBe(['http://example.com' => 8080]);
});
it('prefers a persisted override over a legacy embedded port', function () {
ServiceApplication::query()->whereKey($this->serviceApplication->id)->update([
'fqdn' => 'http://example.com:8080',
'domain_port_overrides' => json_encode(['http://example.com' => 3000]),
]);
expect($this->serviceApplication->fresh()->url)->toBe('http://example.com:3000');
});
it('initializes route state when mounting a service application directly', function () {
Livewire::test(Index::class, [
'serviceApplication' => $this->serviceApplication,
])
->assertSet('parameters', [
'project_uuid' => $this->project->uuid,
'environment_uuid' => $this->environment->uuid,
'service_uuid' => $this->service->uuid,
'stack_service_uuid' => $this->serviceApplication->uuid,
])
->assertSet('query', [])
->assertOk();
});
it('marks noindex changes as pending configuration', function () {
$this->service->isConfigurationChanged(save: true);
Livewire::test(Domains::class, ['service' => $this->service->fresh(['applications', 'server'])])
->call('toggleNoindexDomain', $this->serviceApplication->id, 'http://example.com:8000', true)
->assertDispatched('configurationChanged');
expect($this->service->refresh()->isConfigurationChanged())->toBeTrue();
});