spree_core 3.0.5 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/spree.js.coffee.erb +1 -1
- data/app/models/spree/ability.rb +1 -1
- data/app/models/spree/base.rb +3 -1
- data/app/models/spree/order_updater.rb +2 -1
- data/app/models/spree/price.rb +7 -12
- data/app/models/spree/product.rb +3 -2
- data/app/models/spree/reimbursement.rb +1 -1
- data/app/models/spree/state.rb +2 -0
- data/app/models/spree/zone.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/testing_support/shoulda_matcher_configuration.rb +6 -0
- data/script/rails +9 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +137 -0
- data/spec/helpers/products_helper_spec.rb +224 -0
- data/spec/lib/calculated_adjustments_spec.rb +7 -0
- data/spec/lib/i18n_spec.rb +123 -0
- data/spec/lib/search/base_spec.rb +86 -0
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +101 -0
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +95 -0
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +17 -0
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +16 -0
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +39 -0
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +22 -0
- data/spec/lib/spree/core/importer/order_spec.rb +502 -0
- data/spec/lib/spree/core/validators/email_spec.rb +53 -0
- data/spec/lib/spree/localized_number_spec.rb +38 -0
- data/spec/lib/spree/migrations_spec.rb +34 -0
- data/spec/lib/spree/money_spec.rb +122 -0
- data/spec/lib/tasks/exchanges_spec.rb +136 -0
- data/spec/mailers/order_mailer_spec.rb +124 -0
- data/spec/mailers/reimbursement_mailer_spec.rb +47 -0
- data/spec/mailers/shipment_mailer_spec.rb +63 -0
- data/spec/mailers/test_mailer_spec.rb +24 -0
- data/spec/models/spree/ability_spec.rb +246 -0
- data/spec/models/spree/address_spec.rb +291 -0
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +286 -0
- data/spec/models/spree/adjustment_spec.rb +163 -0
- data/spec/models/spree/app_configuration_spec.rb +23 -0
- data/spec/models/spree/asset_spec.rb +25 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +127 -0
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +25 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +47 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +41 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +15 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +30 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +51 -0
- data/spec/models/spree/calculator/shipping.rb +8 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +23 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +13 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +52 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +20 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +29 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +40 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +51 -0
- data/spec/models/spree/calculator_spec.rb +69 -0
- data/spec/models/spree/classification_spec.rb +93 -0
- data/spec/models/spree/concerns/display_money_spec.rb +43 -0
- data/spec/models/spree/country_spec.rb +18 -0
- data/spec/models/spree/credit_card_spec.rb +324 -0
- data/spec/models/spree/customer_return_spec.rb +262 -0
- data/spec/models/spree/exchange_spec.rb +75 -0
- data/spec/models/spree/gateway/bogus_simple.rb +20 -0
- data/spec/models/spree/gateway/bogus_spec.rb +13 -0
- data/spec/models/spree/gateway_spec.rb +54 -0
- data/spec/models/spree/image_spec.rb +5 -0
- data/spec/models/spree/inventory_unit_spec.rb +242 -0
- data/spec/models/spree/line_item_spec.rb +267 -0
- data/spec/models/spree/option_type_spec.rb +14 -0
- data/spec/models/spree/option_value_spec.rb +13 -0
- data/spec/models/spree/order/address_spec.rb +50 -0
- data/spec/models/spree/order/adjustments_spec.rb +29 -0
- data/spec/models/spree/order/callbacks_spec.rb +42 -0
- data/spec/models/spree/order/checkout_spec.rb +764 -0
- data/spec/models/spree/order/currency_updater_spec.rb +32 -0
- data/spec/models/spree/order/finalizing_spec.rb +117 -0
- data/spec/models/spree/order/helpers_spec.rb +5 -0
- data/spec/models/spree/order/payment_spec.rb +214 -0
- data/spec/models/spree/order/risk_assessment_spec.rb +84 -0
- data/spec/models/spree/order/shipments_spec.rb +43 -0
- data/spec/models/spree/order/state_machine_spec.rb +216 -0
- data/spec/models/spree/order/tax_spec.rb +84 -0
- data/spec/models/spree/order/totals_spec.rb +24 -0
- data/spec/models/spree/order/updating_spec.rb +18 -0
- data/spec/models/spree/order/validations_spec.rb +15 -0
- data/spec/models/spree/order_contents_spec.rb +256 -0
- data/spec/models/spree/order_inventory_spec.rb +228 -0
- data/spec/models/spree/order_merger_spec.rb +133 -0
- data/spec/models/spree/order_spec.rb +954 -0
- data/spec/models/spree/order_updater_spec.rb +283 -0
- data/spec/models/spree/payment/gateway_options_spec.rb +119 -0
- data/spec/models/spree/payment_method_spec.rb +95 -0
- data/spec/models/spree/payment_spec.rb +926 -0
- data/spec/models/spree/preference_spec.rb +80 -0
- data/spec/models/spree/preferences/configuration_spec.rb +30 -0
- data/spec/models/spree/preferences/preferable_spec.rb +348 -0
- data/spec/models/spree/preferences/scoped_store_spec.rb +58 -0
- data/spec/models/spree/preferences/store_spec.rb +46 -0
- data/spec/models/spree/price_spec.rb +42 -0
- data/spec/models/spree/product/scopes_spec.rb +148 -0
- data/spec/models/spree/product_duplicator_spec.rb +103 -0
- data/spec/models/spree/product_filter_spec.rb +26 -0
- data/spec/models/spree/product_option_type_spec.rb +5 -0
- data/spec/models/spree/product_property_spec.rb +11 -0
- data/spec/models/spree/product_spec.rb +474 -0
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +50 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +148 -0
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +86 -0
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +36 -0
- data/spec/models/spree/promotion/rules/first_order_spec.rb +75 -0
- data/spec/models/spree/promotion/rules/item_total_spec.rb +282 -0
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +42 -0
- data/spec/models/spree/promotion/rules/option_value_spec.rb +90 -0
- data/spec/models/spree/promotion/rules/product_spec.rb +143 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +102 -0
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +27 -0
- data/spec/models/spree/promotion/rules/user_spec.rb +37 -0
- data/spec/models/spree/promotion_action_spec.rb +10 -0
- data/spec/models/spree/promotion_category_spec.rb +17 -0
- data/spec/models/spree/promotion_handler/cart_spec.rb +102 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +323 -0
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +48 -0
- data/spec/models/spree/promotion_handler/page_spec.rb +44 -0
- data/spec/models/spree/promotion_rule_spec.rb +29 -0
- data/spec/models/spree/promotion_spec.rb +603 -0
- data/spec/models/spree/property_spec.rb +5 -0
- data/spec/models/spree/prototype_spec.rb +5 -0
- data/spec/models/spree/refund_spec.rb +195 -0
- data/spec/models/spree/reimbursement/credit_spec.rb +36 -0
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +140 -0
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +83 -0
- data/spec/models/spree/reimbursement_performer_spec.rb +30 -0
- data/spec/models/spree/reimbursement_spec.rb +215 -0
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +51 -0
- data/spec/models/spree/reimbursement_type/credit_spec.rb +53 -0
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +46 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +55 -0
- data/spec/models/spree/return_authorization_spec.rb +250 -0
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +77 -0
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +58 -0
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +61 -0
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +32 -0
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +29 -0
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +35 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +65 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +43 -0
- data/spec/models/spree/return_item_spec.rb +682 -0
- data/spec/models/spree/returns_calculator_spec.rb +14 -0
- data/spec/models/spree/shipment_spec.rb +740 -0
- data/spec/models/spree/shipping_calculator_spec.rb +45 -0
- data/spec/models/spree/shipping_category_spec.rb +5 -0
- data/spec/models/spree/shipping_method_spec.rb +88 -0
- data/spec/models/spree/shipping_rate_spec.rb +141 -0
- data/spec/models/spree/state_spec.rb +18 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +36 -0
- data/spec/models/spree/stock/content_item_spec.rb +22 -0
- data/spec/models/spree/stock/coordinator_spec.rb +51 -0
- data/spec/models/spree/stock/differentiator_spec.rb +39 -0
- data/spec/models/spree/stock/estimator_spec.rb +154 -0
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +38 -0
- data/spec/models/spree/stock/package_spec.rb +194 -0
- data/spec/models/spree/stock/packer_spec.rb +70 -0
- data/spec/models/spree/stock/prioritizer_spec.rb +125 -0
- data/spec/models/spree/stock/quantifier_spec.rb +97 -0
- data/spec/models/spree/stock/splitter/backordered_spec.rb +29 -0
- data/spec/models/spree/stock/splitter/base_spec.rb +21 -0
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +47 -0
- data/spec/models/spree/stock/splitter/weight_spec.rb +32 -0
- data/spec/models/spree/stock_item_spec.rb +410 -0
- data/spec/models/spree/stock_location_spec.rb +243 -0
- data/spec/models/spree/stock_movement_spec.rb +56 -0
- data/spec/models/spree/stock_transfer_spec.rb +50 -0
- data/spec/models/spree/store_spec.rb +50 -0
- data/spec/models/spree/tax_category_spec.rb +27 -0
- data/spec/models/spree/tax_rate_spec.rb +382 -0
- data/spec/models/spree/taxon_spec.rb +74 -0
- data/spec/models/spree/taxonomy_spec.rb +18 -0
- data/spec/models/spree/tracker_spec.rb +21 -0
- data/spec/models/spree/user_spec.rb +130 -0
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +24 -0
- data/spec/models/spree/variant_spec.rb +523 -0
- data/spec/models/spree/zone_spec.rb +444 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/big_decimal.rb +5 -0
- data/spec/support/concerns/adjustment_source_spec.rb +23 -0
- data/spec/support/concerns/default_price_spec.rb +28 -0
- data/spec/support/rake.rb +13 -0
- data/spec/support/test_gateway.rb +2 -0
- data/spree_core.gemspec +48 -0
- metadata +185 -4
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::ReimbursementPerformer, :type => :model do
|
4
|
+
let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
|
5
|
+
let(:return_item) { reimbursement.return_items.first }
|
6
|
+
let(:reimbursement_type) { double("ReimbursementType") }
|
7
|
+
let(:reimbursement_type_hash) { { reimbursement_type => [return_item]} }
|
8
|
+
|
9
|
+
before do
|
10
|
+
expect(Spree::ReimbursementPerformer).to receive(:calculate_reimbursement_types).and_return(reimbursement_type_hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".simulate" do
|
14
|
+
subject { Spree::ReimbursementPerformer.simulate(reimbursement) }
|
15
|
+
|
16
|
+
it "reimburses each calculated reimbursement types with the correct return items as a simulation" do
|
17
|
+
expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], true)
|
18
|
+
subject
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.perform' do
|
23
|
+
subject { Spree::ReimbursementPerformer.perform(reimbursement) }
|
24
|
+
|
25
|
+
it "reimburses each calculated reimbursement types with the correct return items as a simulation" do
|
26
|
+
expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], false)
|
27
|
+
subject
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Reimbursement, type: :model do
|
4
|
+
|
5
|
+
describe ".before_create" do
|
6
|
+
describe "#generate_number" do
|
7
|
+
context "number is assigned" do
|
8
|
+
let(:number) { '123' }
|
9
|
+
let(:reimbursement) { Spree::Reimbursement.new(number: number) }
|
10
|
+
|
11
|
+
it "should return the assigned number" do
|
12
|
+
reimbursement.save
|
13
|
+
expect(reimbursement.number).to eq number
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "number is not assigned" do
|
18
|
+
let(:reimbursement) { Spree::Reimbursement.new(number: nil) }
|
19
|
+
|
20
|
+
before do
|
21
|
+
allow(reimbursement).to receive_messages(valid?: true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should assign number with random RI number" do
|
25
|
+
reimbursement.save
|
26
|
+
expect(reimbursement.number).to be =~ /RI\d{9}/
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#display_total" do
|
33
|
+
let(:total) { 100.50 }
|
34
|
+
let(:currency) { "USD" }
|
35
|
+
let(:order) { Spree::Order.new(currency: currency) }
|
36
|
+
let(:reimbursement) { Spree::Reimbursement.new(total: total, order: order) }
|
37
|
+
|
38
|
+
subject { reimbursement.display_total }
|
39
|
+
|
40
|
+
it "returns the value as a Spree::Money instance" do
|
41
|
+
expect(subject).to eq Spree::Money.new(total)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "uses the order's currency" do
|
45
|
+
expect(subject.money.currency.to_s).to eq currency
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#perform!" do
|
50
|
+
let!(:adjustments) { [] } # placeholder to ensure it gets run prior the "before" at this level
|
51
|
+
|
52
|
+
let!(:tax_rate) { nil }
|
53
|
+
let!(:tax_zone) { create(:zone, default_tax: true) }
|
54
|
+
|
55
|
+
let(:order) { create(:order_with_line_items, state: 'payment', line_items_count: 1, line_items_price: line_items_price, shipment_cost: 0) }
|
56
|
+
let(:line_items_price) { BigDecimal.new(10) }
|
57
|
+
let(:line_item) { order.line_items.first }
|
58
|
+
let(:inventory_unit) { line_item.inventory_units.first }
|
59
|
+
let(:payment) { build(:payment, amount: payment_amount, order: order, state: 'completed') }
|
60
|
+
let(:payment_amount) { order.total }
|
61
|
+
let(:customer_return) { build(:customer_return, return_items: [return_item]) }
|
62
|
+
let(:return_item) { build(:return_item, inventory_unit: inventory_unit) }
|
63
|
+
|
64
|
+
let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
|
65
|
+
|
66
|
+
let(:reimbursement) { create(:reimbursement, customer_return: customer_return, order: order, return_items: [return_item]) }
|
67
|
+
|
68
|
+
subject { reimbursement.perform! }
|
69
|
+
|
70
|
+
before do
|
71
|
+
order.shipments.each do |shipment|
|
72
|
+
shipment.inventory_units.update_all state: 'shipped'
|
73
|
+
shipment.update_column('state', 'shipped')
|
74
|
+
end
|
75
|
+
order.reload
|
76
|
+
order.update!
|
77
|
+
if payment
|
78
|
+
payment.save!
|
79
|
+
order.next! # confirm
|
80
|
+
end
|
81
|
+
order.next! # completed
|
82
|
+
customer_return.save!
|
83
|
+
return_item.accept!
|
84
|
+
end
|
85
|
+
|
86
|
+
it "refunds the total amount" do
|
87
|
+
subject
|
88
|
+
expect(reimbursement.unpaid_amount).to eq 0
|
89
|
+
end
|
90
|
+
|
91
|
+
it "creates a refund" do
|
92
|
+
expect {
|
93
|
+
subject
|
94
|
+
}.to change{ Spree::Refund.count }.by(1)
|
95
|
+
expect(Spree::Refund.last.amount).to eq order.total
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with additional tax' do
|
99
|
+
let!(:tax_rate) { create(:tax_rate, name: "Sales Tax", amount: 0.10, included_in_price: false, zone: tax_zone) }
|
100
|
+
|
101
|
+
it 'saves the additional tax and refunds the total' do
|
102
|
+
expect {
|
103
|
+
subject
|
104
|
+
}.to change { Spree::Refund.count }.by(1)
|
105
|
+
return_item.reload
|
106
|
+
expect(return_item.additional_tax_total).to be > 0
|
107
|
+
expect(return_item.additional_tax_total).to eq line_item.additional_tax_total
|
108
|
+
expect(reimbursement.total).to eq line_item.pre_tax_amount + line_item.additional_tax_total
|
109
|
+
expect(Spree::Refund.last.amount).to eq line_item.pre_tax_amount + line_item.additional_tax_total
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'with included tax' do
|
114
|
+
let!(:tax_rate) { create(:tax_rate, name: "VAT Tax", amount: 0.1, included_in_price: true, zone: tax_zone) }
|
115
|
+
|
116
|
+
it 'saves the included tax and refunds the total' do
|
117
|
+
expect {
|
118
|
+
subject
|
119
|
+
}.to change { Spree::Refund.count }.by(1)
|
120
|
+
return_item.reload
|
121
|
+
expect(return_item.included_tax_total).to be < 0
|
122
|
+
expect(return_item.included_tax_total).to eq line_item.included_tax_total
|
123
|
+
expect(reimbursement.total).to eq (line_item.pre_tax_amount + line_item.included_tax_total).round(2)
|
124
|
+
expect(Spree::Refund.last.amount).to eq (line_item.pre_tax_amount + line_item.included_tax_total).round(2)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when reimbursement cannot be fully performed' do
|
129
|
+
let!(:non_return_refund) { create(:refund, amount: 1, payment: payment) }
|
130
|
+
|
131
|
+
it 'raises IncompleteReimbursement error' do
|
132
|
+
expect { subject }.to raise_error(Spree::Reimbursement::IncompleteReimbursementError)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "when exchange is required" do
|
137
|
+
let(:exchange_variant) { build(:variant) }
|
138
|
+
before { return_item.exchange_variant = exchange_variant }
|
139
|
+
it "generates an exchange shipment for the order for the exchange items" do
|
140
|
+
expect { subject }.to change { order.reload.shipments.count }.by 1
|
141
|
+
expect(order.shipments.last.inventory_units.first.variant).to eq exchange_variant
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it "triggers the reimbursement mailer to be sent" do
|
146
|
+
expect(Spree::ReimbursementMailer).to receive(:reimbursement_email).with(reimbursement.id) { double(deliver_later: true) }
|
147
|
+
subject
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "#return_items_requiring_exchange" do
|
152
|
+
it "returns only the return items that require an exchange" do
|
153
|
+
return_items = [double(exchange_required?: true), double(exchange_required?: true),double(exchange_required?: false)]
|
154
|
+
allow(subject).to receive(:return_items) { return_items }
|
155
|
+
expect(subject.return_items_requiring_exchange).to eq return_items.take(2)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#calculated_total" do
|
160
|
+
context 'with return item amounts that would round up if added' do
|
161
|
+
let(:reimbursement) { Spree::Reimbursement.new }
|
162
|
+
|
163
|
+
subject { reimbursement.calculated_total }
|
164
|
+
|
165
|
+
before do
|
166
|
+
reimbursement.return_items << Spree::ReturnItem.new(pre_tax_amount: 10.003)
|
167
|
+
reimbursement.return_items << Spree::ReturnItem.new(pre_tax_amount: 10.003)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'rounds down' do
|
171
|
+
expect(subject).to eq 20
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'with a return item amount that should round up' do
|
176
|
+
let(:reimbursement) { Spree::Reimbursement.new }
|
177
|
+
|
178
|
+
subject { reimbursement.calculated_total }
|
179
|
+
|
180
|
+
before do
|
181
|
+
reimbursement.return_items << Spree::ReturnItem.new(pre_tax_amount: 19.998)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'rounds up' do
|
185
|
+
expect(subject).to eq 20
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '.build_from_customer_return' do
|
191
|
+
let(:customer_return) { create(:customer_return, line_items_count: 5) }
|
192
|
+
|
193
|
+
let!(:pending_return_item) { customer_return.return_items.first.tap { |ri| ri.update!(acceptance_status: 'pending') } }
|
194
|
+
let!(:accepted_return_item) { customer_return.return_items.second.tap(&:accept!) }
|
195
|
+
let!(:rejected_return_item) { customer_return.return_items.third.tap(&:reject!) }
|
196
|
+
let!(:manual_intervention_return_item) { customer_return.return_items.fourth.tap(&:require_manual_intervention!) }
|
197
|
+
let!(:already_reimbursed_return_item) { customer_return.return_items.fifth }
|
198
|
+
|
199
|
+
let!(:previous_reimbursement) { create(:reimbursement, order: customer_return.order, return_items: [already_reimbursed_return_item]) }
|
200
|
+
|
201
|
+
subject { Spree::Reimbursement.build_from_customer_return(customer_return) }
|
202
|
+
|
203
|
+
it 'connects to the accepted return items' do
|
204
|
+
expect(subject.return_items.to_a).to eq [accepted_return_item]
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'connects to the order' do
|
208
|
+
expect(subject.order).to eq customer_return.order
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'connects to the customer_return' do
|
212
|
+
expect(subject.customer_return).to eq customer_return
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::ReimbursementTaxCalculator, :type => :model do
|
4
|
+
|
5
|
+
let!(:tax_rate) { nil }
|
6
|
+
|
7
|
+
let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
|
8
|
+
let(:return_item) { reimbursement.return_items.first }
|
9
|
+
let(:line_item) { return_item.inventory_unit.line_item }
|
10
|
+
|
11
|
+
subject do
|
12
|
+
Spree::ReimbursementTaxCalculator.call(reimbursement)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without taxes' do
|
16
|
+
let!(:tax_rate) { nil }
|
17
|
+
|
18
|
+
it 'leaves the return items additional_tax_total and included_tax_total at zero' do
|
19
|
+
subject
|
20
|
+
|
21
|
+
expect(return_item.additional_tax_total).to eq 0
|
22
|
+
expect(return_item.included_tax_total).to eq 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with additional tax' do
|
27
|
+
let!(:tax_rate) { create(:tax_rate, name: "Sales Tax", amount: 0.10, included_in_price: false, zone: tax_zone) }
|
28
|
+
let(:tax_zone) { create(:zone, default_tax: true) }
|
29
|
+
|
30
|
+
it 'sets additional_tax_total on the return items' do
|
31
|
+
subject
|
32
|
+
return_item.reload
|
33
|
+
|
34
|
+
expect(return_item.additional_tax_total).to be > 0
|
35
|
+
expect(return_item.additional_tax_total).to eq line_item.additional_tax_total
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with included tax' do
|
40
|
+
let!(:tax_rate) { create(:tax_rate, name: "VAT Tax", amount: 0.1, included_in_price: true, zone: tax_zone) }
|
41
|
+
let(:tax_zone) { create(:zone, default_tax: true) }
|
42
|
+
|
43
|
+
it 'sets included_tax_total on the return items' do
|
44
|
+
subject
|
45
|
+
return_item.reload
|
46
|
+
|
47
|
+
expect(return_item.included_tax_total).to be < 0
|
48
|
+
expect(return_item.included_tax_total).to eq line_item.included_tax_total
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe ReimbursementType::Credit, :type => :model do
|
5
|
+
let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
|
6
|
+
let(:return_item) { reimbursement.return_items.first }
|
7
|
+
let(:payment) { reimbursement.order.payments.first }
|
8
|
+
let(:simulate) { false }
|
9
|
+
let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
|
10
|
+
let(:creditable) { DummyCreditable.new(amount: 99.99) }
|
11
|
+
|
12
|
+
class DummyCreditable < Spree::Base
|
13
|
+
attr_accessor :amount
|
14
|
+
self.table_name = 'spree_payments' # Your creditable class should not use this table
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { Spree::ReimbursementType::Credit.reimburse(reimbursement, [return_item], simulate)}
|
18
|
+
|
19
|
+
before do
|
20
|
+
reimbursement.update!(total: reimbursement.calculated_total)
|
21
|
+
allow(Spree::ReimbursementType::Credit).to receive(:create_creditable).and_return(creditable)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.reimburse' do
|
25
|
+
context 'simulate is true' do
|
26
|
+
let(:simulate) { true }
|
27
|
+
|
28
|
+
it 'creates one readonly lump credit for all outstanding balance payable to the customer' do
|
29
|
+
expect(subject.map(&:class)).to eq [Spree::Reimbursement::Credit]
|
30
|
+
expect(subject.map(&:readonly?)).to eq [true]
|
31
|
+
expect(subject.sum(&:amount)).to eq reimbursement.return_items.to_a.sum(&:total)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'does not save to the database' do
|
35
|
+
expect { subject }.to_not change { Spree::Reimbursement::Credit.count }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'simulate is false' do
|
40
|
+
let(:simulate) { false }
|
41
|
+
|
42
|
+
before do
|
43
|
+
expect(creditable).to receive(:save).and_return(true)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'creates one lump credit for all outstanding balance payable to the customer' do
|
47
|
+
expect { subject }.to change { Spree::Reimbursement::Credit.count }.by(1)
|
48
|
+
expect(subject.sum(&:amount)).to eq reimbursement.return_items.to_a.sum(&:total)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe ReimbursementType::Exchange, :type => :model do
|
5
|
+
describe '.reimburse' do
|
6
|
+
let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
|
7
|
+
let(:return_items) { reimbursement.return_items }
|
8
|
+
let(:new_exchange) { double("Exchange") }
|
9
|
+
let(:simulate) { true }
|
10
|
+
|
11
|
+
subject { Spree::ReimbursementType::Exchange.reimburse(reimbursement, return_items, simulate)}
|
12
|
+
|
13
|
+
context 'return items are supplied' do
|
14
|
+
before do
|
15
|
+
expect(Spree::Exchange).to receive(:new).with(reimbursement.order, return_items).and_return(new_exchange)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "simulate is true" do
|
19
|
+
|
20
|
+
it 'does not perform an exchange and returns the exchange object' do
|
21
|
+
expect(new_exchange).not_to receive(:perform!)
|
22
|
+
expect(subject).to eq [new_exchange]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "simulate is false" do
|
27
|
+
let(:simulate) { false }
|
28
|
+
|
29
|
+
it 'performs an exchange and returns the exchange object' do
|
30
|
+
expect(new_exchange).to receive(:perform!)
|
31
|
+
expect(subject).to eq [new_exchange]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "no return items are supplied" do
|
37
|
+
let(:return_items) { [] }
|
38
|
+
|
39
|
+
it 'does not perform an exchange and returns an empty array' do
|
40
|
+
expect(new_exchange).not_to receive(:perform!)
|
41
|
+
expect(subject).to eq []
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe ReimbursementType::OriginalPayment, :type => :model do
|
5
|
+
let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
|
6
|
+
let(:return_item) { reimbursement.return_items.first }
|
7
|
+
let(:payment) { reimbursement.order.payments.first }
|
8
|
+
let(:simulate) { false }
|
9
|
+
let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
|
10
|
+
|
11
|
+
subject { Spree::ReimbursementType::OriginalPayment.reimburse(reimbursement, [return_item], simulate)}
|
12
|
+
|
13
|
+
before { reimbursement.update!(total: reimbursement.calculated_total) }
|
14
|
+
|
15
|
+
describe ".reimburse" do
|
16
|
+
context "simulate is true" do
|
17
|
+
let(:simulate) { true }
|
18
|
+
|
19
|
+
it "returns an array of readonly refunds" do
|
20
|
+
expect(subject.map(&:class)).to eq [Spree::Refund]
|
21
|
+
expect(subject.map(&:readonly?)).to eq [true]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "simulate is false" do
|
26
|
+
it 'performs the refund' do
|
27
|
+
expect {
|
28
|
+
subject
|
29
|
+
}.to change { payment.refunds.count }.by(1)
|
30
|
+
expect(payment.refunds.sum(:amount)).to eq reimbursement.return_items.to_a.sum(&:total)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when no credit is allowed on the payment' do
|
35
|
+
before do
|
36
|
+
expect_any_instance_of(Spree::Payment).to receive(:credit_allowed).and_return 0
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns an empty array' do
|
40
|
+
expect(subject).to eq []
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when a payment is negative' do
|
45
|
+
before do
|
46
|
+
expect_any_instance_of(Spree::Payment).to receive(:amount).and_return -100
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns an empty array' do
|
50
|
+
expect(subject).to eq []
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|