diff --git a/tests/Feature/Billing/BillingPaymentServiceCreditPackTest.php b/tests/Feature/Billing/BillingPaymentServiceCreditPackTest.php new file mode 100644 index 0000000..bf087d1 --- /dev/null +++ b/tests/Feature/Billing/BillingPaymentServiceCreditPackTest.php @@ -0,0 +1,50 @@ +bind(SubscriptionCheckoutGateway::class, FakeSubscriptionCheckoutGateway::class); + + config()->set('billing.credit_packs.small.stripe_price_id', 'price_small_test'); +}); + +it('creates credit pack checkout for user', function () { + $user = User::factory()->create(); + $pack = app(CreditPackRepository::class)->findOrFail('small'); + + $checkout = app(BillingPaymentService::class)->createCreditPackCheckout( + user: $user, + pack: $pack, + successUrl: 'https://example.test/billing/credits/success', + cancelUrl: 'https://example.test/billing/credits/cancel', + ); + + expect($checkout)->toBeInstanceOf(CheckoutSessionDto::class); + expect($checkout->url)->not->toBeEmpty(); +}); + +it('rejects credit pack with no stripe price id', function () { + $user = User::factory()->create(); + $pack = new CreditPackDto( + key: 'small', + label: '500 Credits', + credits: 500, + stripePriceId: null, + description: 'Test', + ); + + app(BillingPaymentService::class)->createCreditPackCheckout( + user: $user, + pack: $pack, + successUrl: 'https://example.test/success', + cancelUrl: 'https://example.test/cancel', + ); +})->throws(InvalidArgumentException::class);