Fix various spec

This commit is contained in:
Gaetan Craig-Riou
2025-01-22 13:51:16 +11:00
parent 6b7373e4cf
commit cd7e92c6ca
4 changed files with 13 additions and 9 deletions

View File

@@ -16,8 +16,10 @@ module Addressing
end
def zone
zone = Spree::Zone.find_or_create_by!(name: ENV.fetch('CHECKOUT_ZONE'))
zone.members.create!(zoneable: country) unless zone.zoneables.include?(country)
zone = Spree::Zone.find_or_create_by(name: ENV.fetch('CHECKOUT_ZONE'))
zone.members << Spree::ZoneMember.create(zoneable: country) unless
zone.zoneables.include?(country)
zone.save!
zone
end

View File

@@ -26,9 +26,8 @@ RSpec.describe Spree::BaseHelper do
context "with a checkout zone defined" do
context "checkout zone is of type country" do
before do
@country_zone = create(:zone, name: "CountryZone")
@country_zone.members.create(zoneable: country)
allow(ENV).to receive(:fetch).and_return(@country_zone.name)
country_zone = create(:zone, name: "CountryZone", member: country)
allow(ENV).to receive(:fetch).and_return(country_zone.name)
end
it "return only the countries defined by the checkout zone" do

View File

@@ -61,9 +61,10 @@ RSpec.describe Invoice::DataPresenter do
expect(presenter.display_line_item_tax_rate(taxable_line_item)).to eq "15.0%, 20.0%"
end
context "one of the tax rate is appliable to a different tax zone" do
context "one of the tax rate is applicable to a different tax zone" do
before do
order.line_items.last.tax_category.tax_rates.last.update!(zone: create(:zone))
new_zone = create(:zone, default_tax: false, member: Spree::Country.last)
order.line_items.last.tax_category.tax_rates.last.update!(zone: new_zone)
order.create_tax_charge!
Orders::GenerateInvoiceService.new(order).generate_or_update_latest_invoice
end

View File

@@ -6,8 +6,10 @@ RSpec.describe "Tax Rates" do
include AuthenticationHelper
let!(:calculator) { create(:calculator_per_item, calculable: create(:order)) }
let!(:tax_rate) { create(:tax_rate, name: "IVA", calculator:) }
let!(:zone) { create(:zone, name: "Ilhas") }
let!(:tax_rate) {
create(:tax_rate, name: "IVA", calculator:, zone: create(:zone, default_tax: false))
}
let!(:zone) { create(:zone, name: "Ilhas", default_tax: false) }
let!(:tax_category) { create(:tax_category, name: "Full") }
before do