From 47d5fe909ed4cb1cdb0ac15c9495271cf6b9cfa5 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 11 Jul 2023 16:58:54 +1000 Subject: [PATCH] Deduplicate order2 setup --- ...ry_fee_with_tax_report_by_producer_spec.rb | 93 +++++++------------ 1 file changed, 34 insertions(+), 59 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 48faca241f..c789930387 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -151,7 +151,23 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end order } - let!(:order2) { create(:order_with_distributor, distributor:) } + + let!(:order2) { + order2 = create(:order_with_distributor, distributor:, order_cycle_id: order_cycle2.id, + ship_address_id: ship_address.id) + + order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) + + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order2.recreate_all_fees! + while !order2.completed? + break unless order2.next! + end + + order2 + } before do product.update!({ @@ -172,22 +188,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # - outgoing exchange (10) 1.5% = 0.15, 2.5% = 0.25 # - line items (50) 1.5% = 0.75, 2.5% = 1.25 - before do - # adds a line items to the order on oc2 - order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) - order2.update!({ - order_cycle_id: order_cycle2.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order2.recreate_all_fees! - while !order2.completed? - break unless order2.next! - end - end - describe "orders" do # for supplier 1, oc1 @@ -607,22 +607,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:included_in_price) { true } - before do - # adds a line items to the order on oc2 - order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) - order2.update!({ - order_cycle_id: order_cycle2.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order2.recreate_all_fees! - while !order2.completed? - break unless order2.next! - end - end - let(:coordinator_state_tax1){ ["Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") @@ -763,19 +747,24 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do name: 'Another State Tax', amount: 0.02, included_in_price:) } - context "added tax" do - before do - # adds a line items to the order on oc2 - order2.line_items.create({ variant:, quantity: 1, price: 50 }) - order2.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: another_address.id - }) - order2.recreate_all_fees! - while !order2.completed? - break unless order2.next! - end + let!(:order2) { + # Ensure tax rates set up first + state_tax_rate2 + + order2 = create(:order_with_distributor, distributor:, order_cycle_id: order_cycle.id, + ship_address_id: another_address.id) + + # adds a line items to the order on oc2 + order2.line_items.create({ variant:, quantity: 1, price: 50 }) + order2.recreate_all_fees! + while !order2.completed? + break unless order2.next! end + + order2 + } + + context "added tax" do let(:admin_state_tax1){ [ "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", @@ -875,20 +864,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "included tax" do let(:included_in_price) { true } - before do - # adds a line items to the order on oc2 - order2.line_items.create({ variant:, quantity: 1, price: 50 }) - order2.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: another_address.id - }) - - order2.recreate_all_fees! - while !order2.completed? - break unless order2.next! - end - end - let(:admin_state_tax1){ [ "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin",