Browse Source

Add rent period question and check multiple condition sets for depends_on

pull/213/head
Kat 4 years ago
parent
commit
4f499a67cf
  1. 8
      README.md
  2. 4
      app/models/form/page.rb
  3. 4
      app/models/form/subsection.rb
  4. 137
      config/forms/2021_2022.json
  5. 14
      spec/fixtures/forms/2021_2022.json
  6. 14
      spec/fixtures/forms/2022_2023.json
  7. 2
      spec/fixtures/forms/test_validator.json
  8. 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 ```jsonc
"page_1": { "questions": { "question_1: "answer_options": ["A", "B"] } }, "page_1": { "questions": { "question_1: "answer_options": ["A", "B"] } },
"page_2": { "questions": { "question_2: "answer_options": ["C", "D"] }, "depends_on": { "question_1": "A" } }, "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_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_4": { "questions": { "question_4: "answer_options": ["G", "H"] }, "depends_on": [{ "question_1": "B" }] },
``` ```
## JSON Form Validation against Schema ## JSON Form Validation against Schema

4
app/models/form/page.rb

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

4
app/models/form/subsection.rb

@ -18,10 +18,12 @@ class Form::Subsection
def enabled?(case_log) def enabled?(case_log)
return true unless depends_on 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 form.get_subsection(subsection_id).status(case_log) == dependent_status.to_sym
end end
end end
end
def status(case_log) def status(case_log)
unless enabled?(case_log) unless enabled?(case_log)

137
config/forms/2021_2022.json

@ -31,7 +31,7 @@
"hint_text": "", "hint_text": "",
"description": "We cannot accept data about a tenant or buyer unless they’ve seen the <a class=\"govuk-link\" href=\"/files/privacy-notice.pdf\">DLUHC privacy notice</a>.<br /><br /><a class=\"govuk-link\" href=\"/logs\">Go to your logs</a>", "description": "We cannot accept data about a tenant or buyer unless they’ve seen the <a class=\"govuk-link\" href=\"/files/privacy-notice.pdf\">DLUHC privacy notice</a>.<br /><br /><a class=\"govuk-link\" href=\"/logs\">Go to your logs</a>",
"questions": {}, "questions": {},
"depends_on": { "gdpr_acceptance": "No" } "depends_on": [{ "gdpr_acceptance": "No" }]
}, },
"organisation_details": { "organisation_details": {
"header": "Organisation details", "header": "Organisation details",
@ -58,7 +58,7 @@
} }
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes" } "depends_on": [{ "gdpr_acceptance": "Yes" }]
}, },
"sale_or_letting": { "sale_or_letting": {
"header": "", "header": "",
@ -75,7 +75,7 @@
} }
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes" } "depends_on": [{ "gdpr_acceptance": "Yes" }]
}, },
"tenant_same_property_renewal": { "tenant_same_property_renewal": {
"header": "", "header": "",
@ -92,10 +92,10 @@
} }
} }
}, },
"depends_on": { "depends_on": [{
"gdpr_acceptance": "Yes", "gdpr_acceptance": "Yes",
"sale_or_letting": "Letting" "sale_or_letting": "Letting"
} }]
}, },
"startdate": { "startdate": {
"header": "", "header": "",
@ -108,10 +108,10 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "depends_on": [{
"gdpr_acceptance": "Yes", "gdpr_acceptance": "Yes",
"sale_or_letting": "Letting" "sale_or_letting": "Letting"
} }]
}, },
"about_this_letting": { "about_this_letting": {
"header": "Tell us about this letting", "header": "Tell us about this letting",
@ -152,10 +152,10 @@
} }
} }
}, },
"depends_on": { "depends_on": [{
"gdpr_acceptance": "Yes", "gdpr_acceptance": "Yes",
"sale_or_letting": "Letting" "sale_or_letting": "Letting"
} }]
}, },
"tenant_code": { "tenant_code": {
"header": "", "header": "",
@ -169,10 +169,10 @@
"width": 10 "width": 10
} }
}, },
"depends_on": { "depends_on": [{
"gdpr_acceptance": "Yes", "gdpr_acceptance": "Yes",
"sale_or_letting": "Letting" "sale_or_letting": "Letting"
} }]
}, },
"property_reference": { "property_reference": {
"header": "", "header": "",
@ -186,7 +186,7 @@
"width": 10 "width": 10
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes" } "depends_on": [{ "gdpr_acceptance": "Yes" }]
}, },
"sale_completion_date": { "sale_completion_date": {
"header": "", "header": "",
@ -199,10 +199,10 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "depends_on": [{
"gdpr_acceptance": "Yes", "gdpr_acceptance": "Yes",
"sale_or_letting": "Sale" "sale_or_letting": "Sale"
} }]
}, },
"purchaser_code": { "purchaser_code": {
"header": "", "header": "",
@ -216,10 +216,10 @@
"width": 10 "width": 10
} }
}, },
"depends_on": { "depends_on": [{
"gdpr_acceptance": "Yes", "gdpr_acceptance": "Yes",
"sale_or_letting": "Sale" "sale_or_letting": "Sale"
} }]
} }
} }
} }
@ -230,7 +230,7 @@
"subsections": { "subsections": {
"household_characteristics": { "household_characteristics": {
"label": "Household characteristics", "label": "Household characteristics",
"depends_on": { "about_this_log": "completed" }, "depends_on": [{ "about_this_log": "completed" }],
"pages": { "pages": {
"person_1_age": { "person_1_age": {
"header": "", "header": "",
@ -779,7 +779,7 @@
}, },
"household_situation": { "household_situation": {
"label": "Household situation", "label": "Household situation",
"depends_on": { "about_this_log": "completed" }, "depends_on": [{ "about_this_log": "completed" }],
"pages": { "pages": {
"previous_housing_situation": { "previous_housing_situation": {
"header": "", "header": "",
@ -907,7 +907,7 @@
}, },
"household_needs": { "household_needs": {
"label": "Household needs", "label": "Household needs",
"depends_on": { "about_this_log": "completed" }, "depends_on": [{ "about_this_log": "completed" }],
"pages": { "pages": {
"armed_forces": { "armed_forces": {
"header": "Experience of the UK Armed Forces", "header": "Experience of the UK Armed Forces",
@ -1052,7 +1052,7 @@
"subsections": { "subsections": {
"tenancy_information": { "tenancy_information": {
"label": "Tenancy information", "label": "Tenancy information",
"depends_on": { "about_this_log": "completed" }, "depends_on": [{ "about_this_log": "completed" }],
"pages": { "pages": {
"starter_tenancy": { "starter_tenancy": {
"header": "", "header": "",
@ -1133,7 +1133,7 @@
}, },
"property_information": { "property_information": {
"label": "Property information", "label": "Property information",
"depends_on": { "about_this_log": "completed" }, "depends_on": [{ "about_this_log": "completed" }],
"pages": { "pages": {
"property_postcode": { "property_postcode": {
"header": "", "header": "",
@ -1182,7 +1182,7 @@
} }
} }
}, },
"depends_on": { "is_la_inferred": false } "depends_on": [{ "is_la_inferred": false }]
}, },
"select_local_authority": { "select_local_authority": {
"header": "", "header": "",
@ -1514,7 +1514,7 @@
} }
} }
}, },
"depends_on": { "la_known": "Yes", "is_la_inferred": false } "depends_on": [{ "la_known": "Yes", "is_la_inferred": false }]
}, },
"why_dont_you_know_la": { "why_dont_you_know_la": {
"header": "", "header": "",
@ -1527,7 +1527,7 @@
"type": "textarea" "type": "textarea"
} }
}, },
"depends_on": { "la_known": "No", "is_la_inferred": false } "depends_on": [{ "la_known": "No", "is_la_inferred": false }]
}, },
"first_time_property_let_as_social_housing": { "first_time_property_let_as_social_housing": {
"header": "", "header": "",
@ -1544,7 +1544,7 @@
} }
} }
}, },
"depends_on": { "tenant_same_property_renewal": "No" } "depends_on": [{ "tenant_same_property_renewal": "No" }]
}, },
"unitletas": { "unitletas": {
"header": "", "header": "",
@ -1564,10 +1564,10 @@
} }
} }
}, },
"depends_on": { "depends_on": [{
"first_time_property_let_as_social_housing": "No", "first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No" "tenant_same_property_renewal": "No"
} }]
}, },
"property_vacancy_reason_not_first_let": { "property_vacancy_reason_not_first_let": {
"header": "", "header": "",
@ -1593,10 +1593,10 @@
} }
} }
}, },
"depends_on": { "depends_on": [{
"first_time_property_let_as_social_housing": "No", "first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No" "tenant_same_property_renewal": "No"
} }]
}, },
"property_vacancy_reason_first_let": { "property_vacancy_reason_first_let": {
"header": "", "header": "",
@ -1614,10 +1614,10 @@
} }
} }
}, },
"depends_on": { "depends_on": [{
"first_time_property_let_as_social_housing": "Yes", "first_time_property_let_as_social_housing": "Yes",
"tenant_same_property_renewal": "No" "tenant_same_property_renewal": "No"
} }]
}, },
"property_number_of_times_relet_not_social_let": { "property_number_of_times_relet_not_social_let": {
"header": "", "header": "",
@ -1634,10 +1634,10 @@
"width": 2 "width": 2
} }
}, },
"depends_on": { "depends_on": [{
"first_time_property_let_as_social_housing": "No", "first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No" "tenant_same_property_renewal": "No"
} }]
}, },
"property_number_of_times_relet_social_let": { "property_number_of_times_relet_social_let": {
"header": "", "header": "",
@ -1654,10 +1654,10 @@
"width": 2 "width": 2
} }
}, },
"depends_on": { "depends_on": [{
"first_time_property_let_as_social_housing": "Yes", "first_time_property_let_as_social_housing": "Yes",
"tenant_same_property_renewal": "No" "tenant_same_property_renewal": "No"
} }]
}, },
"property_unit_type": { "property_unit_type": {
"header": "", "header": "",
@ -1728,7 +1728,7 @@
"width": 2 "width": 2
} }
}, },
"depends_on": { "needstype": "General needs" } "depends_on": [{ "needstype": "General needs" }]
}, },
"void_or_renewal_date": { "void_or_renewal_date": {
"header": "", "header": "",
@ -1741,10 +1741,10 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "depends_on": [{
"rsnvac": "First let of new-build property", "rsnvac": "First let of new-build property",
"tenant_same_property_renewal": "No" "tenant_same_property_renewal": "No"
} }]
}, },
"new_build_handover_date": { "new_build_handover_date": {
"header": "", "header": "",
@ -1757,13 +1757,13 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "depends_on": [{
"tenant_same_property_renewal": "No", "tenant_same_property_renewal": "No",
"rsnvac": [ "rsnvac": [
"First let of conversion, rehabilitation or acquired property?", "First let of conversion, rehabilitation or acquired property?",
"First let of leased property" "First let of leased property"
] ]
} }]
}, },
"property_major_repairs": { "property_major_repairs": {
"header": "", "header": "",
@ -1789,10 +1789,10 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "depends_on": [{
"rsnvac": "First let of new-build property", "rsnvac": "First let of new-build property",
"tenant_same_property_renewal": "No" "tenant_same_property_renewal": "No"
} }]
} }
} }
} }
@ -1803,7 +1803,7 @@
"subsections": { "subsections": {
"income_and_benefits": { "income_and_benefits": {
"label": "Income, benefits and outgoings", "label": "Income, benefits and outgoings",
"depends_on": { "about_this_log": "completed" }, "depends_on": [{ "about_this_log": "completed" }],
"pages": { "pages": {
"net_income_known": { "net_income_known": {
"header": "Household’s combined income", "header": "Household’s combined income",
@ -1826,9 +1826,7 @@
} }
}, },
"weekly_net_income": { "weekly_net_income": {
"depends_on": { "depends_on": [{ "net_income_known": "Yes – the household has a weekly income" }],
"net_income_known": "Yes – the household has a weekly income"
},
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
@ -1854,9 +1852,7 @@
} }
}, },
"monthly_net_income": { "monthly_net_income": {
"depends_on": { "depends_on": [{ "net_income_known": "Yes – the household has a monthly income" }],
"net_income_known": "Yes – the household has a monthly income"
},
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
@ -1882,9 +1878,7 @@
} }
}, },
"yearly_net_income": { "yearly_net_income": {
"depends_on": { "depends_on": [{ "net_income_known": "Yes – the household has a yearly income" }],
"net_income_known": "Yes – the household has a yearly income"
},
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
@ -1965,13 +1959,42 @@
} }
} }
}, },
"depends_on": { "needstype": "Supported housing" } "depends_on": [{ "needstype": "Supported housing" }]
},
"rent_period": {
"header": "",
"description": "",
"questions": {
"period": {
"check_answer_label": "Rent Period",
"header": "How often does the household pay rent and other charges?",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "Weekly for 52 weeks",
"1": "Fortnightly",
"2": "Four-weekly",
"3": "Calendar monthly",
"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"
}
}
},
"depends_on" : [{
"nocharge": "Yes"
},{
"nocharge": null
}]
} }
} }
}, },
"rent": { "rent": {
"label": "Rent", "label": "Rent",
"depends_on": { "about_this_log": "completed" }, "depends_on": [{ "about_this_log": "completed" }],
"pages": { "pages": {
"rent": { "rent": {
"header": "", "header": "",
@ -2089,7 +2112,7 @@
"subsections": { "subsections": {
"local_authority": { "local_authority": {
"label": "Local authority", "label": "Local authority",
"depends_on": { "about_this_log": "completed" }, "depends_on": [{ "about_this_log": "completed" }],
"pages": { "pages": {
"time_lived_in_la": { "time_lived_in_la": {
"header": "", "header": "",
@ -2627,7 +2650,7 @@
"subsections": { "subsections": {
"declaration": { "declaration": {
"label": "Declaration", "label": "Declaration",
"depends_on": { "depends_on": [{
"about_this_log": "completed", "about_this_log": "completed",
"household_characteristics": "completed", "household_characteristics": "completed",
"household_situation": "completed", "household_situation": "completed",
@ -2637,7 +2660,7 @@
"income_and_benefits": "completed", "income_and_benefits": "completed",
"rent": "completed", "rent": "completed",
"local_authority": "completed" "local_authority": "completed"
}, }],
"pages": { "pages": {
"declaration": { "declaration": {
"header": "", "header": "",

14
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": { "property_wheelchair_accessible": {
"questions": { "questions": {
@ -321,7 +321,7 @@
} }
} }
}, },
"depends_on": { "preg_occ": "Yes" } "depends_on": [{ "preg_occ": "Yes" }, { "wchair" : "Yes" }]
}, },
"conditional_question_no_page": { "conditional_question_no_page": {
"questions": { "questions": {
@ -335,7 +335,7 @@
} }
} }
}, },
"depends_on": { "preg_occ": "No" } "depends_on": [{ "preg_occ": "No" }]
}, },
"conditional_question_no_second_page": { "conditional_question_no_second_page": {
"questions": { "questions": {
@ -349,7 +349,7 @@
} }
} }
}, },
"depends_on": { "preg_occ": "No", "sex1": "Male" } "depends_on": [{ "preg_occ": "No", "sex1": "Male" }]
} }
} }
} }
@ -436,7 +436,7 @@
} }
}, },
"dependent_page": { "dependent_page": {
"depends_on": { "incfreq": "Weekly" }, "depends_on": [{ "incfreq": "Weekly" }],
"questions": { "questions": {
"dependent_question": { "dependent_question": {
"check_answer_label": "Dependent Question", "check_answer_label": "Dependent Question",
@ -642,7 +642,7 @@
"subsections": { "subsections": {
"declaration": { "declaration": {
"label": "Declaration", "label": "Declaration",
"depends_on": { "depends_on": [{
"household_characteristics": "completed", "household_characteristics": "completed",
"household_needs": "completed", "household_needs": "completed",
"tenancy_information": "completed", "tenancy_information": "completed",
@ -650,7 +650,7 @@
"income_and_benefits": "completed", "income_and_benefits": "completed",
"rent": "completed", "rent": "completed",
"local_authority": "completed" "local_authority": "completed"
}, }],
"pages": { "pages": {
"declaration": { "declaration": {
"questions": { "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.", "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.",
"questions": { "questions": {
}, },
"depends_on": { "gdpr_acceptance": "No" } "depends_on": [{ "gdpr_acceptance": "No" }]
}, },
"sale_or_letting": { "sale_or_letting": {
"header": "", "header": "",
@ -46,7 +46,7 @@
} }
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes" } "depends_on": [{ "gdpr_acceptance": "Yes" }]
}, },
"tenant_same_property_renewal": { "tenant_same_property_renewal": {
"header": "", "header": "",
@ -63,7 +63,7 @@
} }
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" } "depends_on": [{ "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }]
}, },
"startdate": { "startdate": {
"header": "", "header": "",
@ -76,7 +76,7 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" } "depends_on": [{ "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }]
}, },
"about_this_letting": { "about_this_letting": {
"header": "Tell us 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": { "sale_completion_date": {
"header": "", "header": "",
@ -128,7 +128,7 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" } "depends_on": [{ "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" }]
}, },
"purchaser_code": { "purchaser_code": {
"header": "", "header": "",
@ -142,7 +142,7 @@
"width": 10 "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" "type": "text"
} }
}, },
"depends_on": {"test": "Yes"} "depends_on": [{"test": "Yes"}]
}, },
"person_1_age": { "person_1_age": {
"header": "", "header": "",

16
spec/requests/form_controller_spec.rb

@ -269,6 +269,16 @@ RSpec.describe FormController, type: :request do
} }
end 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 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 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") 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 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") expect(response).to redirect_to("/logs/#{case_log.id}/conditional-question-no-page")
end 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 end
context "case logs that are not owned or managed by your organisation" do context "case logs that are not owned or managed by your organisation" do

Loading…
Cancel
Save