Adds coverage on supplier option to charge tax
This commit is contained in:
Maikel
2025-02-14 12:43:15 +11:00
committed by GitHub

View File

@@ -51,15 +51,17 @@ RSpec.describe "Pay Your Suppliers Report" do
context "with taxes and fees" do
let(:line_item) { order.line_items.first }
let(:tax_rate) {
create(
:tax_rate,
included_in_price: false,
zone: create(:zone_with_member)
)
}
let(:tax_category) {
create(
:tax_category,
tax_rates: [
create(
:tax_rate,
zone: create(:zone_with_member)
)
]
tax_rates: [tax_rate]
)
}
let!(:enterprise_fee) do
@@ -75,7 +77,6 @@ RSpec.describe "Pay Your Suppliers Report" do
before do
# Prepare order or line_item to have respective tax adjustments
hub.update!(charges_sales_tax: true)
supplier.update!(charges_sales_tax: true)
line_item.variant.update!(tax_category:)
line_item.copy_tax_category
@@ -92,18 +93,91 @@ RSpec.describe "Pay Your Suppliers Report" do
order.create_tax_charge!
end
it "Generates the report" do
expect(report_table_rows.length).to eq(1)
table_row = report_table_rows.first
context "supplier charges tax" do
before do
supplier.update!(charges_sales_tax: true)
end
expect(table_row.producer_charges_gst).to eq('Yes')
expect(table_row.total_excl_fees_and_tax.to_f).to eq(10.0)
expect(table_row.total_excl_vat.to_f).to eq(10.1)
expect(table_row.total_fees_excl_tax.to_f).to eq(0.1)
expect(table_row.total_tax_on_fees.to_f).to eq(0.01)
expect(table_row.total_tax_on_product.to_f).to eq(1.0)
expect(table_row.total_tax.to_f).to eq(1.01)
expect(table_row.total.to_f).to eq(11.11)
context "added tax" do
it "Generates the report" do
expect(report_table_rows.length).to eq(1)
table_row = report_table_rows.first
expect(table_row.producer_charges_gst).to eq('Yes')
expect(table_row.total_excl_fees_and_tax.to_f).to eq(10.0)
expect(table_row.total_excl_vat.to_f).to eq(10.1)
expect(table_row.total_fees_excl_tax.to_f).to eq(0.1)
expect(table_row.total_tax_on_fees.to_f).to eq(0.01)
expect(table_row.total_tax_on_product.to_f).to eq(1.0)
expect(table_row.total_tax.to_f).to eq(1.01)
expect(table_row.total.to_f).to eq(11.11)
end
end
context "included tax" do
before do
tax_rate.update(included_in_price: true)
order.create_tax_charge!
end
it "Generates the report" do
expect(report_table_rows.length).to eq(1)
table_row = report_table_rows.first
expect(table_row.producer_charges_gst).to eq('Yes')
expect(table_row.total_excl_fees_and_tax.to_f).to eq(9.09)
expect(table_row.total_excl_vat.to_f).to eq(9.18)
expect(table_row.total_fees_excl_tax.to_f).to eq(0.09)
expect(table_row.total_tax_on_fees.to_f).to eq(0.01)
expect(table_row.total_tax_on_product.to_f).to eq(0.91)
expect(table_row.total_tax.to_f).to eq(0.92)
expect(table_row.total.to_f).to eq(10.10)
end
end
end
context "supplier does not charge tax" do
before do
supplier.update!(charges_sales_tax: false)
end
it "Generates the report, without displaying taxes" do
expect(report_table_rows.length).to eq(1)
table_row = report_table_rows.first
expect(table_row.producer_charges_gst).to eq('No')
expect(table_row.total_excl_fees_and_tax.to_f).to eq(10.0)
expect(table_row.total_excl_vat.to_f).to eq(10.1)
expect(table_row.total_fees_excl_tax.to_f).to eq(0.1)
expect(table_row.total_tax_on_fees.to_f).to eq(0.00)
expect(table_row.total_tax_on_product.to_f).to eq(0.0)
expect(table_row.total_tax.to_f).to eq(0.00)
expect(table_row.total.to_f).to eq(10.1)
end
end
context "fee is owned by the hub" do
before do
enterprise_fee.update(enterprise: hub)
order.create_tax_charge!
end
it "Generates the report, without displaying enterprise fees" do
# enterprise fee exists on the order
fee = Spree::Adjustment.where(originator_type: "EnterpriseFee")[0]
expect(fee.amount.to_f).to eq(0.1)
# but is not displayed on the report
expect(report_table_rows.length).to eq(1)
table_row = report_table_rows.first
expect(table_row.producer_charges_gst).to eq('No')
expect(table_row.total_excl_fees_and_tax.to_f).to eq(10.0)
expect(table_row.total_excl_vat.to_f).to eq(10.0)
expect(table_row.total_fees_excl_tax.to_f).to eq(0.0)
expect(table_row.total_tax_on_fees.to_f).to eq(0.00)
expect(table_row.total_tax_on_product.to_f).to eq(0.0)
expect(table_row.total_tax.to_f).to eq(0.00)
expect(table_row.total.to_f).to eq(10.0)
end
end
end
end