Extend test coverage of CheckoutController

I'm covering the interaction with Stripe here to test for error cases in
the future.
This commit is contained in:
Maikel Linke
2021-03-24 16:56:23 +11:00
parent ec088c3a60
commit af5ac2a25e

View File

@@ -3,6 +3,8 @@
require 'spec_helper'
describe CheckoutController, type: :controller do
include StripeStubs
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:order_cycle) { create(:simple_order_cycle) }
let(:order) { create(:order) }
@@ -97,11 +99,27 @@ describe CheckoutController, type: :controller do
end
describe "when the order is in payment state and a stripe payment intent is provided" do
let(:order) { create(:order_with_totals) }
let(:payment_method) { create(:stripe_sca_payment_method) }
let(:payment) {
create(
:payment,
amount: order.total,
state: "pending",
payment_method: payment_method,
response_code: "pi_123"
)
}
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
stub_payment_intent_get_request
stub_successful_capture_request(order: order)
order.update_attribute :state, "payment"
order.ship_address = create(:address)
order.save!
order.payments << create(:payment, state: "pending", response_code: "pi_123")
order.payments << payment
# this is called a 2nd time after order completion from the reset_order_service
expect(order_cycle_distributed_variants).to receive(:distributes_order_variants?).twice.and_return(true)