Skip to content

Commit

Permalink
Restructures tax ex-/included as shared examples
Browse files Browse the repository at this point in the history
  • Loading branch information
filipefurtad0 committed Oct 9, 2023
1 parent 1c9bd90 commit fa8e329
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 42 deletions.
27 changes: 27 additions & 0 deletions spec/services/order_invoice_comparator_shared_examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@
end
end

shared_examples "attribute changes - tax total changes" do |boolean, type, included_boolean|
let(:order) do
create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1,
included_in_price: included_boolean)
.tap do |order|
order.create_tax_charge!
order.update_shipping_fees!
end
end

context "if included is #{included_boolean}" do
before do
Spree::TaxRate.first.update!(amount: 0.15)
order.create_tax_charge!
end

it "returns #{boolean} if a #{type} attribute changes" do
order.reload
expect(subject).to be true
end
end
end

describe OrderInvoiceComparator do
describe '#can_generate_new_invoice?' do
# this passes 'order' as argument to the invoice comparator
Expand All @@ -53,6 +76,8 @@
describe "detecting relevant" do
it_behaves_like "attribute changes - payment total", true, "relevant"
it_behaves_like "attribute changes - order total", true, "relevant"
it_behaves_like "attribute changes - tax total changes", true, "relevant", false
it_behaves_like "attribute changes - tax total changes", true, "relevant", true
end

describe "detecting non-relevant" do
Expand Down Expand Up @@ -83,6 +108,8 @@
describe "detecting non-relevant" do
it_behaves_like "attribute changes - payment total", false, "non-relevant"
it_behaves_like "attribute changes - order total", false, "non-relevant"
it_behaves_like "attribute changes - tax total changes", false, "non-relevant", false
it_behaves_like "attribute changes - tax total changes", false, "non-relevant", true
end
end
end
Expand Down
42 changes: 0 additions & 42 deletions spec/services/order_invoice_comparator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,6 @@

context "changes on the order object" do
describe "detecting relevant attribute changes" do
it "returns true if a relevant attribute changes" do
Spree::Order.where(id: order.id).update_all(total: order.total + 10)
order.reload
expect(subject).to be true
end

context "additional tax total changes" do
let(:order) do
create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1,
included_in_price: false)
.tap do |order|
order.create_tax_charge!
order.update_shipping_fees!
end
end

it "returns true" do
Spree::TaxRate.first.update!(amount: 0.15)
order.create_tax_charge!
order.reload
expect(subject).to be true
end
end

context "included tax total changes" do
let(:order) do
create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1,
included_in_price: true)
.tap do |order|
order.create_tax_charge!
order.update_shipping_fees!
end
end

it "returns true" do
Spree::TaxRate.first.update!(amount: 0.15)
order.create_tax_charge!
order.reload
expect(subject).to be true
end
end

context "shipping method changes" do
let(:shipping_method) { create(:shipping_method) }
it "returns true" do
Expand Down

0 comments on commit fa8e329

Please sign in to comment.