Browse Source

Add soft validation and interruption screen for basic rent

pull/434/head
Kat 3 years ago
parent
commit
dc4719ff11
  1. 14
      app/models/validations/soft_validations.rb
  2. 48
      config/forms/2021_2022.json
  3. 3
      config/locales/en.yml
  4. 5
      db/migrate/20220328133331_add_rent_value_check.rb
  5. 1
      db/schema.rb
  6. 1
      spec/fixtures/exports/case_logs.xml
  7. 73
      spec/models/validations/soft_validations_spec.rb

14
app/models/validations/soft_validations.rb

@ -24,4 +24,18 @@ module Validations::SoftValidations
weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min) weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min)
end end
def rent_in_soft_min_range?
return unless brent && weekly_value(brent) && startdate
rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:)
rent_range.present? && weekly_value(brent).between?(rent_range.hard_min, rent_range.soft_min)
end
def rent_in_soft_max_range?
return unless brent && weekly_value(brent) && startdate
rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:)
rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max)
end
end end

48
config/forms/2021_2022.json

@ -5568,6 +5568,54 @@
} }
] ]
}, },
"check_min_rent_amount": {
"depends_on": [{ "rent_in_soft_min_range?": true }],
"title_text": "Rent value is under the expected range",
"informative_text": {
"translation": "soft_validations.rent.min_max.hint_text",
"argument": ["brent"]
},
"questions": {
"rent_value_check": {
"check_answer_label": "Rent soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"check_max_rent_amount": {
"depends_on": [{ "rent_in_soft_max_range?": true }],
"title_text": "Rent value is over the expected range",
"informative_text": {
"translation": "soft_validations.rent.min_max.hint_text",
"argument": ["brent"]
},
"questions": {
"rent_value_check": {
"check_answer_label": "Rent soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"outstanding": { "outstanding": {
"header": "", "header": "",
"description": "", "description": "",

3
config/locales/en.yml

@ -224,6 +224,9 @@ en:
message: "Net income is lower than expected based on the main tenant’s working situation. Are you sure this is correct?" message: "Net income is lower than expected based on the main tenant’s working situation. Are you sure this is correct?"
in_soft_max_range: in_soft_max_range:
message: "Net income is higher than expected based on the main tenant’s working situation. Are you sure this is correct?" message: "Net income is higher than expected based on the main tenant’s working situation. Are you sure this is correct?"
rent:
min_max:
hint_text: "You have entered %{brent}"
devise: devise:
two_factor_authentication: two_factor_authentication:
success: "Two factor authentication successful." success: "Two factor authentication successful."

5
db/migrate/20220328133331_add_rent_value_check.rb

@ -0,0 +1,5 @@
class AddRentValueCheck < ActiveRecord::Migration[7.0]
def change
add_column :case_logs, :rent_value_check, :boolean
end
end

1
db/schema.rb

@ -231,6 +231,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.string "relat6" t.string "relat6"
t.string "relat7" t.string "relat7"
t.string "relat8" t.string "relat8"
t.boolean "rent_value_check"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
end end

1
spec/fixtures/exports/case_logs.xml vendored

@ -173,5 +173,6 @@
<relat6/> <relat6/>
<relat7/> <relat7/>
<relat8/> <relat8/>
<rent_value_check/>
</form> </form>
</forms> </forms>

73
spec/models/validations/soft_validations_spec.rb

@ -0,0 +1,73 @@
require "rails_helper"
RSpec.describe Validations::SoftValidations do
let(:record) { FactoryBot.create(:case_log) }
describe "rent min max validations" do
before do
LaRentRange.create!(
ranges_rent_id: "1",
la: "E07000223",
beds: 1,
lettype: 1,
soft_min: 12.41,
soft_max: 89.54,
hard_min: 9.87,
hard_max: 100.99,
start_year: 2021,
)
record.la = "E07000223"
record.lettype = 1
record.beds = 1
record.period = 1
record.startdate = Time.zone.local(2021, 10, 10)
end
context "when validating soft min" do
before do
record.brent = 11
end
it "returns out of soft min range if no startdate is given" do
record.startdate = nil
expect(record)
.not_to be_rent_in_soft_min_range
end
it "returns out of soft min range if no brent is given" do
record.brent = nil
expect(record)
.not_to be_rent_in_soft_min_range
end
it "returns true if weekly rent is in soft min range" do
expect(record)
.to be_rent_in_soft_min_range
end
end
context "when validating soft max" do
before do
record.brent = 90
end
it "returns out of soft max range if no startdate is given" do
record.startdate = nil
expect(record)
.not_to be_rent_in_soft_max_range
end
it "returns out of soft max range if no brent is given" do
record.brent = nil
expect(record)
.not_to be_rent_in_soft_max_range
end
it "returns true if weekly rent is in soft max range" do
expect(record)
.to be_rent_in_soft_max_range
end
end
end
end
Loading…
Cancel
Save