Browse Source

Cldc 629 household situation renewal (#308)

* Add routing for renewals

* Fix inferring postcode (it works 🤷‍♀️)

* Infer remaining renewal variables

* update check answer labels

* Route to the next page if the first one is not routed to from tasklist

* Fix allocation unknown type and depends on for referrals

* add a test for and rename first_page_or_check_answers'
pull/309/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
2bc2df84fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/helpers/tasklist_helper.rb
  2. 10
      app/models/case_log.rb
  3. 4
      app/models/form.rb
  4. 82
      config/forms/2021_2022.json
  5. 2
      db/migrate/20220210132254_remove_checkbox_parent_fields.rb
  6. 15
      db/migrate/20220216094400_change_unknown_letting_allocation_type.rb
  7. 2
      db/schema.rb
  8. 2
      spec/features/form/accessible_autocomplete_spec.rb
  9. 2
      spec/features/form/check_answers_page_spec.rb
  10. 15
      spec/fixtures/forms/2021_2022.json
  11. 11
      spec/helpers/tasklist_helper_spec.rb
  12. 23
      spec/models/case_log_spec.rb
  13. 2
      spec/models/form/subsection_spec.rb
  14. 2
      spec/requests/case_logs_controller_spec.rb

7
app/helpers/tasklist_helper.rb

@ -25,18 +25,19 @@ module TasklistHelper
case_log.form.subsections.count { |subsection| subsection.status(case_log) == status } case_log.form.subsections.count { |subsection| subsection.status(case_log) == status }
end end
def first_page_or_check_answers(subsection, case_log) def next_page_or_check_answers(subsection, case_log)
path = if subsection.is_started?(case_log) path = if subsection.is_started?(case_log)
"case_log_#{subsection.id}_check_answers_path" "case_log_#{subsection.id}_check_answers_path"
else else
"case_log_#{subsection.pages.first.id}_path" next_page = subsection.pages.first.routed_to?(case_log) ? subsection.pages.first.id : case_log.form.next_page(subsection.pages.first, case_log)
"case_log_#{next_page}_path"
end end
send(path, case_log) send(path, case_log)
end end
def subsection_link(subsection, case_log) def subsection_link(subsection, case_log)
if subsection.status(case_log) != :cannot_start_yet if subsection.status(case_log) != :cannot_start_yet
next_page_path = first_page_or_check_answers(subsection, case_log).to_s next_page_path = next_page_or_check_answers(subsection, case_log).to_s
govuk_link_to(subsection.label, next_page_path.dasherize, aria: { describedby: subsection.id.dasherize }) govuk_link_to(subsection.label, next_page_path.dasherize, aria: { describedby: subsection.id.dasherize })
else else
subsection.label subsection.label

10
app/models/case_log.rb

@ -100,6 +100,7 @@ class CaseLog < ApplicationRecord
enum cbl: POLAR, _suffix: true enum cbl: POLAR, _suffix: true
enum chr: POLAR, _suffix: true enum chr: POLAR, _suffix: true
enum cap: POLAR, _suffix: true enum cap: POLAR, _suffix: true
enum letting_allocation_unknown: POLAR, _suffix: true
enum wchair: POLAR2, _suffix: true enum wchair: POLAR2, _suffix: true
enum incfreq: INCFREQ, _suffix: true enum incfreq: INCFREQ, _suffix: true
enum benefits: BENEFITS, _suffix: true enum benefits: BENEFITS, _suffix: true
@ -256,7 +257,14 @@ private
self.nocharge = household_charge == "Yes" ? "No" : "Yes" self.nocharge = household_charge == "Yes" ? "No" : "Yes"
self.layear = "Less than 1 year" if renewal == "Yes" self.layear = "Less than 1 year" if renewal == "Yes"
self.underoccupation_benefitcap = "No" if renewal == "Yes" && year == 2021 self.underoccupation_benefitcap = "No" if renewal == "Yes" && year == 2021
self.homeless = "No" if renewal == "Yes" if renewal == "Yes"
self.homeless = "No"
self.referral = "Internal transfer"
end
if needstype == "General needs"
self.prevten = "Fixed-term private registered provider (PRP) general needs tenancy" if managing_organisation.provider_type == "PRP"
self.prevten = "Fixed-term local authority general needs tenancy" if managing_organisation.provider_type == "LA"
end
end end
def process_postcode_changes! def process_postcode_changes!

4
app/models/form.rb

@ -114,9 +114,11 @@ class Form
end end
def invalidated_page_questions(case_log) def invalidated_page_questions(case_log)
# we're already treating address fields as a special case and reset their values upon saving a case_log
address_questions = %w[postcode_known la previous_postcode_known prevloc property_postcode previous_postcode]
pages_that_are_routed_to = pages.select { |p| p.routed_to?(case_log) } pages_that_are_routed_to = pages.select { |p| p.routed_to?(case_log) }
enabled_question_ids = pages_that_are_routed_to.flat_map(&:questions).map(&:id) || [] enabled_question_ids = pages_that_are_routed_to.flat_map(&:questions).map(&:id) || []
invalidated_pages(case_log).flat_map(&:questions).reject { |q| enabled_question_ids.include?(q.id) } || [] invalidated_pages(case_log).flat_map(&:questions).reject { |q| enabled_question_ids.include?(q.id) || address_questions.include?(q.id) } || []
end end
def invalidated_conditional_questions(case_log) def invalidated_conditional_questions(case_log)

82
config/forms/2021_2022.json

@ -1112,7 +1112,7 @@
"description": "", "description": "",
"questions": { "questions": {
"layear": { "layear": {
"check_answer_label": "How long has the household continuously lived in the local authority area where the new letting is located?", "check_answer_label": "Length of time in local authority area",
"header": "How long has the household continuously lived in the local authority area of the new letting?", "header": "How long has the household continuously lived in the local authority area of the new letting?",
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
@ -1146,14 +1146,15 @@
} }
} }
} }
} },
"depends_on": [{ "renewal": "No" }]
}, },
"time_on_la_waiting_list": { "time_on_la_waiting_list": {
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"lawaitlist": { "lawaitlist": {
"check_answer_label": "How long has the household been on the local authority waiting list where the new letting is located?", "check_answer_label": "Length of time on local authority waiting list",
"header": "How long has the household been on the local authority waiting list for the new letting?", "header": "How long has the household been on the local authority waiting list for the new letting?",
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
@ -1195,6 +1196,7 @@
"description": "", "description": "",
"questions": { "questions": {
"reason": { "reason": {
"check_answer_label": "Reason for leaving last settled home",
"header": "What is the tenant’s main reason for the household leaving their last settled home?", "header": "What is the tenant’s main reason for the household leaving their last settled home?",
"hint_text": "The tenant’s ’last settled home’ is their last long-standing home. For tenants who were in temporary accommodation or sleeping rough, their last settled home is where they were living previously.", "hint_text": "The tenant’s ’last settled home’ is their last long-standing home. For tenants who were in temporary accommodation or sleeping rough, their last settled home is where they were living previously.",
"type": "radio", "type": "radio",
@ -1314,13 +1316,36 @@
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"
} }
},
"depends_on": [{ "renewal": "No" }]
},
"reason_for_leaving_last_settled_home_renewal": {
"header": "Leaving their last settled home",
"description": "",
"questions": {
"reason": {
"check_answer_label": "Reason for leaving last settled home",
"header": "What is the tenant’s main reason for the household leaving their last settled home?",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"value": "End of fixed term tenancy - no fault"
},
"1": {
"value": "End of assured shorthold tenancy - no fault"
} }
}
}
},
"depends_on": [{ "renewal": "Yes" }]
}, },
"previous_housing_situation": { "previous_housing_situation": {
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"prevten": { "prevten": {
"check_answer_label": "Where was the household immediately before this letting?",
"header": "Where was the household immediately before this letting?", "header": "Where was the household immediately before this letting?",
"hint_text": "This is where the household was the night before they moved.", "hint_text": "This is where the household was the night before they moved.",
"type": "radio", "type": "radio",
@ -1396,13 +1421,36 @@
} }
} }
} }
},
"depends_on": [{ "renewal": "No" }]
},
"previous_housing_situation_renewal": {
"header": "",
"description": "",
"questions": {
"prevten": {
"check_answer_label": "Where was the household immediately before this letting?",
"header": "Where was the household immediately before this letting?",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"value": "Supported housing"
},
"1": {
"value": "Sheltered accommodation"
}
}
} }
}, },
"depends_on": [{ "renewal": "Yes", "needstype": "Supported housing" }]
},
"underoccupation_benefitcap": { "underoccupation_benefitcap": {
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"underoccupation_benefitcap": { "underoccupation_benefitcap": {
"check_answer_label": "Removal of spare room subsidy or benefit cap",
"header": "Was the reason for leaving a direct result of the removal of the spare room subsidy or benefit cap introduced from 2013?", "header": "Was the reason for leaving a direct result of the removal of the spare room subsidy or benefit cap introduced from 2013?",
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
@ -1427,13 +1475,15 @@
} }
} }
} }
} },
"depends_on": [{ "renewal": "No" }]
}, },
"homelessness": { "homelessness": {
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"homeless": { "homeless": {
"check_answer_label": "Household homeless immediately before letting",
"header": "Did the household experience homelessness immediately before this letting?", "header": "Did the household experience homelessness immediately before this letting?",
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
@ -1449,14 +1499,14 @@
} }
} }
} }
} },
"depends_on": [{ "renewal": "No" }]
}, },
"previous_postcode": { "previous_postcode": {
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"previous_postcode_known": { "previous_postcode_known": {
"check_answer_label": "Do you know the postcode of the household’s last settled accommodation?",
"header": "Do you know the property’s postcode?", "header": "Do you know the property’s postcode?",
"hint_text": "This is also known as the household’s ’last settled home’.", "hint_text": "This is also known as the household’s ’last settled home’.",
"type": "radio", "type": "radio",
@ -1470,7 +1520,7 @@
"hidden_in_check_answers": true "hidden_in_check_answers": true
}, },
"previous_postcode": { "previous_postcode": {
"check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", "check_answer_label": "Postcode of household’s last settled accommodation",
"header": "Postcode for the previous accommodation", "header": "Postcode for the previous accommodation",
"hint_text": "", "hint_text": "",
"type": "text", "type": "text",
@ -1507,7 +1557,7 @@
"description": "", "description": "",
"questions": { "questions": {
"prevloc": { "prevloc": {
"check_answer_label": "The LA in which household lived immediately before this letting\t", "check_answer_label": "Location of household’s last settled accommodation",
"header": "Which local authority area did the household live in immediately before this letting?", "header": "Which local authority area did the household live in immediately before this letting?",
"hint_text": "Includes temporary accommodation.", "hint_text": "Includes temporary accommodation.",
"type": "select", "type": "select",
@ -1908,7 +1958,7 @@
"description": "", "description": "",
"questions": { "questions": {
"reasonpref": { "reasonpref": {
"check_answer_label": "Was the household given ‘reasonable preference’ by the local authority?", "check_answer_label": "Household given reasonable preference",
"header": "Was the household given ‘reasonable preference’ by the local authority?", "header": "Was the household given ‘reasonable preference’ by the local authority?",
"hint_text": "Households may be given ‘reasonable preference’ for social housing, also known as ‘priority need’, by the local authority.", "hint_text": "Households may be given ‘reasonable preference’ for social housing, also known as ‘priority need’, by the local authority.",
"type": "radio", "type": "radio",
@ -1971,7 +2021,7 @@
"description": "", "description": "",
"questions": { "questions": {
"letting_allocation": { "letting_allocation": {
"check_answer_label": "How was this letting allocated?", "check_answer_label": "Allocation system",
"header": "How was this letting allocated?", "header": "How was this letting allocated?",
"hint_text": "Select all that apply.", "hint_text": "Select all that apply.",
"type": "checkbox", "type": "checkbox",
@ -2044,7 +2094,8 @@
"depends_on": [ "depends_on": [
{ {
"managing_organisation.provider_type": "LA", "managing_organisation.provider_type": "LA",
"needstype": "General needs" "needstype": "General needs",
"renewal": "No"
} }
] ]
}, },
@ -2100,7 +2151,8 @@
"depends_on": [ "depends_on": [
{ {
"managing_organisation.provider_type": "PRP", "managing_organisation.provider_type": "PRP",
"needstype": "General needs" "needstype": "General needs",
"renewal": "No"
} }
] ]
}, },
@ -2156,7 +2208,8 @@
"depends_on": [ "depends_on": [
{ {
"managing_organisation.provider_type": "LA", "managing_organisation.provider_type": "LA",
"needstype": "Supported housing" "needstype": "Supported housing",
"renewal": "No"
} }
] ]
}, },
@ -2215,7 +2268,8 @@
"depends_on": [ "depends_on": [
{ {
"managing_organisation.provider_type": "PRP", "managing_organisation.provider_type": "PRP",
"needstype": "Supported housing" "needstype": "Supported housing",
"renewal": "No"
} }
] ]
} }

2
db/migrate/20220210132254_remove_checkbox_parent_fields.rb

@ -11,7 +11,7 @@ class RemoveCheckboxParentFields < ActiveRecord::Migration[7.0]
change_table :case_logs, bulk: true do |t| change_table :case_logs, bulk: true do |t|
t.column :accessibility_requirements, :string t.column :accessibility_requirements, :string
t.column :condition_effects, :string t.column :condition_effects, :string
t.remove :reasonable_preference_reason, :string t.column :reasonable_preference_reason, :string
end end
end end
end end

15
db/migrate/20220216094400_change_unknown_letting_allocation_type.rb

@ -0,0 +1,15 @@
class ChangeUnknownLettingAllocationType < ActiveRecord::Migration[7.0]
def up
change_table :case_logs, bulk: true do |t|
t.remove :letting_allocation_unknown
t.column :letting_allocation_unknown, :integer
end
end
def down
change_table :case_logs, bulk: true do |t|
t.remove :letting_allocation_unknown
t.column :letting_allocation_unknown, :boolean
end
end
end

2
db/schema.rb

@ -190,7 +190,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "previous_postcode_known" t.integer "previous_postcode_known"
t.integer "previous_la_known" t.integer "previous_la_known"
t.boolean "is_previous_la_inferred" t.boolean "is_previous_la_inferred"
t.boolean "letting_allocation_unknown" t.integer "letting_allocation_unknown"
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

2
spec/features/form/accessible_autocomplete_spec.rb

@ -8,6 +8,8 @@ RSpec.describe "Accessible Automcomplete" do
FactoryBot.create( FactoryBot.create(
:case_log, :case_log,
:in_progress, :in_progress,
la_known: "Yes",
is_la_inferred: false,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
) )

2
spec/features/form/check_answers_page_spec.rb

@ -17,6 +17,8 @@ RSpec.describe "Form Check Answers Page" do
let(:empty_case_log) do let(:empty_case_log) do
FactoryBot.create( FactoryBot.create(
:case_log, :case_log,
la_known: "Yes",
is_la_inferred: false,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
) )

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

@ -19,8 +19,15 @@
"type": "text", "type": "text",
"width": 10 "width": 10
} }
}
}, },
"depends_on": [
{
"housingneeds_a": "Yes"
},
{
"housingneeds_a": null
}
] },
"person_1_age": { "person_1_age": {
"questions": { "questions": {
"age1": { "age1": {
@ -251,7 +258,13 @@
"E06000014": "York" "E06000014": "York"
} }
} }
},
"depends_on": [
{
"la_known": "Yes",
"is_la_inferred": false
} }
]
}, },
"condition_effects": { "condition_effects": {
"questions": { "questions": {

11
spec/helpers/tasklist_helper_spec.rb

@ -37,15 +37,20 @@ RSpec.describe TasklistHelper do
end end
end end
describe "get_first_page_or_check_answers" do describe "get_next_page_or_check_answers" do
let(:subsection) { case_log.form.get_subsection("household_characteristics") } let(:subsection) { case_log.form.get_subsection("household_characteristics") }
it "returns the check answers page path if the section has been started already" do it "returns the check answers page path if the section has been started already" do
expect(first_page_or_check_answers(subsection, case_log)).to match(/check-answers/) expect(next_page_or_check_answers(subsection, case_log)).to match(/check-answers/)
end end
it "returns the first question page path for the section if it has not been started yet" do it "returns the first question page path for the section if it has not been started yet" do
expect(first_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code/) expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code/)
end
it "when first question being not routed to returns the second question link" do
empty_case_log.housingneeds_a = "No"
expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/person-1-age/)
end end
end end

23
spec/models/case_log_spec.rb

@ -582,10 +582,25 @@ RSpec.describe CaseLog do
expect(case_log["underoccupation_benefitcap"]).to eq("No") expect(case_log["underoccupation_benefitcap"]).to eq("No")
end end
it "correctly derives and saves homeless" do it "correctly derives and saves prevten" do
record_from_db = ActiveRecord::Base.connection.execute("select homeless from case_logs where id=#{case_log.id}").to_a[0] case_log.update!({ needstype: "General needs" })
expect(record_from_db["homeless"]).to eq(1)
expect(case_log["homeless"]).to eq("No") record_from_db = ActiveRecord::Base.connection.execute("select prevten from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["prevten"]).to eq(32)
expect(case_log["prevten"]).to eq("Fixed-term private registered provider (PRP) general needs tenancy")
case_log.managing_organisation.update!({ provider_type: "LA" })
case_log.update!({ needstype: "General needs" })
record_from_db = ActiveRecord::Base.connection.execute("select prevten from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["prevten"]).to eq(30)
expect(case_log["prevten"]).to eq("Fixed-term local authority general needs tenancy")
end
it "correctly derives and saves referral" do
record_from_db = ActiveRecord::Base.connection.execute("select referral from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["referral"]).to eq(1)
expect(case_log["referral"]).to eq("Internal transfer")
end end
end end
end end

2
spec/models/form/subsection_spec.rb

@ -70,6 +70,8 @@ RSpec.describe Form::Subsection, type: :model do
case_log.armedforces = "No" case_log.armedforces = "No"
case_log.illness = "No" case_log.illness = "No"
case_log.housingneeds_a = "Yes" case_log.housingneeds_a = "Yes"
case_log.la_known = "Yes"
case_log.is_la_inferred = false
case_log.la = "York" case_log.la = "York"
case_log.illness_type_1 = "Yes" case_log.illness_type_1 = "Yes"
expect(sub_section.answered_questions(case_log).map(&:id)).to eq(expected_questions) expect(sub_section.answered_questions(case_log).map(&:id)).to eq(expected_questions)

2
spec/requests/case_logs_controller_spec.rb

@ -278,6 +278,8 @@ RSpec.describe CaseLogsController, type: :request do
case_log = FactoryBot.create(:case_log, case_log = FactoryBot.create(:case_log,
owning_organisation: organisation, owning_organisation: organisation,
managing_organisation: organisation, managing_organisation: organisation,
la_known: "Yes",
is_la_inferred: true,
postcode_known: "Yes", postcode_known: "Yes",
property_postcode: "PO5 3TE") property_postcode: "PO5 3TE")
id = case_log.id id = case_log.id

Loading…
Cancel
Save