'owner-'.uniqid('', true).'@example.com', 'password' => bcrypt('secret'), 'lang' => 'de', ]); $abo = UserAbo::create([ 'user_id' => $owner->id, 'member_id' => $owner->id, 'shopping_user_id' => 1, 'is_for' => 'me', 'email' => $owner->email, 'payone_userid' => 900300, 'clearingtype' => 'cc', 'active' => $active, 'status' => $status, 'abo_interval' => 5, 'next_date' => now()->toDateString(), ]); return ['owner' => $owner, 'abo' => $abo]; } it('startet den Recovery-Checkout für das eigene fehlgeschlagene Abo und leitet dorthin weiter', function () { $fixture = makeRetryOwnerAbo(); $this->actingAs($fixture['owner']); mock(AboRecoveryCheckoutService::class) ->shouldReceive('buildCheckoutUrl') ->once() ->andReturn('https://checkout.test/checkout/card/abc123'); $controller = new AboController(app(AboRepository::class)); $response = $controller->payNow('me', $fixture['abo']->id, app(AboRecoveryCheckoutService::class)); expect($response->getTargetUrl())->toBe('https://checkout.test/checkout/card/abc123'); }); it('verhindert die nachträgliche Zahlung für ein fremdes Abo (403)', function () { $fixture = makeRetryOwnerAbo(); $stranger = User::forceCreate([ 'email' => 'stranger-'.uniqid('', true).'@example.com', 'password' => bcrypt('secret'), 'lang' => 'de', ]); $this->actingAs($stranger); $service = mock(AboRecoveryCheckoutService::class); $service->shouldNotReceive('buildCheckoutUrl'); $controller = new AboController(app(AboRepository::class)); expect(fn () => $controller->payNow('me', $fixture['abo']->id, $service)) ->toThrow(HttpException::class); }); it('lehnt die nachträgliche Zahlung ab, wenn das Abo nicht fehlgeschlagen ist', function () { Route::post('/user/abos/detail/{view}/{id}', fn () => '')->name('user_abos_detail'); app('router')->getRoutes()->refreshNameLookups(); $fixture = makeRetryOwnerAbo(status: 2); $this->actingAs($fixture['owner']); $service = mock(AboRecoveryCheckoutService::class); $service->shouldNotReceive('buildCheckoutUrl'); $controller = new AboController(app(AboRepository::class)); $response = $controller->payNow('me', $fixture['abo']->id, $service); expect($response->getTargetUrl())->toContain('/user/abos/detail/me/'.$fixture['abo']->id); expect(session('alert-error'))->toBe(__('abo.pay_now_not_allowed')); });