Browse Source

Show inferred postcode

pull/190/head
Kat 4 years ago
parent
commit
04b9476a42
  1. 11
      app/models/form/question.rb
  2. 5
      app/views/form/_check_answers_table.html.erb
  3. 142
      config/forms/2021_2022.json
  4. 20
      spec/requests/case_log_controller_spec.rb

11
app/models/form/question.rb

@ -1,7 +1,7 @@
class Form::Question class Form::Question
attr_accessor :id, :header, :hint_text, :description, :questions, attr_accessor :id, :header, :hint_text, :description, :questions,
:type, :min, :max, :step, :width, :fields_to_add, :result_field, :type, :min, :max, :step, :width, :fields_to_add, :result_field,
:conditional_for, :readonly, :answer_options, :page, :check_answer_label :conditional_for, :readonly, :answer_options, :page, :check_answer_label, :inferred_answers
def initialize(id, hsh, page) def initialize(id, hsh, page)
@id = id @id = id
@ -18,6 +18,7 @@ class Form::Question
@readonly = hsh["readonly"] @readonly = hsh["readonly"]
@answer_options = hsh["answer_options"] @answer_options = hsh["answer_options"]
@conditional_for = hsh["conditional_for"] @conditional_for = hsh["conditional_for"]
@inferred_answers = hsh["inferred_answers"]
@page = page @page = page
end end
@ -31,6 +32,14 @@ class Form::Question
case_log[id].to_s case_log[id].to_s
end end
def get_inferred_answers(case_log)
if inferred_answers
inferred_answers.keys.map { |x| case_log[x].to_s }
else
[]
end
end
def read_only? def read_only?
!!readonly !!readonly
end end

5
app/views/form/_check_answers_table.html.erb

