diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index 7a1481300..53a88a638 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -374,6 +374,15 @@ class BulkUpload::Sales::Year2024::RowParser }, on: :after_log + validates :field_116, + numericality: { + message: I18n.t("validations.range", question: "Percentage discount", min: "0%", max: "70%"), + greater_than_or_equal_to: 0, + less_than_or_equal_to: 70, + if: :discounted_ownership?, + }, + on: :before_log + validates :field_11, inclusion: { in: [10, 12], diff --git a/config/locales/en.yml b/config/locales/en.yml index 8612e0367..fdd34ccff 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -211,6 +211,7 @@ en: already_added: "You have already added this managing agent" merged: "That organisation has already been merged. Select a different organisation." not_answered: "You must answer %{question}" + range: "%{question} should be between %{min} and %{max}" invalid_option: "Enter a valid value for %{question}" invalid_number: "Enter a number for %{question}" no_address_found: "We could not find this address. Edit the address data or fix this error on the CORE site." diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index ce81300b5..f75c62463 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -725,6 +725,24 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end + describe "#field_116" do # percentage discount + context "when percentage discount over 70" do + let(:attributes) { valid_attributes.merge({ field_8: "2", field_116: "71" }) } + + it "returns correct error" do + expect(parser.errors.where(:field_116).map(&:message)).to include("Percentage discount should be between 0% and 70%") + end + end + + context "when percentage discount not over 70" do + let(:attributes) { valid_attributes.merge({ field_8: "2", field_116: "70" }) } + + it "does not return error" do + expect(parser.errors.where(:field_116)).not_to be_present + end + end + end + describe "#field_11" do # type for outright sale context "when an invalid option" do let(:attributes) { setup_section_params.merge({ field_11: "100" }) }