Fix: Bestandsschutz ohne explizites Vertragsende zaehlte nie als aktiv

Der grandfatheredNow-Scope verlangte ein gesetztes grandfathered_until —
das ist aber das explizite Legacy-Vertragsende (valid_until_date) und im
Import-Regelfall NULL (offene Dauervereinbarung). Ergebnis: praktisch
kein Legacy-Kunde hatte eine aktive Zahlungsoption; eingeloggte
Bestandskunden sahen "Buchung erforderlich" und konnten nicht einreichen.
Jetzt gilt: grandfathered_until deckelt, wenn gesetzt; sonst zaehlt die
laufende, vom MAN-Rechnungslauf fortgerollte Periode (current_period_end
= next_due_date). Tests decken beide NULL-Faelle und den Deckel ab.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-07-06 11:40:39 +00:00
parent 6ef4a0d061
commit 3364fd13b8
2 changed files with 57 additions and 4 deletions

View file

@ -118,8 +118,10 @@ test('a grandfathered agreement with expired protection does not count as bookin
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).
test('a grandfathered agreement without an end date counts while its period is running', function () {
// Regelfall des Imports (Fix 06.07.2026): offene Dauervereinbarung —
// grandfathered_until NULL, Gültigkeit über die laufende Periode
// (current_period_end = next_due_date, vom MAN-Lauf fortgerollt).
$user = User::factory()->create();
UserPaymentOption::factory()->create([
@ -127,6 +129,43 @@ test('a grandfathered agreement without an end date does not count as booking',
'payment_option_id' => PaymentOption::factory()->create()->id,
'status' => UserPaymentOptionStatus::Grandfathered->value,
'grandfathered_until' => null,
'current_period_start' => now()->subMonths(3),
'current_period_end' => now()->addMonths(9),
'stripe_subscription_id' => null,
]);
expect($user->hasActiveBooking())->toBeTrue();
});
test('a grandfathered agreement without an end date lapses with its period', 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' => null,
'current_period_start' => now()->subYears(2),
'current_period_end' => now()->subYear(),
'stripe_subscription_id' => null,
]);
expect($user->hasActiveBooking())->toBeFalse();
});
test('an explicit legacy end date caps a grandfathered agreement despite a running period', function () {
// grandfathered_until = explizites Vertragsende (valid_until_date) —
// wenn gesetzt und überschritten, zählt die Vereinbarung nicht mehr,
// auch wenn die Abrechnungsperiode formal noch läuft.
$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(),
'current_period_start' => now()->subMonths(3),
'current_period_end' => now()->addMonths(9),
'stripe_subscription_id' => null,
]);