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
attr_accessor :id, :header, :hint_text, :description, :questions,
: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)
@id = id
@ -18,6 +18,7 @@ class Form::Question
@readonly = hsh["readonly"]
@answer_options = hsh["answer_options"]
@conditional_for = hsh["conditional_for"]
@inferred_answers = hsh["inferred_answers"]
@page = page
end
@ -31,6 +32,14 @@ class Form::Question
case_log[id].to_s
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?
!!readonly
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 %>
<dt>
<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 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 %>

142
config/forms/2021_2022.json

@ -29,8 +29,7 @@
"header": "You cannot use this service",
"hint_text": "",
"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" }
},
"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": {
"header": "",
@ -105,7 +107,10 @@
"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",
@ -125,7 +130,9 @@
"5": "Other intermediate rent product"
},
"conditional_for": {
"intermediate_rent_product_name": ["Other intermediate rent product"]
"intermediate_rent_product_name": [
"Other intermediate rent product"
]
}
},
"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": {
"header": "",
@ -158,7 +168,10 @@
"width": 10
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }
"depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Letting"
}
},
"property_reference": {
"header": "",
@ -185,7 +198,10 @@
"type": "date"
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" }
"depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Sale"
}
},
"purchaser_code": {
"header": "",
@ -199,7 +215,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": {
"household_characteristics": {
"label": "Household characteristics",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"person_1_age": {
"header": "",
@ -302,7 +321,7 @@
"10": "Romania",
"11": "Ireland",
"12": "Slovakia",
"13":"Slovenia",
"13": "Slovenia",
"14": "Croatia",
"15": "Other EU Economic Area (EEA country)",
"16": "Any other country",
@ -759,7 +778,7 @@
},
"household_situation": {
"label": "Household situation",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"previous_housing_situation": {
"header": "",
@ -885,7 +904,7 @@
},
"household_needs": {
"label": "Household needs",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"armed_forces": {
"header": "Experience of the UK Armed Forces",
@ -897,15 +916,19 @@
"type": "radio",
"check_answer_label": "Armed Forces",
"answer_options": {
"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)",
"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)",
"2": "A spouse / civil partner of a UK Armed Forces member who has separated or been bereaved within the last 2 years",
"3": "No",
"4": "Tenant prefers not to say"
},
"conditional_for": {
"leftreg": ["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": [
"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": {
@ -1023,7 +1046,7 @@
"subsections": {
"tenancy_information": {
"label": "Tenancy information",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"starter_tenancy": {
"header": "",
@ -1128,7 +1151,8 @@
"header": "",
"hint_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": {
"header": "",
@ -1509,7 +1533,7 @@
}
}
},
"depends_on": { "tenant_same_property_renewal": "No"}
"depends_on": { "tenant_same_property_renewal": "No" }
},
"unitletas": {
"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": {
"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": {
"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": {
"header": "",
@ -1588,7 +1621,10 @@
"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": {
"header": "",
@ -1604,7 +1640,10 @@
"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": {
"header": "",
@ -1687,7 +1726,10 @@
"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": {
"header": "",
@ -1702,7 +1744,10 @@
},
"depends_on": {
"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": {
@ -1729,7 +1774,10 @@
"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": {
"income_and_benefits": {
"label": "Income and benefits",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"net_income": {
"header": "",
@ -1834,7 +1882,7 @@
},
"rent": {
"label": "Rent",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"rent": {
"header": "",
@ -1865,12 +1913,7 @@
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"scharge": {
@ -1880,12 +1923,7 @@
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"pscharge": {
@ -1895,12 +1933,7 @@
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"supcharg": {
@ -1910,12 +1943,7 @@
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"tcharge": {
@ -1960,7 +1988,7 @@
"subsections": {
"local_authority": {
"label": "Local authority",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"time_lived_in_la": {
"header": "",
@ -2428,7 +2456,7 @@
"answer_options": {
"0": "Yes",
"1": "No",
"2": "Do not know"
"2": "Do not know"
},
"conditional_for": {
"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
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
describe "PATCH" do

Loading…
Cancel
Save