Browse Source

Merge branch 'main' into CLDC-510-income-ranges

pull/58/head
baarkerlounger 4 years ago
parent
commit
6d512292e1
  1. 19
      app/models/case_log.rb
  2. 21
      docs/api/DLUHC-CORE-Data.v1.json
  3. 6
      spec/helpers/check_answers_helper_spec.rb
  4. 42
      spec/models/case_log_spec.rb

19
app/models/case_log.rb

@ -67,6 +67,15 @@ class CaseLogValidator < ActiveModel::Validator
end
end
def validate_outstanding_rent_amount(record)
if record.outstanding_rent_or_charges == "Yes" && record.outstanding_amount.blank?
record.errors.add :outstanding_amount, "You must answer the oustanding amout question if you have outstanding rent or charges."
end
if record.outstanding_rent_or_charges == "No" && record.outstanding_amount.present?
record.errors.add :outstanding_amount, "You must not answer the oustanding amout question if you don't have outstanding rent or charges."
end
end
EMPLOYED_STATUSES = ["Full-time - 30 hours or more", "Part-time - Less than 30 hours"].freeze
def validate_net_income_uc_proportion(record)
(1..8).any? do |n|
@ -80,6 +89,16 @@ class CaseLogValidator < ActiveModel::Validator
end
end
def validate_armed_forces_active_response(record)
if record.armed_forces == "Yes - a regular" && record.armed_forces_active.blank?
record.errors.add :armed_forces_active, "You must answer the armed forces active question if the tenant has served as a regular in the armed forces"
end
if record.armed_forces != "Yes - a regular" && record.armed_forces_active.present?
record.errors.add :armed_forces_active, "You must not answer the armed forces active question if the tenant has not served as a regular in the armed forces"
end
end
def validate_household_pregnancy(record)
if (record.pregnancy == "Yes" || record.pregnancy == "Prefer not to say") && !women_of_child_bearing_age_in_household(record)
record.errors.add :pregnancy, "You must answer no as there are no female tenants aged 16-50 in the property"

21
docs/api/DLUHC-CORE-Data.v1.json

@ -109,7 +109,7 @@
"Invalid Age": {
"value": {
"errors": {
"tenant_age": [
"person_1_age": [
"Tenant age must be between 0 and 120"
]
}
@ -219,7 +219,7 @@
"reasonable_preference_reason": [
"If reasonable preference is Yes, a reason must be given"
],
"tenant_age": [
"person_1_age": [
"Tenant age must be between 0 and 120"
]
}
@ -268,8 +268,8 @@
"x-examples": {
"example-1": {
"tenant_code": "T657",
"tenant_age": 35,
"tenant_gender": "Female",
"person_1_age": 35,
"person_1_gender": "Female",
"tenant_ethnic_group": "White: English/Scottish/Welsh/Northern Irish/British",
"tenant_nationality": "UK national resident in UK",
"previous_housing_situation": "Private sector tenancy",
@ -1207,6 +1207,17 @@
]
}
},
"securitySchemes": {}
"securitySchemes": {
"API Key - 1": {
"name": "API Key",
"type": "apiKey",
"in": "query"
},
"API Key - 2": {
"name": "API Key",
"type": "apiKey",
"in": "query"
}
}
}
}

6
spec/helpers/check_answers_helper_spec.rb

@ -11,7 +11,9 @@ RSpec.describe CheckAnswersHelper do
)
end
let(:case_log_with_met_radio_condition) do
FactoryBot.create(:case_log, armed_forces: "Yes - a regular", armed_forces_injured: "No")
FactoryBot.create(:case_log, armed_forces: "Yes - a regular",
armed_forces_injured: "No",
armed_forces_active: "Yes")
end
let(:subsection) { "income_and_benefits" }
let(:subsection_with_numeric_conditionals) { "household_characteristics" }
@ -56,7 +58,7 @@ RSpec.describe CheckAnswersHelper do
subsection_with_radio_conditionals,
case_log_with_met_radio_condition,
form,
)).to equal(3)
)).to equal(4)
end
end

42
spec/models/case_log_spec.rb

@ -121,6 +121,22 @@ RSpec.describe Form, type: :model do
end
end
context "outstanding rent or charges validation" do
it "must be anwered if answered yes to outstanding rent or charges" do
expect {
CaseLog.create!(outstanding_rent_or_charges: "Yes",
outstanding_amount: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must be not be anwered if answered no to outstanding rent or charges" do
expect {
CaseLog.create!(outstanding_rent_or_charges: "No",
outstanding_amount: 99)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "tenant’s income is from Universal Credit, state pensions or benefits" do
it "Cannot be All if person 1 works full time" do
expect {
@ -140,6 +156,7 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "fixed term tenancy length" do
it "Must not be completed if Type of main tenancy is not responded with either Secure or Assured shorthold " do
expect {
@ -187,6 +204,31 @@ RSpec.describe Form, type: :model do
}.not_to raise_error
end
end
context "armed forces active validation" do
it "must be answered if ever served in the forces as a regular" do
expect {
CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_active: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must not be answered if not ever served as a regular" do
expect {
CaseLog.create!(armed_forces: "No",
armed_forces_active: "Yes")
}.to raise_error(ActiveRecord::RecordInvalid)
end
# Crossover over tests here as injured must be answered as well for no error
it "must be answered if ever served in the forces as a regular" do
expect {
CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_active: "Yes",
armed_forces_injured: "Yes")
}.not_to raise_error
end
end
end
describe "status" do

Loading…
Cancel
Save