46 lines
1.7 KiB
PHP
46 lines
1.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Mailbox;
|
|
use App\Services\Mail\MailboxResolver;
|
|
use App\Services\Mail\MailPurpose;
|
|
use App\Support\Settings;
|
|
|
|
beforeEach(function () {
|
|
config()->set('admin_access.secrets_key', 'base64:'.base64_encode(random_bytes(32)));
|
|
});
|
|
|
|
it('resolves a purpose to the mailbox it points at', function () {
|
|
Mailbox::factory()->create(['key' => 'support', 'address' => 'support@clupilot.com']);
|
|
Settings::set('mail.purpose.support', 'support');
|
|
|
|
expect(app(MailboxResolver::class)->for(MailPurpose::SUPPORT)?->address)
|
|
->toBe('support@clupilot.com');
|
|
});
|
|
|
|
it('falls back to system when a purpose has no mailbox', function () {
|
|
Mailbox::factory()->create(['key' => 'no-reply', 'address' => 'no-reply@clupilot.com']);
|
|
Settings::set('mail.purpose.system', 'no-reply');
|
|
|
|
// billing deliberately unset
|
|
expect(app(MailboxResolver::class)->for(MailPurpose::BILLING)?->address)
|
|
->toBe('no-reply@clupilot.com');
|
|
});
|
|
|
|
it('falls back to system when the named mailbox no longer exists', function () {
|
|
Mailbox::factory()->create(['key' => 'no-reply', 'address' => 'no-reply@clupilot.com']);
|
|
Settings::set('mail.purpose.system', 'no-reply');
|
|
Settings::set('mail.purpose.billing', 'geloescht');
|
|
|
|
expect(app(MailboxResolver::class)->for(MailPurpose::BILLING)?->address)
|
|
->toBe('no-reply@clupilot.com');
|
|
});
|
|
|
|
it('returns null rather than guessing when even system is unset', function () {
|
|
expect(app(MailboxResolver::class)->for(MailPurpose::SYSTEM))->toBeNull();
|
|
});
|
|
|
|
it('rejects a purpose that is not in the curated list', function () {
|
|
expect(fn () => app(MailboxResolver::class)->for('erfunden'))
|
|
->toThrow(InvalidArgumentException::class, 'erfunden');
|
|
});
|