presseportale/tests/Feature/Admin/AdminKiCheckTest.php
Kevin Adametz ada41cb067 mail: Kontakterreichbarkeit - Formpruefung, Domainpruefung, Einlieferer-Bericht
Vier Punkte aus kontakterreichbarkeit-mx-bounces-2026-09-15.md, ohne
Veroeffentlichungssperre:

- PlausibleEmailDomain: Domain ohne Endung oder mit Tippfehler-TLD ist
  ein 422 an der Legacy-API, deterministisch ohne DNS.
- email_domain_checks + MailDomainChecker ueber DnsResolver-Schnittstelle
  (RFC 5321 impliziter MX, RFC 7505 Null MX, Unresolved ist kein Befund),
  Observer an Company/Contact, Job nach Commit, taeglicher Refresh,
  mail:check-domains fuer den Bestand. Nie eine Adresssperre aus DNS.
- Admin > Reports > Einlieferer-Bericht: tote Adressen aus Sperrliste
  und Domainbefund, automatisch abgelehnte Meldungen mit Grund,
  Text zum Kopieren und CSV. Versendet nichts.
- EmailBounceKind::Policy: 5.7.x wird protokolliert, zaehlt aber nicht
  auf den Schwellwert. Statuscode entscheidet vor Diagnosetext.

Messung vorab: 6 von 877 API-Domains ohne Zustellweg, eine davon fuer
66 der 151 Ruecklaeufer verantwortlich.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 09:22:39 +00:00

101 lines
3.7 KiB
PHP

<?php
use App\Enums\PressReleaseClassification;
use App\Enums\PressReleaseStatus;
use App\Jobs\ClassifyPressRelease;
use App\Jobs\ScorePressRelease;
use App\Models\PressRelease;
use App\Models\User;
use App\Services\PressRelease\Classification\ClassificationManager;
use App\Services\PressRelease\PressReleaseService;
use Database\Seeders\RolesAndPermissionsSeeder;
use Illuminate\Support\Facades\Queue;
use Livewire\Volt\Volt as LivewireVolt;
use Tests\TestCase;
beforeEach(function (): void {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
$admin = User::factory()->create(['is_active' => true]);
$admin->assignRole('admin');
$this->actingAs($admin);
});
test('admin editor exposes the KI check button and modal', function () {
/** @var TestCase $this */
$pressRelease = PressRelease::factory()->create(['status' => PressReleaseStatus::Review->value]);
LivewireVolt::test('admin.press-releases.edit', ['id' => $pressRelease->id])
->assertSee('Prüfung')
->assertSee('Prüfung im Hintergrund starten');
});
test('runKiCheck dispatches a non-routing classification job with provider override', function () {
/** @var TestCase $this */
Queue::fake();
$pressRelease = PressRelease::factory()->create(['status' => PressReleaseStatus::Review->value]);
LivewireVolt::test('admin.press-releases.edit', ['id' => $pressRelease->id])
->set('kiProvider', 'deterministic')
->call('runKiCheck')
->assertHasNoErrors();
Queue::assertPushedOn('classification', ClassifyPressRelease::class, function (ClassifyPressRelease $job) use ($pressRelease) {
return $job->pressReleaseId === $pressRelease->id
&& $job->route === false
&& $job->providerOverride === 'deterministic';
});
});
test('runKiCheck dispatches a scoring job when content score is selected', function () {
/** @var TestCase $this */
Queue::fake();
$pressRelease = PressRelease::factory()->create(['status' => PressReleaseStatus::Review->value]);
LivewireVolt::test('admin.press-releases.edit', ['id' => $pressRelease->id])
->set('kiRunClassification', false)
->set('kiRunContentScore', true)
->call('runKiCheck')
->assertHasNoErrors();
Queue::assertPushed(ScorePressRelease::class, fn (ScorePressRelease $job) => $job->pressReleaseId === $pressRelease->id);
Queue::assertNotPushed(ClassifyPressRelease::class);
});
test('runKiCheck does nothing when no check is selected', function () {
/** @var TestCase $this */
Queue::fake();
$pressRelease = PressRelease::factory()->create(['status' => PressReleaseStatus::Review->value]);
LivewireVolt::test('admin.press-releases.edit', ['id' => $pressRelease->id])
->set('kiRunClassification', false)
->call('runKiCheck')
->assertHasNoErrors();
Queue::assertNotPushed(ClassifyPressRelease::class);
});
test('a non-routing classification job updates the verdict but leaves the status unchanged', function () {
/** @var TestCase $this */
config()->set('scoring.classification.provider', 'deterministic');
config()->set('blacklist.words', ['penis']);
// Rote Einstufung, aber als Re-Check ohne Routing: Status bleibt published.
$pressRelease = PressRelease::factory()->published()->create([
'title' => 'Titel penis',
'text' => 'Inhalt',
]);
(new ClassifyPressRelease($pressRelease->id, route: false))->handle(
app(ClassificationManager::class),
app(PressReleaseService::class),
);
$fresh = $pressRelease->fresh();
expect($fresh->classification)->toBe(PressReleaseClassification::Red);
expect($fresh->status)->toBe(PressReleaseStatus::Published);
});