Browse Source

Cldc 632 income and benefits section (#213)

* Update hb question options

* add has benefits field

* derive has_benefits

* update benefit question options

* Add nocharge field

* Add rent period question and check multiple condition sets for depends_on

* update rent period answer options

* Add carehome questions and move the remaining rent questions to income and benefits section

* Reset incfreq and incref and update rent routing based on periods
pull/217/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
57af5eef8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      README.md
  2. 13
      app/models/case_log.rb
  3. 26
      app/models/constants/case_log.rb
  4. 6
      app/models/form/page.rb
  5. 4
      app/models/form/subsection.rb
  6. 14
      app/models/validations/financial_validations.rb
  7. 761
      config/forms/2021_2022.json
  8. 7
      db/migrate/20220110115720_add_has_benefits_field.rb
  9. 7
      db/migrate/20220110161957_add_nocharge_field.rb
  10. 8
      db/migrate/20220111140400_add_care_home_charge_fields.rb
  11. 7
      db/migrate/20220112151048_add_household_charge_field.rb
  12. 7
      db/schema.rb
  13. 2
      docs/api/DLUHC-CORE-Data.v1.json
  14. 6
      spec/factories/case_log.rb
  15. 2
      spec/features/form/helpers.rb
  16. 10
      spec/fixtures/complete_case_log.json
  17. 22
      spec/fixtures/forms/2021_2022.json
  18. 14
      spec/fixtures/forms/2022_2023.json
  19. 2
      spec/fixtures/forms/test_validator.json
  20. 9
      spec/models/case_log_spec.rb
  21. 2
      spec/models/form/question_spec.rb
  22. 16
      spec/requests/form_controller_spec.rb

8
README.md

@ -141,7 +141,7 @@ The JSON should follow the structure:
}
}
},
"depends_on": { "question_key": "answer_value_required_for_this_page_to_be_shown" }
"depends_on": [{ "question_key": "answer_value_required_for_this_page_to_be_shown" }]
}
}
}
@ -171,9 +171,9 @@ Assumptions made by the format:
```jsonc
"page_1": { "questions": { "question_1: "answer_options": ["A", "B"] } },
"page_2": { "questions": { "question_2: "answer_options": ["C", "D"] }, "depends_on": { "question_1": "A" } },
"page_3": { "questions": { "question_3: "answer_options": ["E", "F"] }, "depends_on": { "question_1": "A" } },
"page_4": { "questions": { "question_4: "answer_options": ["G", "H"] }, "depends_on": { "question_1": "B" } },
"page_2": { "questions": { "question_2: "answer_options": ["C", "D"] }, "depends_on": [{ "question_1": "A" }] },
"page_3": { "questions": { "question_3: "answer_options": ["E", "F"] }, "depends_on": [{ "question_1": "A" }] },
"page_4": { "questions": { "question_4: "answer_options": ["G", "H"] }, "depends_on": [{ "question_1": "B" }] },
```
## JSON Form Validation against Schema

13
app/models/case_log.rb

@ -135,6 +135,9 @@ class CaseLog < ApplicationRecord
enum postcode_known: POLAR, _suffix: true
enum la_known: POLAR, _suffix: true
enum net_income_known: NET_INCOME_KNOWN, _suffix: true
enum household_charge: POLAR, _suffix: true
enum is_carehome: POLAR, _suffix: true
enum nocharge: POLAR, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing].freeze
@ -239,12 +242,16 @@ private
case net_income_known
when "Yes – the household has a weekly income"
self.incfreq = "Weekly"
self.incref = nil
when "Yes – the household has a monthly income"
self.incfreq = "Monthly"
self.incref = nil
when "Yes – the household has a yearly income"
self.incfreq = "Yearly"
self.incref = nil
when "Tenant prefers not to say"
self.incref = 1
self.incfreq = nil
end
self.hhmemb = other_hhmemb + 1 if other_hhmemb.present?
self.renttype = RENT_TYPE_MAPPING[rent_type]
@ -253,6 +260,8 @@ private
self.totelder = get_totelder
self.totadult = get_totadult
self.tcharge = brent.to_i + scharge.to_i + pscharge.to_i + supcharg.to_i
self.has_benefits = get_has_benefits
self.nocharge = household_charge == "Yes" ? "No" : "Yes"
end
def process_postcode_changes!
@ -303,6 +312,10 @@ private
end
end
def get_has_benefits
return "Yes" if HAS_BENEFITS_OPTIONS.include?(hb)
end
def all_fields_completed?
mandatory_fields.none? { |field| public_send(field).nil? if respond_to?(field) }
end

26
app/models/constants/case_log.rb

