mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
RSpec3-ize OrderUpdater spec
This commit is contained in:
@@ -1,88 +1,98 @@
|
||||
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 }
|
||||
context "#updating_payment_state" do
|
||||
let(:order) { build(:order) }
|
||||
let(:order_updater) { described_class.new(order) }
|
||||
|
||||
it "is failed if no valid payments" do
|
||||
order.stub_chain(:payments, :valid, :empty?).and_return(true)
|
||||
allow(order).to receive_message_chain(:payments, :valid, :empty?) { true }
|
||||
|
||||
updater.update_payment_state
|
||||
order.payment_state.should == 'failed'
|
||||
order_updater.update_payment_state
|
||||
expect(order.payment_state).to eq('failed')
|
||||
end
|
||||
|
||||
context "payment total is greater than order total" do
|
||||
it "is credit_owed" do
|
||||
before do
|
||||
order.payment_total = 2
|
||||
order.total = 1
|
||||
end
|
||||
|
||||
it "is credit_owed" do
|
||||
expect {
|
||||
updater.update_payment_state
|
||||
order_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
|
||||
before do
|
||||
order.payment_total = 1
|
||||
order.total = 2
|
||||
end
|
||||
|
||||
it "is credit_owed" do
|
||||
expect {
|
||||
updater.update_payment_state
|
||||
order_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
|
||||
before do
|
||||
order.payment_total = 30
|
||||
order.total = 30
|
||||
end
|
||||
|
||||
it "is paid" do
|
||||
expect {
|
||||
updater.update_payment_state
|
||||
order_updater.update_payment_state
|
||||
}.to change { order.payment_state }.to 'paid'
|
||||
end
|
||||
end
|
||||
|
||||
context "order is canceled" do
|
||||
before do
|
||||
order.state = 'canceled'
|
||||
end
|
||||
before { order.state = 'canceled' }
|
||||
|
||||
context "and is still unpaid" do
|
||||
it "is void" do
|
||||
before do
|
||||
order.payment_total = 0
|
||||
order.total = 30
|
||||
end
|
||||
|
||||
it "is void" do
|
||||
expect {
|
||||
updater.update_payment_state
|
||||
order_updater.update_payment_state
|
||||
}.to change { order.payment_state }.to 'void'
|
||||
end
|
||||
end
|
||||
|
||||
context "and is paid" do
|
||||
it "is credit_owed" do
|
||||
before 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)
|
||||
end
|
||||
|
||||
it "is credit_owed" do
|
||||
expect {
|
||||
updater.update_payment_state
|
||||
order_updater.update_payment_state
|
||||
}.to change { order.payment_state }.to 'credit_owed'
|
||||
end
|
||||
end
|
||||
|
||||
context "and payment is refunded" do
|
||||
it "is void" do
|
||||
before 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)
|
||||
end
|
||||
|
||||
it "is void" do
|
||||
expect {
|
||||
updater.update_payment_state
|
||||
order_updater.update_payment_state
|
||||
}.to change { order.payment_state }.to 'void'
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user