presseportale/tests/Feature/PressReleaseBookingGateTest.php
Kevin Adametz 13716b9c06 press-releases: begrenzter Pruefkreislauf mit Admin-Queue (Roadmap 1d.4, E3)
Automatische Pruefung je Meldung hoechstens max_automatic_attempts (3);
das letzte Rot blockt statt abzulehnen: Meldung bleibt in review, Admin
sieht sie unter "Pruefung noetig" mit allen KI-Begruendungen und
entscheidet (Freischalten / Mit Kommentar zurueck). Danach ist die
Automatik fuer diese Meldung aus - jede Freigabe geht direkt zum Menschen.

Gelb: yellow_to_manual_queue wird jetzt ausgewertet (Vorgabe false).
Kundenseite: "Zur Pruefung freigeben" mit Erklaerung der drei Schritte,
Versuchszaehler an der Ablehnung, Hinweis auf menschliche Pruefung.

Blade: inline @php(...) vor einem @php...@endphp-Block wird als Rohblock
gelesen - vier Stellen auf Blockform umgestellt.

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

109 lines
3.6 KiB
PHP

<?php
use App\Enums\PressReleaseStatus;
use App\Enums\UserPaymentOptionStatus;
use App\Models\Category;
use App\Models\Company;
use App\Models\PressRelease;
use App\Models\SinglePurchase;
use App\Models\User;
use App\Models\UserPaymentOption;
use App\Services\PressRelease\BookingRequiredException;
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);
});
function draftForGate(): array
{
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
$company = Company::factory()->presseecho()->create();
$customer->companies()->attach($company->id, ['role' => 'owner']);
$pr = PressRelease::factory()->create([
'user_id' => $customer->id,
'company_id' => $company->id,
'category_id' => Category::factory()->create()->id,
'portal' => $company->portal->value,
'status' => 'draft',
]);
return compact('customer', 'pr');
}
test('with the gate on a draft without a booking shows the notice and links to bookings', function () {
/** @var TestCase $this */
config()->set('billing.enforce_booking', true);
['customer' => $customer, 'pr' => $pr] = draftForGate();
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id])
->assertSee('Noch keine Buchung')
->assertSee('Buchung wählen')
->assertSee(route('me.bookings.index'), false)
->assertDontSee('Zur Prüfung freigeben');
});
test('with the gate on a paid single purchase unlocks the submission action', function () {
/** @var TestCase $this */
config()->set('billing.enforce_booking', true);
['customer' => $customer, 'pr' => $pr] = draftForGate();
SinglePurchase::factory()->paid()->create(['user_id' => $customer->id]);
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id])
->assertDontSee('Noch keine Buchung')
->assertSee('Zur Prüfung freigeben');
});
test('submitting without a booking is rejected at the service level', function () {
/** @var TestCase $this */
config()->set('billing.enforce_booking', true);
Queue::fake();
['pr' => $pr] = draftForGate();
expect(fn () => app(PressReleaseService::class)->submitForReview($pr))
->toThrow(BookingRequiredException::class);
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Draft);
});
test('a legacy grandfathered booking allows submitting for review', function () {
/** @var TestCase $this */
config()->set('billing.enforce_booking', true);
Queue::fake();
['customer' => $customer, 'pr' => $pr] = draftForGate();
UserPaymentOption::factory()->create([
'user_id' => $customer->id,
'status' => UserPaymentOptionStatus::Grandfathered->value,
'grandfathered_until' => now()->addYear(),
'stripe_subscription_id' => null,
]);
app(PressReleaseService::class)->submitForReview($pr);
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Review);
});
test('with the gate off the notice never shows', function () {
/** @var TestCase $this */
config()->set('billing.enforce_booking', false);
['customer' => $customer, 'pr' => $pr] = draftForGate();
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id])
->assertDontSee('Noch keine Buchung')
->assertSee('Zur Prüfung freigeben');
});