@ -206,15 +206,14 @@ module Constants::CaseLog
PERIOD = {
"Weekly for 52 weeks" => 1,
"Fortnightly" => 2,
"Four-weekly" => 3,
"Calendar monthly" => 4,
"Every 2 weeks" => 2,
"Every 4 weeks" => 3,
"Every calendar month" => 4,
"Weekly for 50 weeks" => 5,
"Weekly for 49 weeks" => 6,
"Weekly for 48 weeks" => 7,
"Weekly for 47 weeks" => 8,
"Weekly for 46 weeks" => 9,
"Weekly for 53 weeks" => 10,
}.freeze
LATIME = {
@ -229,13 +228,13 @@ module Constants::CaseLog
}.freeze
HOUSING_BENEFIT = {
"Housing Benefit, but not Universal Credit" => 1,
"Universal Credit with housing element, but not Housing Benefit" => 6,
"Universal Credit without housing element and no Housing Benefit" => 7,
"Universal Credit and Housing Benefit" => 8,
"Not Housing Benefit or Universal Credit" => 9,
"Dont know" => 3,
"Prefer not to say" => 100,
"Housing benefit" => 1,
"Universal Credit with housing element (excluding housing benefit)" => 6,
"Universal Credit (without housing element)" => 7,
"Housing benefit and Universal Credit (without housing element)" => 8,
"None" => 9,
"Don't know" => 3,
"Tenant prefers not to say" => 100,
}.freeze
REASON = {
@ -1077,4 +1076,9 @@ module Constants::CaseLog
"Yes – the household has a yearly income" => 2,
"Tenant prefers not to say" => 3,
}.freeze
HAS_BENEFITS_OPTIONS = ["Housing benefit",
"Universal Credit with housing element (excluding housing benefit)",
"Universal Credit (without housing element)",
"Housing benefit and Universal Credit (without housing element)"].freeze
end

6
app/models/form/page.rb

@ -32,8 +32,10 @@ private
def depends_on_met(case_log)
return true unless depends_on
depends_on.all? do |question, value|
!case_log[question].nil? && case_log[question] == value
depends_on.any? do |conditions_set|
conditions_set.all? do |question, value|
value.nil? ? case_log[question] == value : !case_log[question].nil? && case_log[question] == value
end
end
end
end

4
app/models/form/subsection.rb

@ -18,10 +18,12 @@ class Form::Subsection
def enabled?(case_log)
return true unless depends_on
depends_on.all? do |subsection_id, dependent_status|
depends_on.any? do |conditions_set|
conditions_set.all? do |subsection_id, dependent_status|
form.get_subsection(subsection_id).status(case_log) == dependent_status.to_sym
end
end
end
def status(case_log)
unless enabled?(case_log)

14
app/models/validations/financial_validations.rb

@ -38,15 +38,15 @@ module Validations::FinancialValidations
def validate_hbrentshortfall(record)
is_present = record.hbrentshortfall.present?
is_yes = record.hbrentshortfall == "Yes"
hb_donotknow = record.hb == "Dont know"
hb_no_hb_or_uc = record.hb == "Not Housing Benefit or Universal Credit"
hb_uc_no_hb = record.hb == "Universal Credit without housing element and no Housing Benefit"
hb_no_uc = record.hb == "Housing Benefit, but not Universal Credit"
hb_uc_no_he_hb = record.hb == "Universal Credit with housing element, but not Housing Benefit"
hb_and_uc = record.hb == "Universal Credit and Housing Benefit"
hb_donotknow = record.hb == "Don't know"
hb_none = record.hb == "None"
hb_uc_no_hb = record.hb == "Universal Credit (without housing element)"
hb_no_uc = record.hb == "Housing benefit"
hb_uc_no_he_hb = record.hb == "Universal Credit with housing element (excluding housing benefit)"
hb_and_uc = record.hb == "Housing benefit and Universal Credit (without housing element)"
conditions = [
{ condition: is_yes && (hb_donotknow || hb_no_hb_or_uc || hb_uc_no_hb), error: "Outstanding amount for basic rent and/or benefit eligible charges can not be 'Yes' if tenant is not in receipt of housing benefit or universal benefit or if benefit is unknown" },
{ condition: is_yes && (hb_donotknow || hb_none || hb_uc_no_hb), error: "Outstanding amount for basic rent and/or benefit eligible charges can not be 'Yes' if tenant is not in receipt of housing benefit or universal benefit or if benefit is unknown" },
{ condition: (hb_no_uc || hb_uc_no_he_hb || hb_and_uc) && !is_present, error: "Must be completed if Universal credit and/or Housing Benefit received" },
]

761
config/forms/2021_2022.json

File diff suppressed because it is too large Load Diff

