Files
openfoodnetwork/spec/models/spree/order/payment_spec.rb
Matt-Yorkley 365700615a Remove dead code: Spree::Config.auto_capture
We set this value to `true` unconditionally in an initializer, and then check the value in various places via Spree::Config. It's never false, and it's not configurable, so we can just drop it and remove the related conditionals. 🔥
2021-03-05 16:03:07 +00:00

55 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
module Spree
describe Spree::Order do
let(:order) { build(:order) }
let(:updater) { OrderManagement::Order::Updater.new(order) }
let(:bogus) { create(:bogus_payment_method, distributors: [create(:enterprise)]) }
before do
allow(order).to receive_message_chain(:line_items, :empty?).and_return(false)
allow(order).to receive_messages total: 100
end
it 'processes all payments' do
payment1 = create(:payment, amount: 50, payment_method: bogus)
payment2 = create(:payment, amount: 50, payment_method: bogus)
allow(order).to receive(:pending_payments).and_return([payment1, payment2])
order.process_payments!
updater.update_payment_state
expect(order.payment_state).to eq 'paid'
expect(payment1).to be_completed
expect(payment2).to be_completed
end
it 'does not go over total for order' do
payment1 = create(:payment, amount: 50, payment_method: bogus)
payment2 = create(:payment, amount: 50, payment_method: bogus)
payment3 = create(:payment, amount: 50, payment_method: bogus)
allow(order).to receive(:pending_payments).and_return([payment1, payment2, payment3])
order.process_payments!
updater.update_payment_state
expect(order.payment_state).to eq 'paid'
expect(payment1).to be_completed
expect(payment2).to be_completed
expect(payment3).to be_checkout
end
it "does not use failed payments" do
payment1 = create(:payment, amount: 50, payment_method: bogus)
payment2 = create(:payment, amount: 50, state: 'failed', payment_method: bogus)
allow(order).to receive(:pending_payments).and_return([payment1])
expect(payment2).not_to receive(:process!)
order.process_payments!
end
end
end