Browse Source

CLDC-2388 Map purchase prices errors to type (#1673)

pull/1688/head v.0.3.26
Jack 2 years ago committed by GitHub
parent
commit
38df2a5559
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      app/services/bulk_upload/sales/year2022/row_parser.rb
  2. 24
      spec/services/bulk_upload/sales/year2022/row_parser_spec.rb

34
app/services/bulk_upload/sales/year2022/row_parser.rb

@ -324,6 +324,27 @@ class BulkUpload::Sales::Year2022::RowParser
if: proc { field_84 == 12 }, if: proc { field_84 == 12 },
on: :after_log on: :after_log
validates :field_68,
presence: {
message: I18n.t("validations.not_answered", question: "What was the full purchase price?"),
},
if: :shared_ownership?,
on: :after_log
validates :field_77,
presence: {
message: I18n.t("validations.not_answered", question: "What was the full purchase price?"),
},
if: :discounted_ownership?,
on: :after_log
validates :field_87,
presence: {
message: I18n.t("validations.not_answered", question: "What was the full purchase price?"),
},
if: :outright_sale?,
on: :after_log
validates :field_109, presence: { message: I18n.t("validations.not_answered", question: "more than 2 buyers"), category: :setup }, if: :joint_purchase?, on: :after_log validates :field_109, presence: { message: I18n.t("validations.not_answered", question: "more than 2 buyers"), category: :setup }, if: :joint_purchase?, on: :after_log
validates :field_113, presence: { message: I18n.t("validations.not_answered", question: "ownership type"), category: :setup }, on: :after_log validates :field_113, presence: { message: I18n.t("validations.not_answered", question: "ownership type"), category: :setup }, on: :after_log
@ -538,7 +559,6 @@ private
lanomagr: %i[field_65], lanomagr: %i[field_65],
frombeds: %i[field_66], frombeds: %i[field_66],
fromprop: %i[field_67], fromprop: %i[field_67],
value: %i[field_68 field_77 field_87],
equity: %i[field_69], equity: %i[field_69],
mortgage: %i[field_70 field_80 field_88], mortgage: %i[field_70 field_80 field_88],
extrabor: %i[field_71 field_81 field_89], extrabor: %i[field_71 field_81 field_89],
@ -1034,15 +1054,11 @@ private
next if log.optional_fields.include?(question.id) next if log.optional_fields.include?(question.id)
next if question.completed?(log) next if question.completed?(log)
if setup_question?(question) fields.each do |field|
fields.each do |field| unless errors.any? { |e| fields.include?(e.attribute) }
unless errors.any? { |e| fields.include?(e.attribute) } if setup_question?(question)
errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase), category: :setup) errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase), category: :setup)
end else
end
else
fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase)) errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase))
end end
end end

24
spec/services/bulk_upload/sales/year2022/row_parser_spec.rb

@ -419,6 +419,30 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
end end
end end
context "when type is shared ownership" do
let(:attributes) { valid_attributes.merge({ field_113: 1, field_68: nil }) }
it "has error on correct fields" do
expect(parser.errors).to include(:field_68)
end
end
context "when type is discounted ownership" do
let(:attributes) { valid_attributes.merge({ field_113: 2, field_77: nil }) }
it "has error on correct fields" do
expect(parser.errors).to include(:field_77)
end
end
context "when type is outright sale" do
let(:attributes) { valid_attributes.merge({ field_113: 3, field_87: nil }) }
it "has error on correct fields" do
expect(parser.errors).to include(:field_87)
end
end
describe "#field_93" do # username for created_by describe "#field_93" do # username for created_by
context "when blank" do context "when blank" do
let(:attributes) { { bulk_upload:, field_93: "" } } let(:attributes) { { bulk_upload:, field_93: "" } }

Loading…
Cancel
Save