-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2002 from jhawthorn/outstanding_balance_omnibus
Update outstanding_balance to use reimbursements
- Loading branch information
Showing
6 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
core/spec/models/spree/order/outstanding_balance_integration_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
require 'spec_helper' | ||
|
||
# This method in particular has been difficult to get right. | ||
# Many things will affect this amount | ||
# | ||
# See also: | ||
# https://github.com/solidusio/solidus/issues/1254 | ||
# https://github.com/spree/spree/issues/6229 | ||
# https://github.com/solidusio/solidus/issues/1107 | ||
# https://github.com/solidusio/solidus/pull/1557 | ||
# https://github.com/solidusio/solidus/pull/1536 | ||
|
||
RSpec.describe "Outstanding balance integration tests" do | ||
let!(:order) { create(:order_with_line_items, line_items_count: 2, line_items_price: 3, shipment_cost: 13) } | ||
before { order.update_attributes!(state: 'complete', completed_at: Time.now) } | ||
|
||
subject do | ||
order.reload | ||
order.update! | ||
order.outstanding_balance | ||
end | ||
|
||
context 'when the order is unpaid' do | ||
it { should eq order.total } | ||
it { should eq 19 } | ||
|
||
context 'when the order is cancelled' do | ||
before { order.cancel! } | ||
it { should eq 0 } | ||
end | ||
end | ||
|
||
context 'when the order is fully paid' do | ||
let!(:payment) { create(:payment, :completed, order: order, amount: order.total) } | ||
it { should eq 0 } | ||
|
||
context 'and there is a full refund' do | ||
let!(:refund) { create(:refund, payment: payment, amount: payment.amount) } | ||
it { should eq 19 } | ||
end | ||
|
||
context 'when the order is cancelled' do | ||
before { order.update_attributes!(state: "canceled") } | ||
it { should eq(-19) } | ||
|
||
context 'and the payment is voided' do | ||
before { payment.update_attributes!(state: "void") } | ||
it { should eq 0 } | ||
end | ||
|
||
context 'and there is a full refund' do | ||
let!(:refund) { create(:refund, payment: payment, amount: payment.amount) } | ||
it { should eq 0 } | ||
end | ||
|
||
context 'and there is a partial refund' do | ||
let!(:refund) { create(:refund, payment: payment, amount: 6) } | ||
it { should eq(-13) } | ||
end | ||
end | ||
|
||
context 'with a cancelled item' do | ||
let(:cancelations) { Spree::OrderCancellations.new(order) } | ||
let(:cancelled_item) { order.line_items.first } | ||
|
||
before do | ||
# Required to refund | ||
Spree::RefundReason.create!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) | ||
|
||
cancelations.cancel_unit(cancelled_item.inventory_units.first) | ||
cancelations.reimburse_units(cancelled_item.inventory_units) | ||
|
||
order.reload | ||
end | ||
|
||
it 'discounts the cancelled item amount' do | ||
expect(order.refund_total).to eq(3) | ||
expect(order.reimbursement_total).to eq(3) | ||
expect(order.payment_total).to eq(16) | ||
expect(order.outstanding_balance).to eq(0) | ||
|
||
expect(order.total).to eq(19) | ||
end | ||
end | ||
end | ||
|
||
context 'when the order is partly paid' do | ||
let!(:payment) { create(:payment, :completed, order: order, amount: 10) } | ||
it { should eq 9 } | ||
|
||
context 'and there is a full refund' do | ||
let!(:refund) { create(:refund, payment: payment, amount: payment.amount) } | ||
it { should eq 19 } | ||
end | ||
|
||
context 'when the order is cancelled' do | ||
before { order.update_attributes!(state: "canceled") } | ||
it { should eq(-10) } | ||
|
||
context 'and the payment is voided' do | ||
before { payment.update_attributes!(state: "void") } | ||
it { should eq 0 } | ||
end | ||
|
||
context 'and there is a full refund' do | ||
let!(:refund) { create(:refund, payment: payment, amount: payment.amount) } | ||
it { should eq 0 } | ||
end | ||
|
||
context 'and there is a partial refund' do | ||
let!(:refund) { create(:refund, payment: payment, amount: 6) } | ||
it { should eq(-4) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters