Browse Source

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

pull/2316/head
Robert Sullivan 2 years ago
parent
commit
b118471d41
  1. 9
      app/services/bulk_upload/sales/year2024/row_parser.rb
  2. 1
      config/locales/en.yml
  3. 18
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

9
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -374,6 +374,15 @@ class BulkUpload::Sales::Year2024::RowParser
}, },
on: :after_log 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, validates :field_11,
inclusion: { inclusion: {
in: [10, 12], in: [10, 12],

1
config/locales/en.yml

@ -211,6 +211,7 @@ en:
already_added: "You have already added this managing agent" already_added: "You have already added this managing agent"
merged: "That organisation has already been merged. Select a different organisation." merged: "That organisation has already been merged. Select a different organisation."
not_answered: "You must answer %{question}" not_answered: "You must answer %{question}"
range: "%{question} should be between %{min} and %{max}"
invalid_option: "Enter a valid value for %{question}" invalid_option: "Enter a valid value for %{question}"
invalid_number: "Enter a number 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." no_address_found: "We could not find this address. Edit the address data or fix this error on the CORE site."

18
spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

@ -725,6 +725,24 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end end
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 describe "#field_11" do # type for outright sale
context "when an invalid option" do context "when an invalid option" do
let(:attributes) { setup_section_params.merge({ field_11: "100" }) } let(:attributes) { setup_section_params.merge({ field_11: "100" }) }

Loading…
Cancel
Save