R1.1: Buchungs-Gate geprueft + safe-by-default; Legacy-Buchungspfade festgeschrieben
Default von billing.enforce_booking auf true gedreht: ein in Produktion vergessener Env-Key haette das Gate sonst still geoeffnet (jeder haette ohne Zahlung veroeffentlichen koennen). Tests ergaenzt: Grandfathered gueltig/abgelaufen/NULL (= abgelaufen, Entscheidung 19.06.), Active ausserhalb der Periode, Service-Level-Submit mit Legacy-Buchung und BookingRequiredException ohne Buchung. Scope-Logik selbst war korrekt. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
c3db80c651
commit
ad2879daa4
4 changed files with 109 additions and 9 deletions
|
|
@ -73,3 +73,62 @@ test('a cancelled legacy agreement does not count as booking', function () {
|
|||
|
||||
expect($user->hasActiveBooking())->toBeFalse();
|
||||
});
|
||||
|
||||
test('an active legacy agreement outside its current period does not count as booking', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'payment_option_id' => PaymentOption::factory()->create()->id,
|
||||
'status' => UserPaymentOptionStatus::Active->value,
|
||||
'current_period_start' => now()->subMonths(2)->startOfMonth(),
|
||||
'current_period_end' => now()->subMonths(2)->endOfMonth(),
|
||||
'grandfathered_until' => null,
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
expect($user->hasActiveBooking())->toBeFalse();
|
||||
});
|
||||
|
||||
test('a grandfathered agreement with valid protection counts as booking', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'payment_option_id' => PaymentOption::factory()->create()->id,
|
||||
'status' => UserPaymentOptionStatus::Grandfathered->value,
|
||||
'grandfathered_until' => now()->addYear(),
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
expect($user->hasActiveBooking())->toBeTrue();
|
||||
});
|
||||
|
||||
test('a grandfathered agreement with expired protection does not count as booking', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'payment_option_id' => PaymentOption::factory()->create()->id,
|
||||
'status' => UserPaymentOptionStatus::Grandfathered->value,
|
||||
'grandfathered_until' => now()->subDay(),
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
expect($user->hasActiveBooking())->toBeFalse();
|
||||
});
|
||||
|
||||
test('a grandfathered agreement without an end date does not count as booking', function () {
|
||||
// NULL = abgelaufen/ungültig (User-Entscheidung 19.06.2026).
|
||||
$user = User::factory()->create();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'payment_option_id' => PaymentOption::factory()->create()->id,
|
||||
'status' => UserPaymentOptionStatus::Grandfathered->value,
|
||||
'grandfathered_until' => null,
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
expect($user->hasActiveBooking())->toBeFalse();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
<?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;
|
||||
|
||||
|
|
@ -60,6 +66,36 @@ test('with the gate on a paid single purchase unlocks the submission action', fu
|
|||
->assertSee('Zur Prüfung einreichen');
|
||||
});
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue