mivita/tests/Feature/AboUpdateCreditCardRequestTest.php
Kevin 671022a28d Abo: Kreditkarte aktualisieren (CRM, Portal, Berater-Link) + Admin-Abo-Löschung
- Karten-Update ohne Abbuchung via PAYONE creditcardcheck/pseudocardpan
  (AboPaymentMethodService, CardUpdateResult/CreditCardCheckData-DTOs)
- Eingabe nur durch Abo-Inhaber: CRM- und Portal-Formular + zeitlich
  begrenzter Berater→Kunde-Link (AboCardUpdateLink + Mail)
- Änderungshistorie in user_abo_card_changes, Anzeige im Admin-Abo-Detail
- Admin: Abo löschen (destroy) inkl. Test
- Portal-Fix: myOrderCreate wirft 404 statt TypeError bei ungültiger ID
- VIP-Sichtbarkeitstests für Einmalartikel-Fenster ergänzt
- Enthält bereits die Freeze-Guards für den Stripe-Notbetrieb (Folge-Commit)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 15:56:19 +00:00

74 lines
2.7 KiB
PHP

<?php
use App\Http\Requests\Abo\UpdateAboCreditCardRequest;
use App\Models\UserAbo;
use App\Services\Payment\Payone\DTOs\CreditCardCheckData;
use Illuminate\Support\Facades\Validator;
use Tests\TestCase;
uses(TestCase::class);
function validCardForm(array $override = []): array
{
return array_merge([
'cc_cardholder_first' => 'Max',
'cc_cardholder_last' => 'Mustermann',
'cc_cardpan' => '4111111111111111',
'cc_cardexpiremonth' => '12',
'cc_cardexpireyear' => '2030',
'cc_cardtype' => 'V',
'cc_cardcvc2' => '123',
], $override);
}
it('maps form data to the cc_* keys the payment service expects', function () {
$dto = CreditCardCheckData::fromFormData(validCardForm());
expect($dto)->toBeInstanceOf(CreditCardCheckData::class)
->and($dto->cardPan)->toBe('4111111111111111')
->and($dto->cardType)->toBe('V');
expect($dto->toCheckArray())->toBe([
'cc_cardholder_first' => 'Max',
'cc_cardholder_last' => 'Mustermann',
'cc_cardpan' => '4111111111111111',
'cc_cardexpiremonth' => '12',
'cc_cardexpireyear' => '2030',
'cc_cardtype' => 'V',
'cc_cardcvc2' => '123',
]);
});
it('accepts a valid credit card form', function () {
$rules = (new UpdateAboCreditCardRequest)->rules();
expect(Validator::make(validCardForm(), $rules)->passes())->toBeTrue();
});
it('rejects invalid credit card input', function (array $override) {
$rules = (new UpdateAboCreditCardRequest)->rules();
expect(Validator::make(validCardForm($override), $rules)->fails())->toBeTrue();
})->with([
'missing holder' => [['cc_cardholder_first' => '']],
'non-numeric pan' => [['cc_cardpan' => '4111-1111-1111']],
'too short pan' => [['cc_cardpan' => '411111']],
'invalid month' => [['cc_cardexpiremonth' => '13']],
'two-digit year' => [['cc_cardexpireyear' => '30']],
'unknown card type' => [['cc_cardtype' => 'X']],
'too short cvc' => [['cc_cardcvc2' => '12']],
]);
it('allows updating the card only for active credit-card abos', function () {
expect((new UserAbo(['clearingtype' => 'cc', 'status' => 2]))->canUpdatePaymentMethod())->toBeTrue();
expect((new UserAbo(['clearingtype' => 'cc', 'status' => 3]))->canUpdatePaymentMethod())->toBeTrue(); // hold = Kartenwechsel erlaubt
});
it('forbids updating the card for non-cc or terminal abos', function (string $clearingtype, int $status) {
expect((new UserAbo(['clearingtype' => $clearingtype, 'status' => $status]))->canUpdatePaymentMethod())->toBeFalse();
})->with([
'paypal (wlt)' => ['wlt', 2],
'cancelled' => ['cc', 4],
'finished' => ['cc', 5],
'inactive' => ['cc', 6],
]);