From 895032fe6a97f27bae9f6c2ca6a0505adb48b23a Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 8 Feb 2020 14:59:40 +0000 Subject: [PATCH] Move stubbed requests to the top as they are the same for every test --- spec/requests/checkout/stripe_sca_spec.rb | 64 ++++++----------------- 1 file changed, 15 insertions(+), 49 deletions(-) diff --git a/spec/requests/checkout/stripe_sca_spec.rb b/spec/requests/checkout/stripe_sca_spec.rb index 6001de71d9..acb1eca2ea 100644 --- a/spec/requests/checkout/stripe_sca_spec.rb +++ b/spec/requests/checkout/stripe_sca_spec.rb @@ -79,6 +79,21 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques order.update_attributes(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) order.reload.update_totals set_order order + + # Authorizes the payment + 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) + + # Retrieves payment intent info + stub_request(:get, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}") + .with(headers: { 'Stripe-Account' => 'abc123' }) + .to_return(payment_intent_authorize_response_mock) + + # Captures the payment + stub_request(:post, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}/capture") + .with(basic_auth: ["sk_test_12345", ""], body: { amount_to_capture: "1234" }) + .to_return(payment_intent_response_mock) end context "when the user submits a new card and doesn't request that the card is saved for later" do @@ -92,21 +107,6 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques .with(body: { payment_method: stripe_payment_method }, headers: { 'Stripe-Account' => 'abc123' }) .to_return(hubs_payment_method_response_mock) - - # Authorizes the payment - stub_request(:post, "https://api.stripe.com/v1/payment_intents") - .with(basic_auth: ["sk_test_12345", ""], body: /#{hubs_stripe_payment_method}.*#{order.number}/) - .to_return(payment_intent_authorize_response_mock) - - # Retrieves paymeent intent info - stub_request(:get, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}") - .with(headers: { 'Stripe-Account' => 'abc123' }) - .to_return(payment_intent_authorize_response_mock) - - # Captures the payment - stub_request(:post, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}/capture") - .with(basic_auth: ["sk_test_12345", ""], body: { amount_to_capture: "1234" }) - .to_return(payment_intent_response_mock) end context "and the payment intent request is successful" do @@ -192,23 +192,6 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques stub_request(:post, "https://api.stripe.com/v1/payment_methods/#{stripe_payment_method}/attach") .with(body: { customer: customer_id }) .to_return(payment_method_attach_response_mock) - - # Authorizes the payment - 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) - - # Retrieves paymeent intent info - stub_request(:get, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}") - .with(headers: { 'Stripe-Account' => 'abc123' }) - .to_return(payment_intent_authorize_response_mock) - - # Captures the payment - stub_request(:post, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}/capture") - .with(basic_auth: ["sk_test_12345", ""], body: { amount_to_capture: "1234" }) - .to_return(payment_intent_response_mock) end context "and the customer, payment_method and payment_intent requests are successful" do @@ -294,23 +277,6 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques before do params[:order][:existing_card_id] = credit_card.id quick_login_as(order.user) - - # Authorizes the payment - 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) - - # Retrieves paymeent intent info - stub_request(:get, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}") - .with(headers: { 'Stripe-Account' => 'abc123' }) - .to_return(payment_intent_authorize_response_mock) - - # Captures the payment - stub_request(:post, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}/capture") - .with(basic_auth: ["sk_test_12345", ""], body: { amount_to_capture: "1234" }) - .to_return(payment_intent_response_mock) end context "and the payment intent and payment method requests are accepted" do