Browse Source

Make deposit dynamically optional, update BU

pull/2210/head
Kat 2 years ago
parent
commit
08107bc0dc
  1. 1
      app/models/sales_log.rb
  2. 8
      app/services/bulk_upload/sales/year2024/row_parser.rb
  3. 30
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

1
app/models/sales_log.rb

@ -121,6 +121,7 @@ class SalesLog < Log
not_required << "proplen" if proplen_optional?
not_required << "mortlen" if mortlen_optional?
not_required << "frombeds" if frombeds_optional?
not_required << "deposit" if form.start_year_after_2024? && stairowned_100?
not_required |= %w[address_line2 county postcode_full] if saledate && collection_start_year_for_date(saledate) >= 2023

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

@ -341,6 +341,14 @@ class BulkUpload::Sales::Year2024::RowParser
},
on: :before_log
validates :field_103,
inclusion: {
in: [1, 2],
if: proc { field_88 != 100 },
question: QUESTIONS[:field_103],
},
on: :before_log
validates :field_9,
presence: {
message: I18n.t("validations.not_answered", question: "type of shared ownership sale"),

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

@ -975,6 +975,36 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end
end
describe "#field_103" do # shared ownership mortgageused
context "when invalid value" do
let(:attributes) { setup_section_params.merge(field_103: "4") }
it "returns correct errors" do
expect(parser.errors[:field_103]).to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership")
end
end
context "when value is 3 and stairowned is not 100" do
let(:attributes) { setup_section_params.merge(field_103: "3", field_86: "1", field_87: "50", field_88: "99", field_109: nil) }
it "returns correct errors" do
expect(parser.errors[:field_103]).to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership")
end
end
context "when value is 3 and stairowned is 100" do
let(:attributes) { setup_section_params.merge(field_103: "3", field_86: "1", field_87: "50", field_88: "100", field_109: nil) }
it "does not add errors and sets mortgage used to 3" do
expect(parser.log.mortgageused).to be(3)
expect(parser.log.stairowned).to be(100)
expect(parser.log.deposit).to be(nil)
expect(parser.errors[:field_103]).to be_empty
expect(parser.errors[:field_109]).to be_empty
end
end
end
describe "soft validations" do
context "when soft validation is triggered" do
let(:attributes) { valid_attributes.merge({ field_31: 22, field_35: 5 }) }

Loading…
Cancel
Save