mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-27 21:06:49 +00:00
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. 🔥
55 lines
1.8 KiB
Ruby
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
|