mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
Problem: order payments didn't seem to be loaded in any particular order, and OrderUpdater#update_payment_state was relying on payment order to de- termine payment state. Strategy: Adapt a version of this method from a future version of Spree. I tried to select a version where I would have to make the absolute mini- mum number of changes to get it to work. See comments in code for justif- ications of the changes that I did make.
92 lines
2.5 KiB
Ruby
92 lines
2.5 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe Spree::OrderUpdater do
|
|
# Copied pretty much verbatim from Spree 2.4. Remove this file once we get there,
|
|
# assuming the unchanged 2.4 logic still works for us.
|
|
# Only changes are stubs of :empty? instead of :size
|
|
context "updating payment state" do
|
|
let(:order) { Spree::Order.new }
|
|
let(:updater) { order.updater }
|
|
|
|
it "is failed if no valid payments" do
|
|
order.stub_chain(:payments, :valid, :empty?).and_return(true)
|
|
|
|
updater.update_payment_state
|
|
order.payment_state.should == 'failed'
|
|
end
|
|
|
|
context "payment total is greater than order total" do
|
|
it "is credit_owed" do
|
|
order.payment_total = 2
|
|
order.total = 1
|
|
|
|
expect {
|
|
updater.update_payment_state
|
|
}.to change { order.payment_state }.to 'credit_owed'
|
|
end
|
|
end
|
|
|
|
context "order total is greater than payment total" do
|
|
it "is credit_owed" do
|
|
order.payment_total = 1
|
|
order.total = 2
|
|
|
|
expect {
|
|
updater.update_payment_state
|
|
}.to change { order.payment_state }.to 'balance_due'
|
|
end
|
|
end
|
|
|
|
context "order total equals payment total" do
|
|
it "is paid" do
|
|
order.payment_total = 30
|
|
order.total = 30
|
|
|
|
expect {
|
|
updater.update_payment_state
|
|
}.to change { order.payment_state }.to 'paid'
|
|
end
|
|
end
|
|
|
|
context "order is canceled" do
|
|
before do
|
|
order.state = 'canceled'
|
|
end
|
|
|
|
context "and is still unpaid" do
|
|
it "is void" do
|
|
order.payment_total = 0
|
|
order.total = 30
|
|
expect {
|
|
updater.update_payment_state
|
|
}.to change { order.payment_state }.to 'void'
|
|
end
|
|
end
|
|
|
|
context "and is paid" do
|
|
it "is credit_owed" do
|
|
order.payment_total = 30
|
|
order.total = 30
|
|
order.stub_chain(:payments, :valid, :empty?).and_return(false)
|
|
order.stub_chain(:payments, :completed, :empty?).and_return(false)
|
|
expect {
|
|
updater.update_payment_state
|
|
}.to change { order.payment_state }.to 'credit_owed'
|
|
end
|
|
end
|
|
|
|
context "and payment is refunded" do
|
|
it "is void" do
|
|
order.payment_total = 0
|
|
order.total = 30
|
|
order.stub_chain(:payments, :valid, :empty?).and_return(false)
|
|
order.stub_chain(:payments, :completed, :empty?).and_return(false)
|
|
expect {
|
|
updater.update_payment_state
|
|
}.to change { order.payment_state }.to 'void'
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|