From bd4b3110c1002648eba9d2b60bc2801bee669ee0 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 18 Nov 2022 11:08:18 +0100 Subject: [PATCH] test OrderCycleSupplierTotals with different combination: product with/without tax category, supplier enabled/disabled vat --- ...rders_cycle_supplier_totals_report_spec.rb | 66 +++++++++++++++++-- 1 file changed, 59 insertions(+), 7 deletions(-) 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 6f68c7f8dc..d5f01e114e 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 @@ -11,7 +11,9 @@ module Reporting let!(:order) do create(:completed_order_with_totals, line_items_count: 1, distributor: distributor) end - + let!(:supplier) do + order.line_items.first.variant.product.supplier + end let(:current_user) { distributor.owner } let(:params) { { display_summary_row: false } } let(:report) do @@ -29,17 +31,67 @@ module Reporting it "generates the report" do expect(report_table.length).to eq(1) end + context "with a VAT/GST-free supplier" do + before(:each) do + supplier.update(charges_sales_tax: false) + end - it "has a variant row" do - supplier = order.line_items.first.variant.product.supplier - supplier_name_field = report_table.first[0] - expect(supplier_name_field).to eq supplier.name + it "has a variant row when product belongs to a tax category" do + product_tax_category_name = order.line_items.first.variant.product.tax_category.name + + supplier_name_field = report_table.first[0] + supplier_vat_status_field = report_table.first[-2] + product_tax_category_field = report_table.first[-1] + + expect(supplier_name_field).to eq supplier.name + expect(supplier_vat_status_field).to eq "No" + expect(product_tax_category_field).to eq product_tax_category_name + 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) + supplier_name_field = report_table.first[0] + supplier_vat_status_field = report_table.first[-2] + product_tax_category_field = report_table.first[-1] + + expect(supplier_name_field).to eq supplier.name + expect(supplier_vat_status_field).to eq "No" + expect(product_tax_category_field).to eq "none" + end + end + context "with a VAT/GST-enabled supplier" do + before(:each) do + supplier.update(charges_sales_tax: true) + end + + it "has a variant row when product belongs to a tax category" do + product_tax_category_name = order.line_items.first.variant.product.tax_category.name + + supplier_name_field = report_table.first[0] + supplier_vat_status_field = report_table.first[-2] + product_tax_category_field = report_table.first[-1] + + expect(supplier_name_field).to eq supplier.name + expect(supplier_vat_status_field).to eq "Yes" + expect(product_tax_category_field).to eq product_tax_category_name + 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) + supplier_name_field = report_table.first[0] + supplier_vat_status_field = report_table.first[-2] + product_tax_category_field = report_table.first[-1] + + expect(supplier_name_field).to eq supplier.name + expect(supplier_vat_status_field).to eq "Yes" + expect(product_tax_category_field).to eq "none" + end end it "includes sku column" do variant_sku = order.line_items.first.variant.sku - last_column_title = table_headers.last - first_row_last_column_value = report_table.first.last + last_column_title = table_headers[-3] + first_row_last_column_value = report_table.first[-3] expect(last_column_title).to eq "SKU" expect(first_row_last_column_value).to eq variant_sku