Browse Source

Cldc 632 check answers (#228)

Co-authored-by: dushan-madetech <dushan@madetech.com>
pull/231/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
be87a1348a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/helpers/check_answers_helper.rb
  2. 8
      app/models/case_log.rb
  3. 9
      app/models/constants/case_log.rb
  4. 4
      app/models/form/subsection.rb
  5. 2
      app/models/validations/financial_validations.rb
  6. 2
      app/views/form/_check_answers_table.html.erb
  7. 191
      config/forms/2021_2022.json
  8. 2
      config/locales/en.yml
  9. 2
      spec/factories/case_log.rb
  10. 2
      spec/fixtures/complete_case_log.json
  11. 4
      spec/fixtures/forms/2021_2022.json
  12. 8
      spec/models/case_log_spec.rb
  13. 2
      spec/models/form/question_spec.rb
  14. 5
      spec/requests/case_log_controller_spec.rb

10
app/helpers/check_answers_helper.rb

@ -12,6 +12,16 @@ module CheckAnswersHelper
end
end
def get_answer_label(question, case_log)
answer = ActionController::Base.helpers.number_to_currency(question.answer_label(case_log), delimiter: ",", format: "%n")
if answer.present?
[question.prefix, answer, question.suffix].join("")
else
"<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end
end
private
def create_next_missing_question_link(subsection, case_log)

8
app/models/case_log.rb

@ -241,18 +241,20 @@ private
self.year = startdate.year
end
case net_income_known
when "Yes – the household has a weekly income"
when "Weekly"
self.incfreq = "Weekly"
self.incref = nil
when "Yes – the household has a monthly income"
when "Monthly"
self.incfreq = "Monthly"
self.incref = nil
when "Yes – the household has a yearly income"
when "Annually"
self.incfreq = "Yearly"
self.incref = nil
when "Tenant prefers not to say"
self.incref = 1
self.incfreq = nil
when "Don’t know"
self.incfreq = nil
end
self.hhmemb = other_hhmemb + 1 if other_hhmemb.present?
self.renttype = RENT_TYPE_MAPPING[rent_type]

9
app/models/constants/case_log.rb

@ -233,7 +233,7 @@ module Constants::CaseLog
"Universal Credit (without housing element)" => 7,
"Housing benefit and Universal Credit (without housing element)" => 8,
"None" => 9,
"Don't know" => 3,
"Dont know" => 3,
"Tenant prefers not to say" => 100,
}.freeze
@ -1071,10 +1071,11 @@ module Constants::CaseLog
}.freeze
NET_INCOME_KNOWN = {
"Yes – the household has a weekly income" => 0,
"Yes – the household has a monthly income" => 1,
"Yes – the household has a yearly income" => 2,
"Weekly" => 0,
"Monthly" => 1,
"Annually" => 2,
"Tenant prefers not to say" => 3,
"Don’t know" => 4,
}.freeze
HAS_BENEFITS_OPTIONS = ["Housing benefit",

4
app/models/form/subsection.rb

@ -31,7 +31,7 @@ class Form::Subsection
end
qs = applicable_questions(case_log)
return :not_started if qs.all? { |question| case_log[question.id].blank? }
return :not_started if qs.all? { |question| case_log[question.id].blank? || question.read_only? }
return :completed if qs.all? { |question| question.completed?(case_log) }
:in_progress
@ -66,6 +66,6 @@ class Form::Subsection
end
def displayed_to_user?(case_log, question)
question.page.routed_to?(case_log) && question.enabled?(case_log) && !question.read_only?
question.page.routed_to?(case_log) && question.enabled?(case_log)
end
end

2
app/models/validations/financial_validations.rb

@ -34,7 +34,7 @@ module Validations::FinancialValidations
def validate_tshortfall(record)
is_yes = record.hbrentshortfall == "Yes"
hb_donotknow = record.hb == "Don't know"
hb_donotknow = record.hb == "Dont know"
hb_none = record.hb == "None"
hb_uc_no_hb = record.hb == "Universal Credit (without housing element)"

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

@ -3,7 +3,7 @@
<%= 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) %> <br/>
<%= get_answer_label(question, @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 %>

191
config/forms/2021_2022.json

@ -1843,28 +1843,29 @@
"description": "",
"questions": {
"net_income_known": {
"check_answer_label": "Income known",
"header": "Do you know the household’s combined income after tax?",
"check_answer_label": "How often household receives income",
"header": "How often does the household receive income?",
"guidance_partial": "what_counts_as_income",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "Yes – the household has a weekly income",
"1": "Yes – the household has a monthly income",
"2": "Yes – the household has a yearly income",
"0": "Weekly",
"1": "Monthly",
"2": "Annually",
"divider_a": true,
"3": "Tenant prefers not to say"
"3": "Don’t know",
"4": "Tenant prefers not to say"
}
}
}
},
"weekly_net_income": {
"depends_on": [{ "net_income_known": "Yes – the household has a weekly income" }],
"depends_on": [{ "net_income_known": "Weekly" }],
"header": "",
"description": "",
"questions": {
"earnings": {
"check_answer_label": "Income",
"check_answer_label": "Total household income",
"header": "How much income does the household have in total every week?",
"hint_text": "",
"type": "numeric",
@ -1872,7 +1873,7 @@
"step": "1",
"width": 5,
"prefix": "£",
"suffix": "every week"
"suffix": " every week"
}
},
"soft_validations": {
@ -1886,12 +1887,12 @@
}
},
"monthly_net_income": {
"depends_on": [{ "net_income_known": "Yes – the household has a monthly income" }],
"depends_on": [{ "net_income_known": "Monthly" }],
"header": "",
"description": "",
"questions": {
"earnings": {
"check_answer_label": "Income",
"check_answer_label": "Total household income",
"header": "How much income does the household have in total every month?",
"hint_text": "",
"type": "numeric",
@ -1899,7 +1900,7 @@
"step": "1",
"width": 5,
"prefix": "£",
"suffix": "every month"
"suffix": " every month"
}
},
"soft_validations": {
@ -1913,12 +1914,12 @@
}
},
"yearly_net_income": {
"depends_on": [{ "net_income_known": "Yes – the household has a yearly income" }],
"depends_on": [{ "net_income_known": "Annually" }],
"header": "",
"description": "",
"questions": {
"earnings": {
"check_answer_label": "Income",
"check_answer_label": "Total household income",
"header": "How much income does the household have in total every year?",
"hint_text": "",
"type": "numeric",
@ -1926,7 +1927,7 @@
"step": "1",
"width": 5,
"prefix": "£",
"suffix": "every year"
"suffix": " every year"
}
},
"soft_validations": {
@ -1944,7 +1945,7 @@
"description": "",
"questions": {
"hb": {
"check_answer_label": "Universal Credit & Housing Benefit",
"check_answer_label": "Housing-related benefits received",
"header": "Is the household likely to be receiving any of these housing-related benefits?",
"hint_text": "",
"type": "radio",
@ -1955,7 +1956,7 @@
"3": "Universal Credit (without housing element)",
"4": "None",
"divider": true,
"5": "Don't know",
"5": "Dont know",
"6": "Tenant prefers not to say"
}
}
@ -1966,7 +1967,7 @@
"description": "",
"questions": {
"benefits": {
"check_answer_label": "Benefits as a proportion of income",
"check_answer_label": "Household income from Universal credit, state pension or benefits",
"header": "How much of the household's income is from Universal Credit, state pensions or benefits?",
"hint_text": "This excludes child and housing benefit, council tax support and tax credits.",
"type": "radio",
@ -1985,7 +1986,7 @@
"description": "",
"questions": {
"household_charge": {
"check_answer_label": "Does the household pay rent or other charges for the accommodation?",
"check_answer_label": "Does the household pay rent or charges?",
"header": "Does the household pay rent or other charges for the accommodation?",
"hint_text": "",
"type": "radio",
@ -2002,20 +2003,20 @@
"description": "",
"questions": {
"period": {
"check_answer_label": "Rent Period",
"check_answer_label": "Frequency of household rent and charges",
"header": "How often does the household pay rent and other charges?",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "Weekly for 52 weeks",
"1": "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"
"0": "Every 2 weeks",
"1": "Every 4 weeks",
"2": "Every calendar month",
"3": "Weekly for 50 weeks",
"4": "Weekly for 49 weeks",
"5": "Weekly for 48 weeks",
"6": "Weekly for 47 weeks",
"7": "Weekly for 46 weeks",
"8": "Weekly for 52 weeks"
}
}
},
@ -2030,7 +2031,7 @@
"description": "",
"questions": {
"is_carehome": {
"check_answer_label": "Is this accommodation a care home?",
"check_answer_label": "Care home accommodation",
"header": "Is this accommodation a care home?",
"hint_text": "",
"type": "radio",
@ -2043,13 +2044,13 @@
}
},
"chcharge": {
"check_answer_label": "How much does the household pay every week?",
"check_answer_label": "Care home charges",
"header": "How much does the household pay every week?",
"hint_text": "",
"type": "numeric",
"width": 5,
"prefix": "£",
"suffix": "every week"
"suffix": " every week"
}
},
"depends_on" : [{
@ -2108,7 +2109,7 @@
"description": "",
"questions": {
"is_carehome": {
"check_answer_label": "Is this accommodation a care home?",
"check_answer_label": "Care home accommodation",
"header": "Is this accommodation a care home?",
"hint_text": "",
"type": "radio",
@ -2121,13 +2122,13 @@
}
},
"chcharge": {
"check_answer_label": "How much does the household pay every 2 weeks?",
"check_answer_label": "Care home charges",
"header": "How much does the household pay every 2 weeks?",
"hint_text": "",
"type": "numeric",
"width": 5,
"prefix": "£",
"suffix": "every 2 weeks"
"suffix": " every 2 weeks"
}
},
"depends_on" : [{
@ -2145,7 +2146,7 @@
"description": "",
"questions": {
"is_carehome": {
"check_answer_label": "Is this accommodation a care home?",
"check_answer_label": "Care home accommodation",
"header": "Is this accommodation a care home?",
"hint_text": "",
"type": "radio",
@ -2158,13 +2159,13 @@
}
},
"chcharge": {
"check_answer_label": "How much does the household pay every 4 weeks?",
"check_answer_label": "Care home charges",
"header": "How much does the household pay every 4 weeks?",
"hint_text": "",
"type": "numeric",
"width": 5,
"prefix": "£",
"suffix": "every 4 weeks"
"suffix": " every 4 weeks"
}
},
"depends_on" : [{
@ -2182,7 +2183,7 @@
"description": "",
"questions": {
"is_carehome": {
"check_answer_label": "Is this accommodation a care home?",
"check_answer_label": "Care home accommodation",
"header": "Is this accommodation a care home?",
"hint_text": "",
"type": "radio",
@ -2195,13 +2196,13 @@
}
},
"chcharge": {
"check_answer_label": "How much does the household pay every month?",
"check_answer_label": "Care home charges",
"header": "How much does the household pay every month?",
"hint_text": "",
"type": "numeric",
"width": 5,
"prefix": "£",
"suffix": "month"
"suffix": " every month"
}
},
"depends_on" : [{
@ -2227,9 +2228,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every week",
"suffix": " every week",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"scharge": {
"check_answer_label": "Service Charge",
@ -2240,9 +2242,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every week",
"suffix": " every week",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"pscharge": {
"check_answer_label": "Personal Service Charge",
@ -2253,9 +2256,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every week",
"suffix": " every week",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"supcharg": {
"check_answer_label": "Support Charge",
@ -2266,12 +2270,13 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every week",
"suffix": " every week",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"tcharge": {
"check_answer_label": "Total Charge",
"check_answer_label": "Household rent and charges",
"header": "Total charge",
"hint_text": "This is the total for rent and all charges.",
"type": "numeric",
@ -2279,7 +2284,7 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every week",
"suffix": " every week",
"readonly": true,
"requires_js": true
}
@ -2397,9 +2402,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 2 weeks",
"suffix": " every 2 weeks",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"scharge": {
"check_answer_label": "Service Charge",
@ -2410,9 +2416,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 2 weeks",
"suffix": " every 2 weeks",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"pscharge": {
"check_answer_label": "Personal Service Charge",
@ -2423,9 +2430,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 2 weeks",
"suffix": " every 2 weeks",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"supcharg": {
"check_answer_label": "Support Charge",
@ -2436,12 +2444,13 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 2 weeks",
"suffix": " every 2 weeks",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"tcharge": {
"check_answer_label": "Total Charge",
"check_answer_label": "Household rent and charges",
"header": "Total charge",
"hint_text": "This is the total for rent and all charges.",
"type": "numeric",
@ -2449,7 +2458,7 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 2 weeks",
"suffix": " every 2 weeks",
"readonly": true,
"requires_js": true
}
@ -2486,9 +2495,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 4 weeks",
"suffix": " every 4 weeks",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"scharge": {
"check_answer_label": "Service Charge",
@ -2499,9 +2509,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 4 weeks",
"suffix": " every 4 weeks",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"pscharge": {
"check_answer_label": "Personal Service Charge",
@ -2512,9 +2523,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 4 weeks",
"suffix": " every 4 weeks",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"supcharg": {
"check_answer_label": "Support Charge",
@ -2525,12 +2537,13 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 4 weeks",
"suffix": " every 4 weeks",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"tcharge": {
"check_answer_label": "Total Charge",
"check_answer_label": "Household rent and charges",
"header": "Total charge",
"hint_text": "This is the total for rent and all charges.",
"type": "numeric",
@ -2538,7 +2551,7 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every 4 weeks",
"suffix": " every 4 weeks",
"readonly": true,
"requires_js": true
}
@ -2575,9 +2588,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every month",
"suffix": " every month",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"scharge": {
"check_answer_label": "Service Charge",
@ -2588,9 +2602,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every month",
"suffix": " every month",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"pscharge": {
"check_answer_label": "Personal Service Charge",
@ -2601,9 +2616,10 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every month",
"suffix": " every month",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"supcharg": {
"check_answer_label": "Support Charge",
@ -2614,12 +2630,13 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every month",
"suffix": " every month",
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
"result-field": "tcharge",
"hidden_in_check_answers": true
},
"tcharge": {
"check_answer_label": "Total Charge",
"check_answer_label": "Household rent and charges",
"header": "Total charge",
"hint_text": "This is the total for rent and all charges.",
"type": "numeric",
@ -2627,7 +2644,7 @@
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every month",
"suffix": " every month",
"readonly": true,
"requires_js": true
}
@ -2657,8 +2674,8 @@
"description": "",
"questions": {
"hbrentshortfall": {
"check_answer_label": "After housing benefit and/or housing element of UC payment is received, will there be an outstanding amount for basic rent and/or benefit eligible charges?",
"header": "After housing benefit and/or housing element of UC payment is received, will there be an outstanding amount for basic rent and/or benefit eligible charges?",
"check_answer_label": "Outstanding amount for basic rent and charges",
"header": "After the household has received any housing-related benefits, will there be an outstanding amount for basic rent and eligible charges?",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -2674,15 +2691,15 @@
"description": "",
"questions": {
"tshortfall": {
"check_answer_label": "Outstanding amount",
"header": "What do you expect the amount to be?",
"hint_text": "Give an estimated amount if you don't know the exact figure.",
"check_answer_label": "Estimated outstanding amount",
"header": "What do you expect the outstanding amount to be?",
"hint_text": "Give an estimated amount if you dont know the exact figure.",
"type": "numeric",
"min": 0,
"step": 1,
"width": 5,
"prefix": "£",
"suffix": "every month"
"suffix": " every month"
}
},
"depends_on": [{"has_benefits": "Yes",

2
config/locales/en.yml

@ -58,7 +58,7 @@ en:
financial:
tshortfall:
outstanding_amount_not_required: "You must not answer the outstanding amount question if you don't have outstanding rent or charges."
outstanding_amount_not_required: "You must not answer the outstanding amount question if you dont have outstanding rent or charges."
hbrentshortfall:
outstanding_no_benefits: "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"
benefits:

2
spec/factories/case_log.rb

@ -112,7 +112,7 @@ FactoryBot.define do
discarded_at { nil }
tenancyother { nil }
override_net_income_validation { nil }
net_income_known { "Yes – the household has a weekly income" }
net_income_known { "Weekly" }
gdpr_acceptance { "Yes" }
gdpr_declined { "No" }
property_owner_organisation { "Test" }

2
spec/fixtures/complete_case_log.json vendored

@ -74,7 +74,7 @@
"mrcyear": 2020,
"offered": 2,
"wchair": "Yes",
"net_income_known": "Yes – the household has a weekly income",
"net_income_known": "Weekly",
"earnings": 150,
"benefits": "Some",
"hb": "Universal Credit with housing element (excluding housing benefit)",

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

@ -451,7 +451,7 @@
}
}
},
"rent": {
"rent_and_charges": {
"label": "Rent",
"pages": {
"rent": {
@ -648,7 +648,7 @@
"tenancy_information": "completed",
"property_information": "completed",
"income_and_benefits": "completed",
"rent": "completed",
"rent_and_charges": "completed",
"local_authority": "completed"
}],
"pages": {

8
spec/models/case_log_spec.rb

@ -123,7 +123,7 @@ RSpec.describe Form, type: :model do
end
context "reason for leaving last settled home validation" do
it "Reason for leaving must be don't know if reason for leaving settled home (Q9a) is don't know." do
it "Reason for leaving must be don’t know if reason for leaving settled home (Q9a) is don’t know." do
expect {
CaseLog.create!(reason: "Don’t know",
underoccupation_benefitcap: "Yes - benefit cap",
@ -1118,11 +1118,11 @@ RSpec.describe Form, type: :model do
context "net_income" do
it "infers the income frequency" do
case_log.update!(net_income_known: "Yes – the household has a weekly income")
case_log.update!(net_income_known: "Weekly")
expect(case_log.reload.incfreq).to eq("Weekly")
case_log.update!(net_income_known: "Yes – the household has a monthly income")
case_log.update!(net_income_known: "Monthly")
expect(case_log.reload.incfreq).to eq("Monthly")
case_log.update!(net_income_known: "Yes – the household has a yearly income")
case_log.update!(net_income_known: "Annually")
expect(case_log.reload.incfreq).to eq("Yearly")
end
end

2
spec/models/form/question_spec.rb

@ -74,7 +74,7 @@ RSpec.describe Form::Question, type: :model do
end
context "when the question is read only" do
let(:subsection_id) { "rent" }
let(:subsection_id) { "rent_and_charges" }
let(:page_id) { "rent" }
let(:question_id) { "tcharge" }

5
spec/requests/case_log_controller_spec.rb

@ -278,6 +278,11 @@ RSpec.describe CaseLogsController, type: :request do
get "/logs/#{id}/property-information/check-answers"
expect(CGI.unescape_html(response.body)).to include("Not known")
end
it "shows `you haven't answered this question` if the question wasn't answered" do
get "/logs/#{id}/income-and-benefits/check-answers"
expect(CGI.unescape_html(response.body)).to include("You didn’t answer this question")
end
end
end

Loading…
Cancel
Save