mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Add spec to test receiving a redirect from stripe with a valid payment intent id
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe CheckoutController, type: :controller do
|
||||
let(:distributor) { double(:distributor) }
|
||||
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let(:order_cycle) { create(:simple_order_cycle) }
|
||||
let(:order) { create(:order) }
|
||||
let(:reset_order_service) { double(ResetOrderService) }
|
||||
@@ -36,7 +36,7 @@ describe CheckoutController, type: :controller do
|
||||
expect(flash[:info]).to eq("The hub you have selected is temporarily closed for orders. Please try again later.")
|
||||
end
|
||||
|
||||
describe "redirection to the cart" do
|
||||
describe "redirection to cart and stripe" do
|
||||
let(:order_cycle_distributed_variants) { double(:order_cycle_distributed_variants) }
|
||||
|
||||
before do
|
||||
@@ -44,7 +44,7 @@ describe CheckoutController, type: :controller do
|
||||
allow(order).to receive(:distributor).and_return(distributor)
|
||||
order.order_cycle = order_cycle
|
||||
|
||||
allow(OrderCycleDistributedVariants).to receive(:new).with(order_cycle, distributor).and_return(order_cycle_distributed_variants)
|
||||
allow(OrderCycleDistributedVariants).to receive(:new).and_return(order_cycle_distributed_variants)
|
||||
end
|
||||
|
||||
it "redirects when some items are out of stock" do
|
||||
@@ -62,12 +62,34 @@ describe CheckoutController, type: :controller do
|
||||
expect(response).to redirect_to cart_path
|
||||
end
|
||||
|
||||
it "does not redirect when items are available and in stock" do
|
||||
allow(order).to receive_message_chain(:insufficient_stock_lines, :empty?).and_return true
|
||||
expect(order_cycle_distributed_variants).to receive(:distributes_order_variants?).with(order).and_return(true)
|
||||
describe "when items are available and in stock" do
|
||||
before do
|
||||
allow(order).to receive_message_chain(:insufficient_stock_lines, :empty?).and_return true
|
||||
end
|
||||
|
||||
get :edit
|
||||
expect(response).to be_success
|
||||
it "does not redirect" do
|
||||
expect(order_cycle_distributed_variants).to receive(:distributes_order_variants?).with(order).and_return(true)
|
||||
get :edit
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
describe "when the order is in payment state and a stripe payment intent is provided" do
|
||||
before do
|
||||
order.update_attribute :state, "payment"
|
||||
order.ship_address = create(:address)
|
||||
order.save!
|
||||
order.payments << create(:payment, state: "pending", response_code: "pi_123")
|
||||
|
||||
# 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)
|
||||
end
|
||||
|
||||
it "completes the order and redirects to the order confirmation page" do
|
||||
get :edit, { payment_intent: "pi_123" }
|
||||
expect(order.completed?).to be true
|
||||
expect(response).to redirect_to spree.order_path(order)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user