7
db/migrate/20220110115720_add_has_benefits_field.rb

@ -0,0 +1,7 @@
class AddHasBenefitsField < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :has_benefits, :string
end
end
end

7
db/migrate/20220110161957_add_nocharge_field.rb

@ -0,0 +1,7 @@
class AddNochargeField < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :nocharge, :integer
end
end
end

8
db/migrate/20220111140400_add_care_home_charge_fields.rb

@ -0,0 +1,8 @@
class AddCareHomeChargeFields < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :is_carehome, :integer
t.column :chcharge, :decimal
end
end
end

7
db/migrate/20220112151048_add_household_charge_field.rb

@ -0,0 +1,7 @@
class AddHouseholdChargeField < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :household_charge, :integer
end
end
end

7
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_01_07_103143) do
ActiveRecord::Schema.define(version: 2022_01_12_151048) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -178,6 +178,11 @@ ActiveRecord::Schema.define(version: 2022_01_07_103143) do
t.integer "totelder"
t.integer "totadult"
t.integer "net_income_known"
t.string "has_benefits"
t.integer "nocharge"
t.integer "is_carehome"
t.decimal "chcharge"
t.integer "household_charge"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
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"

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

@ -323,7 +323,7 @@
"earnings": 1000,
"incfreq": "Monthly",
"benefits": "Some",
"hb": "Universal Credit with housing element, but not Housing Benefit",
"hb": "Universal Credit with housing element (excluding housing benefit)",
"period": "Weekly",
"brent": 200,
"scharge": 50,

6
spec/factories/case_log.rb

@ -72,7 +72,7 @@ FactoryBot.define do
wchair { "Yes" }
earnings { 68 }
benefits { "Some" }
period { "Fortnightly" }
period { "Every 2 weeks" }
brent { 200 }
scharge { 50 }
pscharge { 40 }
@ -148,6 +148,10 @@ FactoryBot.define do
armedforces { 1 }
builtype { 1 }
unitletas { 2 }
household_charge { "Yes" }
has_benefits { "Yes" }
is_carehome { "No" }
chcharge { 7 }
end
created_at { Time.zone.now }
updated_at { Time.zone.now }

2
spec/features/form/helpers.rb

@ -12,7 +12,7 @@ module Helpers
click_button("Save and continue")
choose("case-log-benefits-all-field")
click_button("Save and continue")
choose("case-log-hb-prefer-not-to-say-field")
choose("case-log-hb-tenant-prefers-not-to-say-field")
click_button("Save and continue")
end

10
spec/fixtures/complete_case_log.json vendored

@ -77,8 +77,8 @@
"net_income_known": "Yes – the household has a weekly income",
"earnings": 150,
"benefits": "Some",
"hb": "Universal Credit with housing element, but not Housing Benefit",
"period": "Fortnightly",
"hb": "Universal Credit with housing element (excluding housing benefit)",
"period": "Every 2 weeks",
"brent": 200,
"scharge": 50,
"pscharge": 40,
@ -144,6 +144,10 @@
"property_wheelchair_accessible": "Yes",
"void_or_renewal_date": "05/05/2020",
"tenant_same_property_renewal": "Yes",
"new_build_handover_date": "01/01/2019"
"new_build_handover_date": "01/01/2019",
"has_benefits": "Yes",
"household_charge": "Yes",
"is_carehome": "Yes",
"chcharge": "6"
}
}

22
spec/fixtures/forms/2021_2022.json vendored

