diff --git a/spec/features/admin/payments_stripe_spec.rb b/spec/features/admin/payments_stripe_spec.rb index 43f179950a..11b8e3cd34 100644 --- a/spec/features/admin/payments_stripe_spec.rb +++ b/spec/features/admin/payments_stripe_spec.rb @@ -5,12 +5,13 @@ feature ' I want to make Stripe payments ' do include AuthenticationHelper + include StripeHelper - let(:order) { create(:completed_order_with_fees) } + let!(:order) { create(:completed_order_with_fees) } + let!(:stripe_payment_method) { create(:stripe_sca_payment_method, distributors: [order.distributor]) } context "with a payment using a StripeSCA payment method" do before do - stripe_payment_method = create(:stripe_sca_payment_method, distributors: [order.distributor]) order.payments << create(:payment, payment_method: stripe_payment_method, order: order) end @@ -34,4 +35,30 @@ feature ' end end end + + context "making a new Stripe payment" do + let!(:stripe_account) { create(:stripe_account, enterprise: order.distributor, stripe_user_id: "abc123") } + + before do + stub_hub_payment_methods_request + stub_payment_intents_post_request order: order, stripe_account_header: true + stub_payment_intent_get_request + stub_successful_capture_request order: order + end + + it "adds a payment with state complete", js: true do + login_as_admin_and_visit spree.new_admin_order_payment_path order + + choose "StripeSCA" + fill_in "payment_amount", with: order.total.to_s + fill_in "cardholder_name", with: "David Gilmour" + fill_in "stripe-cardnumber", with: "4242424242424242" + fill_in "exp-date", with: "01-01-2050" + fill_in "cvc", with: "678" + click_button "Update" + + expect(page).to have_link "StripeSCA" + expect(order.payments.reload.first.state).to eq "completed" + end + end end diff --git a/spec/support/request/stripe_helper.rb b/spec/support/request/stripe_helper.rb index 608b1cadd0..da6d7cb36d 100644 --- a/spec/support/request/stripe_helper.rb +++ b/spec/support/request/stripe_helper.rb @@ -27,10 +27,11 @@ module StripeHelper Spree::Config.set(stripe_connect_enabled: true) end - def stub_payment_intents_post_request(order:, response: {}) - stub_request(:post, "https://api.stripe.com/v1/payment_intents") + def stub_payment_intents_post_request(order:, response: {}, stripe_account_header: true) + stub = stub_request(:post, "https://api.stripe.com/v1/payment_intents") .with(basic_auth: ["sk_test_12345", ""], body: /.*#{order.number}/) - .to_return(payment_intent_authorize_response_mock(response)) + stub = stub.with(headers: { 'Stripe-Account' => 'abc123' }) if stripe_account_header + stub.to_return(payment_intent_authorize_response_mock(response)) end def stub_payment_intent_get_request(response: {}, stripe_account_header: true)