From 07774c4572294076bca97166258b833fca9de498 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 3 Jul 2023 16:38:16 +0100 Subject: [PATCH] Update tax category specs --- .../unit/admin/bulk_product_update_spec.js.coffee | 9 ++++----- .../enterprise_fee_applicator_spec.rb | 9 ++++----- .../orders_cycle_supplier_totals_report_spec.rb | 14 +++++++++++--- spec/mailers/producer_mailer_spec.rb | 2 +- spec/models/spree/adjustment_spec.rb | 4 ++-- .../services/order_tax_adjustments_fetcher_spec.rb | 4 +--- spec/system/admin/product_import_spec.rb | 2 +- .../sales_tax/sales_tax_totals_by_order_spec.rb | 6 ++---- .../sales_tax/sales_tax_totals_by_producer_spec.rb | 9 +++------ spec/system/admin/reports_spec.rb | 6 +++--- .../consumer/split_checkout_tax_not_incl_spec.rb | 2 +- 11 files changed, 33 insertions(+), 34 deletions(-) diff --git a/spec/javascripts/unit/admin/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/admin/bulk_product_update_spec.js.coffee index cae859743c..28ff35e1e8 100644 --- a/spec/javascripts/unit/admin/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/admin/bulk_product_update_spec.js.coffee @@ -187,7 +187,6 @@ describe "filtering products for submission to database", -> description: "" deleted_at: null meta_keywords: null - tax_category_id: null shipping_category_id: null created_at: null updated_at: null @@ -205,6 +204,7 @@ describe "filtering products for submission to database", -> on_hand: 2 price: 10.0 unit_value: 250 + tax_category_id: null unit_description: "(bottle)" display_as: "bottle" display_name: "nothing" @@ -221,7 +221,6 @@ describe "filtering products for submission to database", -> variant_unit: 'volume' variant_unit_scale: 1 variant_unit_name: 'loaf' - tax_category_id: null master_attributes: id: 2 unit_value: 250 @@ -231,6 +230,7 @@ describe "filtering products for submission to database", -> on_hand: 2 price: 10.0 unit_value: 250 + tax_category_id: null unit_description: "(bottle)" display_as: "bottle" display_name: "nothing" @@ -822,8 +822,8 @@ describe "AdminProductEditCtrl", -> expect(product).toEqual id: 123 variants: [ - {id: -1, price: null, unit_value: null, unit_description: null, on_demand: false, on_hand: null, display_as: null, display_name: null} - {id: -2, price: null, unit_value: null, unit_description: null, on_demand: false, on_hand: null, display_as: null, display_name: null} + {id: -1, price: null, unit_value: null, tax_category_id: null, unit_description: null, on_demand: false, on_hand: null, display_as: null, display_name: null} + {id: -2, price: null, unit_value: null, tax_category_id: null, unit_description: null, on_demand: false, on_hand: null, display_as: null, display_name: null} ] it "shows the variant(s)", -> @@ -978,7 +978,6 @@ describe "AdminProductEditCtrl", -> description: "" deleted_at: null meta_keywords: null - tax_category_id: null shipping_category_id: null created_at: null updated_at: null diff --git a/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb b/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb index 23d7952067..2beec77b17 100644 --- a/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb +++ b/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb @@ -5,15 +5,15 @@ require 'open_food_network/enterprise_fee_applicator' module OpenFoodNetwork describe EnterpriseFeeApplicator do - let(:line_item) { create(:line_item) } + let(:line_item) { create(:line_item, variant: target_variant) } let(:inherits_tax) { true } let(:enterprise_fee) { create(:enterprise_fee, inherits_tax_category: inherits_tax, tax_category: fee_tax_category) } let(:fee_tax_category) { nil } let(:tax_category) { create(:tax_category) } - let(:product) { create(:simple_product, tax_category: tax_category) } - let(:target_variant) { product.variants.first } + let!(:target_variant) { create(:variant, tax_category: tax_category) } + let(:product) { variant.product } let(:applicator) { EnterpriseFeeApplicator.new(enterprise_fee, target_variant, 'role') } describe "#create_line_item_adjustment" do @@ -37,10 +37,9 @@ module OpenFoodNetwork end describe "#create_order_adjustment" do - let(:target_variant) { nil } let(:inherits_tax) { false } let(:fee_tax_category) { tax_category } - let(:order) { line_item.order } + let(:order) { create(:order) } it "creates an adjustment for an order" do allow(applicator).to receive(:order_adjustment_label) { 'label' } diff --git a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb index 6dcba9b807..43f767faf8 100644 --- a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb @@ -105,8 +105,11 @@ describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotals do end context "with a VAT/GST-free supplier" do - before(:each) do + let(:tax_category) { create(:tax_category) } + + before do supplier.update(charges_sales_tax: false) + order.line_items.first.variant.update(tax_category_id: tax_category.id) end it "has a variant row when product belongs to a tax category" do @@ -122,7 +125,8 @@ describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotals do end it "has a variant row when product doesn't belong to a tax category" do - order.line_items.first.variant.product.update(tax_category_id: nil) + order.line_items.first.variant.update(tax_category_id: nil) + supplier_name_field = report_table.first[0] supplier_vat_status_field = report_table.first[-2] product_tax_category_field = report_table.first[-1] @@ -134,8 +138,11 @@ describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotals do end context "with a VAT/GST-enabled supplier" do + let(:tax_category) { create(:tax_category) } + before(:each) do supplier.update(charges_sales_tax: true) + order.line_items.first.variant.update(tax_category_id: tax_category.id) end it "has a variant row when product belongs to a tax category" do @@ -151,7 +158,8 @@ describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotals do end it "has a variant row when product doesn't belong to a tax category" do - order.line_items.first.variant.product.update(tax_category_id: nil) + order.line_items.first.variant.update(tax_category_id: nil) + supplier_name_field = report_table.first[0] supplier_vat_status_field = report_table.first[-2] product_tax_category_field = report_table.first[-1] diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 153b72aac4..8642ecdba4 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -16,7 +16,7 @@ describe ProducerMailer, type: :mailer do let(:d1) { create(:distributor_enterprise, charges_sales_tax: true) } let(:d2) { create(:distributor_enterprise) } let(:p1) { - create(:product, name: "Zebra", price: 12.34, supplier: s1, tax_category: tax_category) + create(:product, name: "Zebra", price: 12.34, supplier: s1, tax_category_id: tax_category.id) } let(:p2) { create(:product, name: "Aardvark", price: 23.45, supplier: s2) } let(:p3) { create(:product, name: "Banana", price: 34.56, supplier: s1) } diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 5e9e2197ea..b22c31a5c2 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -527,8 +527,8 @@ module Spree create(:tax_rate, included_in_price: included_in_price, zone: zone, calculator: ::Calculator::FlatRate.new(preferred_amount: 0.1)) } - let(:product) { create(:product, tax_category: tax_category) } - let(:variant) { product.variants.first } + let(:variant) { create(:variant, tax_category: tax_category) } + let(:product) { variant.product } describe "tax adjustment creation" do before do diff --git a/spec/services/order_tax_adjustments_fetcher_spec.rb b/spec/services/order_tax_adjustments_fetcher_spec.rb index 7b91f4ee1d..360fda1742 100644 --- a/spec/services/order_tax_adjustments_fetcher_spec.rb +++ b/spec/services/order_tax_adjustments_fetcher_spec.rb @@ -43,9 +43,7 @@ describe OrderTaxAdjustmentsFetcher do let(:tax_category25) { create(:tax_category, tax_rates: [tax_rate25]) } let(:tax_category30) { create(:tax_category, tax_rates: [tax_rate30]) } - let(:variant) do - create(:variant, product: create(:product, tax_category: tax_category10)) - end + let(:variant) { create(:variant, tax_category: tax_category10) } let(:enterprise_fee) do create(:enterprise_fee, enterprise: coordinator, tax_category: tax_category20, diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index f9c38aab50..fd2d1559c5 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -190,7 +190,7 @@ describe "Product Import" do expect(page).to have_no_selector '.updated-count' carrots = Spree::Product.find_by(name: 'Carrots') - expect(carrots.tax_category).to eq tax_category + expect(carrots.variants.first.tax_category).to eq tax_category expect(carrots.shipping_category).to eq shipping_category end diff --git a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb index 718ed1e3d3..f9ce7e273e 100644 --- a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb +++ b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb @@ -82,10 +82,8 @@ describe "Sales Tax Totals By order" do distributor.shipping_methods << shipping_method distributor.payment_methods << payment_method - product.update!( - tax_category_id: tax_category.id, - supplier_id: supplier.id - ) + product.update!(supplier_id: supplier.id) + variant.update!(tax_category_id: tax_category.id) order.update!( number: 'ORDER_NUMBER_1', diff --git a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb index b8cc954c15..9a1a9053d1 100644 --- a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb +++ b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb @@ -56,12 +56,9 @@ describe "Sales Tax Totals By Producer" do distributor.shipping_methods << shipping_method distributor.payment_methods << payment_method - supplier.update!({ name: 'Supplier', charges_sales_tax: true }) - - product.update!({ - tax_category_id: tax_category.id, - supplier_id: supplier.id - }) + supplier.update!(name: 'Supplier', charges_sales_tax: true) + product.update!(supplier_id: supplier.id) + variant.update!(tax_category_id: tax_category.id) end context 'added tax' do diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 6264aaee39..7681e1e96c 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -294,7 +294,7 @@ describe ' } let(:enterprise_fee) { create(:enterprise_fee, enterprise: user1.enterprises.first, - tax_category: product2.tax_category, + tax_category: product2.variants.first.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 120.0)) } let(:order_cycle) { @@ -588,12 +588,12 @@ describe ' let(:enterprise_fee1) { create(:enterprise_fee, enterprise: user1.enterprises.first, - tax_category: product2.tax_category, + tax_category: product2.variants.first.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 10)) } let(:enterprise_fee2) { create(:enterprise_fee, enterprise: user1.enterprises.first, - tax_category: product2.tax_category, + tax_category: product2.variants.first.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 20)) } let(:order_cycle) { diff --git a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb index 046a6ac483..a8c34f34c9 100644 --- a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb @@ -32,7 +32,7 @@ describe "As a consumer, I want to see adjustment breakdown" do let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true) } let(:supplier) { create(:supplier_enterprise) } let(:product_with_tax) { - create(:simple_product, supplier: supplier, price: 10, tax_category: tax_category) + create(:product, supplier: supplier, price: 10, tax_category_id: tax_category.id) } let(:variant_with_tax) { product_with_tax.variants.first } let(:order_cycle) {