presseportale/tests/Feature/MailSuppressionAdminTest.php
Kevin Adametz e7e12b9436 admin: Mail-Sperrliste, Markierung nicht erreichbarer Newsrooms (Roadmap 1b.6, Schritt 4)
Admin ▸ Mail-Sperrliste mit Freigabe, manueller Sperre, nicht lesbaren
Rückläufern und Breaker-Zustand. Firmenseite markiert gesperrte
Firmen-E-Mail und Pressekontakte. Die Claim-Seite zählt gesperrte
Adressen nicht mehr als Empfänger und erklärt, warum kein Link geht.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 14:01:07 +00:00

79 lines
3.3 KiB
PHP

<?php
use App\Enums\EmailSuppressionReason;
use App\Models\Company;
use App\Models\Contact;
use App\Models\EmailSuppression;
use App\Models\User;
use App\Services\Mail\EmailSuppressionService;
use Database\Seeders\RolesAndPermissionsSeeder;
use Illuminate\Support\Facades\Mail;
use Livewire\Volt\Volt as LivewireVolt;
use Tests\TestCase;
/**
* Roadmap 1b.6, Schritt 4: nicht erreichbare Newsrooms im Admin markiert,
* nicht beanspruchbar, Freigabe im Admin.
*/
beforeEach(function (): void {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
Mail::fake();
});
function suppressionAdmin(): User
{
$admin = User::factory()->create(['is_active' => true]);
$admin->assignRole('admin');
test()->actingAs($admin);
return $admin;
}
test('a newsroom whose only address bounced is not claimable and says why', function () {
/** @var TestCase $this */
Company::factory()->create(['portal' => 'businessportal24', 'slug' => 'tot-gmbh', 'email' => 'presse@tot.example', 'name' => 'Tot GmbH']);
app(EmailSuppressionService::class)->suppress('presse@tot.example', EmailSuppressionReason::HardBounce, 'imap');
$this->get('https://businessportal24.test/de/newsroom/tot-gmbh/verwalten')
->assertOk()
->assertSeeText('nicht mehr erreichbar')
->assertDontSeeText('Anmeldelink senden');
$this->post('https://businessportal24.test/de/newsroom/tot-gmbh/verwalten')->assertSessionHas('newsroom-claim-unreachable');
Mail::assertNothingQueued();
});
test('the admin company page marks unreachable company and contact addresses', function () {
/** @var TestCase $this */
suppressionAdmin();
$company = Company::factory()->create(['email' => 'presse@tot.example']);
Contact::factory()->for($company)->create(['email' => 'kontakt@tot.example', 'portal' => $company->portal->value]);
app(EmailSuppressionService::class)->suppress('presse@tot.example', EmailSuppressionReason::HardBounce, 'imap');
app(EmailSuppressionService::class)->suppress('kontakt@tot.example', EmailSuppressionReason::HardBounce, 'imap');
LivewireVolt::test('admin.companies.show', ['id' => $company->id])
->assertSee('E-Mail nicht erreichbar')
->call('setTab', 'contacts')
->assertSee('kontakt@tot.example')
->assertSeeInOrder(['nicht erreichbar', 'kontakt@tot.example']);
});
test('the suppression list shows, releases and manually suppresses addresses', function () {
/** @var TestCase $this */
$admin = suppressionAdmin();
app(EmailSuppressionService::class)->suppress('presse@tot.example', EmailSuppressionReason::HardBounce, 'imap');
$component = LivewireVolt::test('admin.mail.suppressions')
->assertSee('presse@tot.example')
->assertSee('Postfach existiert nicht');
$component->call('release', EmailSuppression::query()->firstOrFail()->id);
expect(app(EmailSuppressionService::class)->isSuppressed('presse@tot.example'))->toBeFalse()
->and(EmailSuppression::query()->first()->released_by_user_id)->toBe($admin->id);
$component->set('newEmail', 'Neu@Tot.example')->set('newNote', 'von Hand')->call('suppress')->assertHasNoErrors();
expect(app(EmailSuppressionService::class)->isSuppressed('neu@tot.example'))->toBeTrue();
$this->get(route('admin.mail.suppressions'))->assertOk()->assertSeeText('Mail-Sperrliste');
});