Skip to content

Commit

Permalink
Fix broken create(:return_item) factory calls
Browse files Browse the repository at this point in the history
create(:return_item) causes the DefaultRefundAmount calculator to
be called, which expects an order to be set on the return item's
inventory unit[1]. However, the order is nil in the inventory_unit
factory that comes with Solidus[2], so we need to set an order
manually.

[1]: solidusio/solidus@06df181#diff-fb6cfba1ceafec4b06ee8ec4ccb986beR4
[2]: https://github.com/solidusio/solidus/blob/749691ecaa2e231b3ccc027d038fc07820190177/core/lib/spree/testing_support/factories/inventory_unit_factory.rb#L11
  • Loading branch information
aldesantis committed Sep 13, 2019
1 parent d1a5772 commit fc8193f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
10 changes: 8 additions & 2 deletions spec/mailers/solidus_quiet_logistics/inbound/rma_mailer_spec.rb
Expand Up @@ -8,8 +8,14 @@
let(:return_authorization) { create(:return_authorization) }
let(:return_items) do
[
create(:return_item, return_authorization: return_authorization),
create(:return_item, return_authorization: return_authorization),
create(:return_item,
inventory_unit: create(:inventory_unit, order: create(:order)),
return_authorization: return_authorization,
),
create(:return_item,
inventory_unit: create(:inventory_unit, order: create(:order)),
return_authorization: return_authorization,
),
]
end

Expand Down
Expand Up @@ -78,9 +78,24 @@ def parse_items(document)

let(:variant) { create(:variant, sku: '050-00400') }

let!(:good_return_item) { create(:return_item, return_authorization: return_authorization) }
let!(:damaged_return_item) { create(:return_item, return_authorization: return_authorization) }
let!(:incorrect_return_item) { create(:return_item, return_authorization: return_authorization) }
let!(:good_return_item) do
create(:return_item,
inventory_unit: create(:inventory_unit, order: create(:order), state: 'shipped'),
return_authorization: return_authorization,
)
end
let!(:damaged_return_item) do
create(:return_item,
inventory_unit: create(:inventory_unit, order: create(:order), state: 'shipped'),
return_authorization: return_authorization,
)
end
let!(:incorrect_return_item) do
create(:return_item,
inventory_unit: create(:inventory_unit, order: create(:order), state: 'shipped'),
return_authorization: return_authorization,
)
end

let(:rma_document_to_customer_mailer) { instance_double('ActionMailer::Delivery') }
let(:rma_document_to_suppport_mailer) { instance_double('ActionMailer::Delivery') }
Expand All @@ -99,6 +114,7 @@ def parse_items(document)
end

it 'refunds the correct return items and sends an email to the support for the incorrect return items' do

expect(rma_document_to_customer_mailer).to receive(:deliver_later)
expect(rma_document_to_suppport_mailer).to receive(:deliver_later)

Expand Down
Expand Up @@ -39,7 +39,7 @@
let!(:first_return_item) do
create(
:return_item,
inventory_unit: create(:inventory_unit, variant: first_variant),
inventory_unit: create(:inventory_unit, order: create(:order), variant: first_variant),
return_authorization: return_authorization,
return_reason: return_reason,
)
Expand All @@ -48,7 +48,7 @@
let!(:second_return_item) do
create(
:return_item,
inventory_unit: create(:inventory_unit, variant: first_variant),
inventory_unit: create(:inventory_unit, order: create(:order), variant: first_variant),
return_authorization: return_authorization,
return_reason: return_reason,
)
Expand All @@ -57,7 +57,7 @@
let!(:third_return_item) do
create(
:return_item,
inventory_unit: create(:inventory_unit, variant: first_variant),
inventory_unit: create(:inventory_unit, order: create(:order), variant: first_variant),
return_authorization: return_authorization,
return_reason: create(:return_reason),
)
Expand All @@ -66,7 +66,7 @@
let!(:fourth_return_item) do
create(
:return_item,
inventory_unit: create(:inventory_unit, variant: second_variant),
inventory_unit: create(:inventory_unit, order: create(:order), variant: second_variant),
return_authorization: return_authorization,
return_reason: return_reason,
)
Expand Down

0 comments on commit fc8193f

Please sign in to comment.