2026-03-13 16:02:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Models\Application;
|
|
|
|
|
use App\Models\ApplicationPreview;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
|
|
|
|
it('populates fqdn from docker_compose_domains after generate_preview_fqdn_compose', function () {
|
|
|
|
|
$application = Application::factory()->create([
|
|
|
|
|
'build_pack' => 'dockercompose',
|
|
|
|
|
'docker_compose_domains' => json_encode([
|
|
|
|
|
'web' => ['domain' => 'https://example.com'],
|
|
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-30 11:04:11 +00:00
|
|
|
$preview = ApplicationPreview::forceCreate([
|
2026-03-13 16:02:05 +00:00
|
|
|
'application_id' => $application->id,
|
|
|
|
|
'pull_request_id' => 42,
|
2026-03-30 11:04:11 +00:00
|
|
|
'pull_request_html_url' => 'https://github.com/example/repo/pull/42',
|
2026-03-13 16:02:05 +00:00
|
|
|
'docker_compose_domains' => $application->docker_compose_domains,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$preview->generate_preview_fqdn_compose();
|
|
|
|
|
|
|
|
|
|
$preview->refresh();
|
|
|
|
|
|
|
|
|
|
expect($preview->fqdn)->not->toBeNull();
|
|
|
|
|
expect($preview->fqdn)->toContain('42');
|
|
|
|
|
expect($preview->fqdn)->toContain('example.com');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('populates fqdn with multiple domains from multiple services', function () {
|
|
|
|
|
$application = Application::factory()->create([
|
|
|
|
|
'build_pack' => 'dockercompose',
|
|
|
|
|
'docker_compose_domains' => json_encode([
|
|
|
|
|
'web' => ['domain' => 'https://web.example.com'],
|
|
|
|
|
'api' => ['domain' => 'https://api.example.com'],
|
|
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-30 11:04:11 +00:00
|
|
|
$preview = ApplicationPreview::forceCreate([
|
2026-03-13 16:02:05 +00:00
|
|
|
'application_id' => $application->id,
|
|
|
|
|
'pull_request_id' => 7,
|
2026-03-30 11:04:11 +00:00
|
|
|
'pull_request_html_url' => 'https://github.com/example/repo/pull/7',
|
2026-03-13 16:02:05 +00:00
|
|
|
'docker_compose_domains' => $application->docker_compose_domains,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$preview->generate_preview_fqdn_compose();
|
|
|
|
|
|
|
|
|
|
$preview->refresh();
|
|
|
|
|
|
|
|
|
|
expect($preview->fqdn)->not->toBeNull();
|
|
|
|
|
$domains = explode(',', $preview->fqdn);
|
|
|
|
|
expect($domains)->toHaveCount(2);
|
|
|
|
|
expect($preview->fqdn)->toContain('web.example.com');
|
|
|
|
|
expect($preview->fqdn)->toContain('api.example.com');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('sets fqdn to null when no domains are configured', function () {
|
|
|
|
|
$application = Application::factory()->create([
|
|
|
|
|
'build_pack' => 'dockercompose',
|
|
|
|
|
'docker_compose_domains' => json_encode([
|
|
|
|
|
'web' => ['domain' => ''],
|
|
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-30 11:04:11 +00:00
|
|
|
$preview = ApplicationPreview::forceCreate([
|
2026-03-13 16:02:05 +00:00
|
|
|
'application_id' => $application->id,
|
|
|
|
|
'pull_request_id' => 99,
|
2026-03-30 11:04:11 +00:00
|
|
|
'pull_request_html_url' => 'https://github.com/example/repo/pull/99',
|
2026-03-13 16:02:05 +00:00
|
|
|
'docker_compose_domains' => $application->docker_compose_domains,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$preview->generate_preview_fqdn_compose();
|
|
|
|
|
|
|
|
|
|
$preview->refresh();
|
|
|
|
|
|
|
|
|
|
expect($preview->fqdn)->toBeNull();
|
|
|
|
|
});
|