diff --git a/spec/features/admin/payments_stripe_spec.rb b/spec/features/admin/payments_stripe_spec.rb index 0d6f022453..e4d227e773 100644 --- a/spec/features/admin/payments_stripe_spec.rb +++ b/spec/features/admin/payments_stripe_spec.rb @@ -13,12 +13,11 @@ feature ' let!(:stripe_payment_method) do create(:stripe_sca_payment_method, distributors: [order.distributor]) end + let!(:stripe_account) do + create(:stripe_account, enterprise: order.distributor, stripe_user_id: "abc123") + end context "making a new Stripe payment", js: true do - let!(:stripe_account) do - create(:stripe_account, enterprise: order.distributor, stripe_user_id: "abc123") - end - before do stub_payment_methods_post_request stub_payment_intent_get_request @@ -107,6 +106,7 @@ feature ' context "with a payment using a StripeSCA payment method" do before do + order.update payments: [] order.payments << create(:payment, payment_method: stripe_payment_method, order: order) end @@ -129,5 +129,31 @@ feature ' expect(page).to have_content order.payments.last.amount end end + + context "that is completed", js: true do + let(:payment) { OrderPaymentFinder.new(order.reload).last_payment } + + before do + stub_payment_intent_get_request stripe_account_header: false + stub_successful_capture_request order: order + + payment.update response_code: "pi_123", amount: order.total + payment.purchase! + + stub_refund_request + end + + it "allows to refund the payment" do + login_as_admin_and_visit spree.admin_order_payments_path order + + expect(page).to have_link "StripeSCA" + expect(page).to have_content "COMPLETED" + + page.find('a.icon-void').click + + expect(page).to have_content "VOID" + expect(payment.reload.state).to eq "void" + end + end end end diff --git a/spec/support/request/stripe_helper.rb b/spec/support/request/stripe_helper.rb index 3f6eaa18e4..ef71652b1a 100644 --- a/spec/support/request/stripe_helper.rb +++ b/spec/support/request/stripe_helper.rb @@ -76,6 +76,13 @@ module StripeHelper .to_return(response_mock) end + def stub_refund_request + stub_request(:post, "https://api.stripe.com/v1/charges/ch_1234/refunds") + .with(body: { amount: 2000, expand: ["charge"] }, + headers: { 'Stripe-Account' => 'abc123' }) + .to_return(payment_successful_refund_mock) + end + private def payment_intent_authorize_response_mock(options) @@ -116,4 +123,11 @@ module StripeHelper { status: options[:code] || 200, body: JSON.generate(id: "pm_456", customer: "cus_A123") } end + + def payment_successful_refund_mock + { status: 200, + body: JSON.generate(object: "refund", + amount: 2000, + charge: "ch_1234") } + end end