Browse Source

fix postcode field

pull/2222/head
Kat 2 years ago
parent
commit
b78e571b70
  1. 4
      app/models/validations/sales/sale_information_validations.rb
  2. 10
      spec/models/validations/sales/sale_information_validations_spec.rb

4
app/models/validations/sales/sale_information_validations.rb

@ -89,11 +89,11 @@ module Validations::Sales::SaleInformationValidations
return unless record.discount && record.value && record.la
if record.london_property? && record.discount_value > 136_400
%i[discount value la postcode uprn].each do |field|
%i[discount value la postcode_full uprn].each do |field|
record.errors.add field, I18n.t("validations.sale_information.value.over_discounted_london_max", discount_value: record.field_formatted_as_currency("discount_value"))
end
elsif record.property_not_in_london? && record.discount_value > 102_400
%i[discount value la postcode uprn].each do |field|
%i[discount value la postcode_full uprn].each do |field|
record.errors.add field, I18n.t("validations.sale_information.value.over_discounted_max", discount_value: record.field_formatted_as_currency("discount_value"))
end
end

10
spec/models/validations/sales/sale_information_validations_spec.rb

@ -632,7 +632,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
expect(record.errors["discount"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
expect(record.errors["la"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
expect(record.errors["postcode"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
expect(record.errors["postcode_full"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
expect(record.errors["uprn"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
end
@ -641,7 +641,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to be_empty
expect(record.errors["discount"]).to be_empty
expect(record.errors["la"]).to be_empty
expect(record.errors["postcode"]).to be_empty
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["uprn"]).to be_empty
end
end
@ -657,7 +657,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
expect(record.errors["discount"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
expect(record.errors["la"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
expect(record.errors["postcode"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
expect(record.errors["postcode_full"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
expect(record.errors["uprn"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
end
@ -666,7 +666,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to be_empty
expect(record.errors["discount"]).to be_empty
expect(record.errors["la"]).to be_empty
expect(record.errors["postcode"]).to be_empty
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["uprn"]).to be_empty
end
end
@ -680,7 +680,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to be_empty
expect(record.errors["discount"]).to be_empty
expect(record.errors["la"]).to be_empty
expect(record.errors["postcode"]).to be_empty
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["uprn"]).to be_empty
end
end

Loading…
Cancel
Save