@ -276,7 +276,7 @@
}
}
},
"depends_on": {"is_la_inferred": false}
"depends_on": [{"is_la_inferred": false}]
},
"property_wheelchair_accessible": {
"questions": {
@ -321,7 +321,7 @@
}
}
},
"depends_on": { "preg_occ": "Yes" }
"depends_on": [{ "preg_occ": "Yes" }, { "wchair" : "Yes" }]
},
"conditional_question_no_page": {
"questions": {
@ -335,7 +335,7 @@
}
}
},
"depends_on": { "preg_occ": "No" }
"depends_on": [{ "preg_occ": "No" }]
},
"conditional_question_no_second_page": {
"questions": {
@ -349,7 +349,7 @@
}
}
},
"depends_on": { "preg_occ": "No", "sex1": "Male" }
"depends_on": [{ "preg_occ": "No", "sex1": "Male" }]
}
}
}
@ -417,11 +417,11 @@
"header": "Is the tenant likely to be in receipt of any of these housing-related benefits?",
"type": "radio",
"answer_options": {
"0": "Housing Benefit, but not Universal Credit",
"1": "Prefer not to say"
"0": "Housing benefit",
"1": "Tenant prefers not to say"
},
"conditional_for": {
"conditional_question": ["Housing Benefit, but not Universal Credit"]
"conditional_question": ["Housing benefit"]
}
},
"conditional_question": {
@ -436,7 +436,7 @@
}
},
"dependent_page": {
"depends_on": { "incfreq": "Weekly" },
"depends_on": [{ "incfreq": "Weekly" }],
"questions": {
"dependent_question": {
"check_answer_label": "Dependent Question",
@ -462,7 +462,7 @@
"type": "radio",
"answer_options": {
"0": "Weekly for 52 weeks",
"1": "Fortnightly"
"1": "Every 2 weeks"
}
},
"brent": {
@ -642,7 +642,7 @@
"subsections": {
"declaration": {
"label": "Declaration",
"depends_on": {
"depends_on": [{
"household_characteristics": "completed",
"household_needs": "completed",
"tenancy_information": "completed",
@ -650,7 +650,7 @@
"income_and_benefits": "completed",
"rent": "completed",
"local_authority": "completed"
},
}],
"pages": {
"declaration": {
"questions": {

14
spec/fixtures/forms/2022_2023.json vendored

@ -29,7 +29,7 @@
"description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.",
"questions": {
},
"depends_on": { "gdpr_acceptance": "No" }
"depends_on": [{ "gdpr_acceptance": "No" }]
},
"sale_or_letting": {
"header": "",
@ -46,7 +46,7 @@
}
}
},
"depends_on": { "gdpr_acceptance": "Yes" }
"depends_on": [{ "gdpr_acceptance": "Yes" }]
},
"tenant_same_property_renewal": {
"header": "",
@ -63,7 +63,7 @@
}
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }
"depends_on": [{ "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }]
},
"startdate": {
"header": "",
@ -76,7 +76,7 @@
"type": "date"
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }
"depends_on": [{ "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }]
},
"about_this_letting": {
"header": "Tell us about this letting",
@ -115,7 +115,7 @@
}
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }
"depends_on": [{ "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }]
},
"sale_completion_date": {
"header": "",
@ -128,7 +128,7 @@
"type": "date"
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" }
"depends_on": [{ "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" }]
},
"purchaser_code": {
"header": "",
@ -142,7 +142,7 @@
"width": 10
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" }
"depends_on": [{ "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" }]
}
}
}

2
spec/fixtures/forms/test_validator.json vendored

@ -22,7 +22,7 @@
"type": "text"
}
},
"depends_on": {"test": "Yes"}
"depends_on": [{"test": "Yes"}]
},
"person_1_age": {
"header": "",

9
spec/models/case_log_spec.rb

@ -1038,6 +1038,8 @@ RSpec.describe Form, type: :model do
other_hhmemb: 6,
rent_type: "London living rent",
needstype: "General needs",
hb: "Housing benefit",
hbrentshortfall: "No",
})
end
@ -1218,5 +1220,12 @@ RSpec.describe Form, type: :model do
expect(record_from_db["totadult"]).to eq(3)
end
end
it "correctly derives and saves has_benefits" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select has_benefits from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["has_benefits"]).to eq("Yes")
end
end
end

2
spec/models/form/question_spec.rb

@ -145,7 +145,7 @@ RSpec.describe Form::Question, type: :model do
end
it "knows whether it is enabled or not for met conditions" do
case_log.hb = "Housing Benefit, but not Universal Credit"
case_log.hb = "Housing benefit"
expect(subject.enabled?(case_log)).to be true
end
end

16
spec/requests/form_controller_spec.rb

@ -269,6 +269,16 @@ RSpec.describe FormController, type: :request do
}
end
let(:case_log_form_conditional_question_wchair_yes_params) do
{
id: case_log.id,
case_log: {
page: "property_wheelchair_accessible",
wchair: "Yes",
},
}
end
it "routes to the appropriate conditional page based on the question answer of the current page" do
post "/logs/#{case_log.id}/form", params: case_log_form_conditional_question_yes_params
expect(response).to redirect_to("/logs/#{case_log.id}/conditional-question-yes-page")
@ -276,6 +286,12 @@ RSpec.describe FormController, type: :request do
post "/logs/#{case_log.id}/form", params: case_log_form_conditional_question_no_params
expect(response).to redirect_to("/logs/#{case_log.id}/conditional-question-no-page")
end
it "routes to the page if at least one of the condition sets is met" do
post "/logs/#{case_log.id}/form", params: case_log_form_conditional_question_wchair_yes_params
post "/logs/#{case_log.id}/form", params: case_log_form_conditional_question_no_params
expect(response).to redirect_to("/logs/#{case_log.id}/conditional-question-yes-page")
end
end
context "case logs that are not owned or managed by your organisation" do

Loading…
Cancel
Save