Browse Source

CLDC-3318: Add maximum percentage discount validation for bulk uploads (#2316)

* CLDC-3318: Add maximum percentage discount validation for bulk uploads

* CLDC-2213: Review markups
CLDC-3339-update-selcet-correct-address-error
Robert Sullivan 9 months ago committed by GitHub
parent
commit
e2ed41c03a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/services/bulk_upload/sales/year2024/row_parser.rb
  2. 26
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

9
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],

26
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" }) }

Loading…
Cancel
Save