1
0

Fix bug where shipments by LP provider with wrong size received discounts

This commit is contained in:
Tim Kächele 2021-11-22 19:54:59 +01:00
parent a9dc75a695
commit 91e271186e
2 changed files with 25 additions and 1 deletions

View File

@ -6,6 +6,7 @@ module PlanetExpress
def applicable_to?(shipment)
lp_provider_shipment?(shipment) &&
l_shipment?(shipment) &&
third_l_shipment_in_month?(shipment) &&
rule_not_applied_in_month_already?(shipment)
end
@ -16,6 +17,10 @@ module PlanetExpress
private
def l_shipment?(shipment)
shipment.l_shipment?
end
def lp_provider_shipment?(shipment)
shipment.lp_provider?
end
@ -26,7 +31,7 @@ module PlanetExpress
count = shipment_repository.l_shipment_count_for_provider_and_month(provider,
month)
(count % 3) == 2
count == 2
end
def rule_not_applied_in_month_already?(shipment)

View File

@ -73,6 +73,25 @@ RSpec.describe PlanetExpress::LShipmentDiscountRule do
end.to_not(change { shipment.discounts })
end
end
context 'non L shipment' do
before(:each) do
shipment_repo.add(applicable_shipment)
shipment_repo.add(applicable_shipment)
end
let(:shipping_option) do
shipping_option_repo.find_by_provider_and_package_size('LP', 'M')
end
let(:shipment) do
PlanetExpress::Shipment.new(Date.today, shipping_option)
end
it 'does not update the discounts' do
expect do
subject.apply_to(shipment)
end.to_not(change { shipment.discounts })
end
end
end
end
end