Files
coolify/tests/Feature/SettingsEmailSmtpSetupTest.php
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

153 lines
4.5 KiB
PHP

<?php
use App\Livewire\Notifications\Email as NotificationEmail;
use App\Livewire\SettingsEmail;
use App\Models\InstanceSettings;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Once;
use Livewire\Livewire;
uses(RefreshDatabase::class);
function setupInstanceAdminForEmailSettings(): User
{
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
InstanceSettings::forceCreate([
'id' => 0,
'smtp_enabled' => false,
'resend_enabled' => false,
]);
Once::flush();
$user = User::factory()->create();
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
return $user;
}
function smtpSetupPayload(): array
{
return [
'smtpFromAddress' => 'alerts@example.com',
'smtpFromName' => 'Coolify',
'smtpHost' => 'smtp.example.com',
'smtpPort' => '587',
'smtpEncryption' => 'starttls',
'smtpEhloDomain' => 'coolify.example.com',
'resendEnabled' => false,
'resendApiKey' => null,
];
}
test('saving smtp settings does not require a resend api key when resend is disabled', function () {
$user = setupInstanceAdminForEmailSettings();
$this->actingAs($user);
session(['currentTeam' => ['id' => 0]]);
Livewire::test(SettingsEmail::class)
->fill(smtpSetupPayload())
->set('smtpEnabled', true)
->call('submitSmtp')
->assertHasNoErrors()
->assertNotDispatched('error');
$settings = InstanceSettings::find(0);
expect($settings->smtp_enabled)->toBeTrue()
->and($settings->smtp_host)->toBe('smtp.example.com')
->and($settings->smtp_ehlo_domain)->toBe('coolify.example.com')
->and($settings->resend_enabled)->toBeFalse();
});
test('team smtp settings save their own ehlo domain', function () {
setupInstanceAdminForEmailSettings();
$team = Team::factory()->create();
$user = User::factory()->create();
$team->members()->attach($user->id, ['role' => 'admin']);
$this->actingAs($user);
session(['currentTeam' => $team]);
Livewire::test(NotificationEmail::class)
->fill(smtpSetupPayload())
->set('smtpEnabled', true)
->call('submitSmtp')
->assertHasNoErrors()
->assertNotDispatched('error');
expect($team->emailNotificationSettings->fresh()->smtp_ehlo_domain)
->toBe('coolify.example.com');
});
test('saving transactional email settings does not require a resend api key when resend is disabled', function () {
$user = setupInstanceAdminForEmailSettings();
$this->actingAs($user);
session(['currentTeam' => ['id' => 0]]);
Livewire::test(SettingsEmail::class)
->fill(smtpSetupPayload())
->call('submit')
->assertHasNoErrors()
->assertNotDispatched('error');
$settings = InstanceSettings::find(0);
expect($settings->smtp_host)->toBe('smtp.example.com')
->and($settings->resend_enabled)->toBeFalse()
->and($settings->resend_api_key)->toBeNull();
});
test('enabling smtp delivery does not require a resend api key when resend is disabled', function () {
$user = setupInstanceAdminForEmailSettings();
$this->actingAs($user);
session(['currentTeam' => ['id' => 0]]);
Livewire::test(SettingsEmail::class)
->fill(smtpSetupPayload())
->set('smtpEnabled', true)
->call('instantSaveSmtp')
->assertHasNoErrors()
->assertNotDispatched('error');
$settings = InstanceSettings::find(0);
expect($settings->smtp_enabled)->toBeTrue()
->and($settings->resend_enabled)->toBeFalse();
});
test('disabling resend does not require a resend api key', function () {
$user = setupInstanceAdminForEmailSettings();
$this->actingAs($user);
session(['currentTeam' => ['id' => 0]]);
Livewire::test(SettingsEmail::class)
->fill(smtpSetupPayload())
->set('resendEnabled', false)
->set('resendApiKey', null)
->call('submitResend')
->assertHasNoErrors()
->assertNotDispatched('error');
});
test('enabling resend still requires an api key', function () {
$user = setupInstanceAdminForEmailSettings();
$this->actingAs($user);
session(['currentTeam' => ['id' => 0]]);
Livewire::test(SettingsEmail::class)
->fill(smtpSetupPayload())
->set('resendEnabled', true)
->set('resendApiKey', null)
->call('submitResend')
->assertDispatched('error');
expect(InstanceSettings::find(0)->resend_enabled)->toBeFalse();
});