@ -3,7 +3,10 @@
<%= question.check_answer_label.to_s.present? ? question.check_answer_label.to_s : question.header.to_s %> <%= question.check_answer_label.to_s.present? ? question.check_answer_label.to_s : question.header.to_s %>
<dt> <dt>
<dd class="govuk-summary-list__value"> <dd class="govuk-summary-list__value">
<%= question.answer_label(@case_log) %> <%= question.answer_label(@case_log) %> <br/>
<% question.get_inferred_answers(@case_log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span><br/>
<% end %>
</dd> </dd>
<dd class="govuk-summary-list__actions"> <dd class="govuk-summary-list__actions">
<%= govuk_link_to(question.update_answer_link_name(@case_log), "/logs/#{@case_log.id}/#{question.page.id.to_s.dasherize}").html_safe %> <%= govuk_link_to(question.update_answer_link_name(@case_log), "/logs/#{@case_log.id}/#{question.page.id.to_s.dasherize}").html_safe %>

142
config/forms/2021_2022.json

@ -29,8 +29,7 @@
"header": "You cannot use this service", "header": "You cannot use this service",
"hint_text": "", "hint_text": "",
"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" }
}, },
"organisation_details": { "organisation_details": {
@ -92,7 +91,10 @@
} }
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" } "depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Letting"
}
}, },
"startdate": { "startdate": {
"header": "", "header": "",
@ -105,7 +107,10 @@
"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",
@ -125,7 +130,9 @@
"5": "Other intermediate rent product" "5": "Other intermediate rent product"
}, },
"conditional_for": { "conditional_for": {
"intermediate_rent_product_name": ["Other intermediate rent product"] "intermediate_rent_product_name": [
"Other intermediate rent product"
]
} }
}, },
"intermediate_rent_product_name": { "intermediate_rent_product_name": {
@ -144,7 +151,10 @@
} }
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" } "depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Letting"
}
}, },
"tenant_code": { "tenant_code": {
"header": "", "header": "",
@ -158,7 +168,10 @@
"width": 10 "width": 10
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" } "depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Letting"
}
}, },
"property_reference": { "property_reference": {
"header": "", "header": "",
@ -185,7 +198,10 @@
"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": "",
@ -199,7 +215,10 @@
"width": 10 "width": 10
} }
}, },
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" } "depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Sale"
}
} }
} }
} }
@ -210,7 +229,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": "",
@ -302,7 +321,7 @@
"10": "Romania", "10": "Romania",
"11": "Ireland", "11": "Ireland",
"12": "Slovakia", "12": "Slovakia",
"13":"Slovenia", "13": "Slovenia",
"14": "Croatia", "14": "Croatia",
"15": "Other EU Economic Area (EEA country)", "15": "Other EU Economic Area (EEA country)",
"16": "Any other country", "16": "Any other country",
@ -759,7 +778,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": "",
@ -885,7 +904,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",
@ -897,15 +916,19 @@
"type": "radio", "type": "radio",
"check_answer_label": "Armed Forces", "check_answer_label": "Armed Forces",
"answer_options": { "answer_options": {
"0":"A current or former regular in the UK Armed Forces (exc. National Service)", "0": "A current or former regular in the UK Armed Forces (exc. National Service)",
"1":"A current or former reserve in the UK Armed Forces (exc. National Service)", "1": "A current or former reserve in the UK Armed Forces (exc. National Service)",
"2": "A spouse / civil partner of a UK Armed Forces member who has separated or been bereaved within the last 2 years", "2": "A spouse / civil partner of a UK Armed Forces member who has separated or been bereaved within the last 2 years",
"3": "No", "3": "No",
"4": "Tenant prefers not to say" "4": "Tenant prefers not to say"
}, },
"conditional_for": { "conditional_for": {
"leftreg": ["A current or former regular in the UK Armed Forces (exc. National Service)"], "leftreg": [
"reservist": ["A current or former regular in the UK Armed Forces (exc. National Service)"] "A current or former regular in the UK Armed Forces (exc. National Service)"
],
"reservist": [
"A current or former regular in the UK Armed Forces (exc. National Service)"
]
} }
}, },
"leftreg": { "leftreg": {
@ -1023,7 +1046,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": "",
@ -1128,7 +1151,8 @@
"header": "", "header": "",
"hint_text": "", "hint_text": "",
"type": "text", "type": "text",
"width": 5 "width": 5,
"inferred_answers": { "la": { "is_la_inferred": true } }
} }
} }
}, },
@ -1147,7 +1171,7 @@
} }
} }
}, },
"depends_on": {"is_la_inferred": false} "depends_on": { "is_la_inferred": false }
}, },
"select_local_authority": { "select_local_authority": {
"header": "", "header": "",
@ -1509,7 +1533,7 @@
} }
} }
}, },
"depends_on": { "tenant_same_property_renewal": "No"} "depends_on": { "tenant_same_property_renewal": "No" }
}, },
"unitletas": { "unitletas": {
"header": "", "header": "",
@ -1528,7 +1552,10 @@
} }
} }
}, },
"depends_on": { "first_time_property_let_as_social_housing": "No", "tenant_same_property_renewal": "No" } "depends_on": {
"first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No"
}
}, },
"property_vacancy_reason_not_first_let": { "property_vacancy_reason_not_first_let": {
"header": "", "header": "",
@ -1554,7 +1581,10 @@
} }
} }
}, },
"depends_on": { "first_time_property_let_as_social_housing": "No", "tenant_same_property_renewal": "No" } "depends_on": {
"first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No"
}
}, },
"property_vacancy_reason_first_let": { "property_vacancy_reason_first_let": {
"header": "", "header": "",
@ -1572,7 +1602,10 @@
} }
} }
}, },
"depends_on": { "first_time_property_let_as_social_housing": "Yes", "tenant_same_property_renewal": "No" } "depends_on": {
"first_time_property_let_as_social_housing": "Yes",
"tenant_same_property_renewal": "No"
}
}, },
"property_number_of_times_relet_not_social_let": { "property_number_of_times_relet_not_social_let": {
"header": "", "header": "",
@ -1588,7 +1621,10 @@
"step": 1 "step": 1
} }
}, },
"depends_on": { "first_time_property_let_as_social_housing": "No", "tenant_same_property_renewal": "No" } "depends_on": {
"first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No"
}
}, },
"property_number_of_times_relet_social_let": { "property_number_of_times_relet_social_let": {
"header": "", "header": "",
@ -1604,7 +1640,10 @@
"step": 1 "step": 1
} }
}, },
"depends_on": { "first_time_property_let_as_social_housing": "Yes", "tenant_same_property_renewal": "No" } "depends_on": {
"first_time_property_let_as_social_housing": "Yes",
"tenant_same_property_renewal": "No"
}
}, },
"property_unit_type": { "property_unit_type": {
"header": "", "header": "",
@ -1687,7 +1726,10 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "rsnvac": "First let of newbuild property", "tenant_same_property_renewal": "No" } "depends_on": {
"rsnvac": "First let of newbuild property",
"tenant_same_property_renewal": "No"
}
}, },
"new_build_handover_date": { "new_build_handover_date": {
"header": "", "header": "",
@ -1702,7 +1744,10 @@
}, },
"depends_on": { "depends_on": {
"tenant_same_property_renewal": "No", "tenant_same_property_renewal": "No",
"rsnvac": ["First let of conversion, rehabilitation or acquired property?", "First let of leased property"] "rsnvac": [
"First let of conversion, rehabilitation or acquired property?",
"First let of leased property"
]
} }
}, },
"property_major_repairs": { "property_major_repairs": {
@ -1729,7 +1774,10 @@
"type": "date" "type": "date"
} }
}, },
"depends_on": { "rsnvac": "First let of newbuild property", "tenant_same_property_renewal": "No"} "depends_on": {
"rsnvac": "First let of newbuild property",
"tenant_same_property_renewal": "No"
}
} }
} }
} }
@ -1740,7 +1788,7 @@
"subsections": { "subsections": {
"income_and_benefits": { "income_and_benefits": {
"label": "Income and benefits", "label": "Income and benefits",
"depends_on": {"about_this_log": "completed"}, "depends_on": { "about_this_log": "completed" },
"pages": { "pages": {
"net_income": { "net_income": {
"header": "", "header": "",
@ -1834,7 +1882,7 @@
}, },
"rent": { "rent": {
"label": "Rent", "label": "Rent",
"depends_on": {"about_this_log": "completed"}, "depends_on": { "about_this_log": "completed" },
"pages": { "pages": {
"rent": { "rent": {
"header": "", "header": "",
@ -1865,12 +1913,7 @@
"type": "numeric", "type": "numeric",
"min": 0, "min": 0,
"step": 1, "step": 1,
"fields-to-add": [ "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge" "result-field": "tcharge"
}, },
"scharge": { "scharge": {
@ -1880,12 +1923,7 @@
"type": "numeric", "type": "numeric",
"min": 0, "min": 0,
"step": 1, "step": 1,
"fields-to-add": [ "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge" "result-field": "tcharge"
}, },
"pscharge": { "pscharge": {
@ -1895,12 +1933,7 @@
"type": "numeric", "type": "numeric",
"min": 0, "min": 0,
"step": 1, "step": 1,
"fields-to-add": [ "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge" "result-field": "tcharge"
}, },
"supcharg": { "supcharg": {
@ -1910,12 +1943,7 @@
"type": "numeric", "type": "numeric",
"min": 0, "min": 0,
"step": 1, "step": 1,
"fields-to-add": [ "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge" "result-field": "tcharge"
}, },
"tcharge": { "tcharge": {
@ -1960,7 +1988,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": "",
@ -2428,7 +2456,7 @@
"answer_options": { "answer_options": {
"0": "Yes", "0": "Yes",
"1": "No", "1": "No",
"2": "Do not know" "2": "Do not know"
}, },
"conditional_for": { "conditional_for": {
"reasonable_preference_reason": ["Yes"] "reasonable_preference_reason": ["Yes"]

20
spec/requests/case_log_controller_spec.rb

@ -240,6 +240,26 @@ RSpec.describe CaseLogsController, type: :request do
end end
end end
end end
context "Check answers" do
before do
stub_request(:get, /api.postcodes.io/)
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\"}}", headers: {})
sign_in user
end
it "shows the inferred postcode" do
case_log = FactoryBot.create(:case_log,
owning_organisation: organisation,
managing_organisation: organisation,
postcode_known: "Yes",
property_postcode: "P0 0ST")
id = case_log.id
get "/logs/#{id}/property-information/check-answers"
expected_inferred_answer = "<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">Manchester</span>"
expect(CGI.unescape_html(response.body)).to include(expected_inferred_answer)
end
end
end end
describe "PATCH" do describe "PATCH" do

Loading…
Cancel
Save