diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index 928060dfa..488dea386 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -366,6 +366,15 @@ class BulkUpload::Sales::Year2024::RowParser }, on: :after_log + validates :field_116, + numericality: { + message: I18n.t("validations.numeric.within_range", field: "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/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index ea0ea386e..c1014ecc3 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,32 @@ 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 must 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 + + context "when percentage less than 0" do + let(:attributes) { valid_attributes.merge({ field_8: "2", field_116: "-1" }) } + + it "returns correct error" do + expect(parser.errors.where(:field_116).map(&:message)).to include("Percentage discount must be between 0% and 70%") + 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" }) }