Browse Source

Merge remote-tracking branch 'origin/main' into cldc-913-i18n-validation-messages

pull/218/head
Stéphane Meny 4 years ago
parent
commit
1790632c85
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 8
      README.md
  2. 12
      app/helpers/tasklist_helper.rb
  3. 13
      app/models/case_log.rb
  4. 26
      app/models/constants/case_log.rb
  5. 6
      app/models/form.rb
  6. 6
      app/models/form/page.rb
  7. 6
      app/models/form/subsection.rb
  8. 14
      app/models/validations/financial_validations.rb
  9. 11
      app/views/case_logs/_tasklist.html.erb
  10. 779
      config/forms/2021_2022.json
  11. 7
      db/migrate/20220110115720_add_has_benefits_field.rb
  12. 7
      db/migrate/20220110161957_add_nocharge_field.rb
  13. 8
      db/migrate/20220111140400_add_care_home_charge_fields.rb
  14. 7
      db/migrate/20220112151048_add_household_charge_field.rb
  15. 7
      db/schema.rb
  16. 2
      docs/api/DLUHC-CORE-Data.v1.json
  17. 6
      spec/factories/case_log.rb
  18. 2
      spec/features/form/helpers.rb
  19. 18
      spec/features/form/validations_spec.rb
  20. 10
      spec/fixtures/complete_case_log.json
  21. 24
      spec/fixtures/forms/2021_2022.json
  22. 14
      spec/fixtures/forms/2022_2023.json
  23. 2
      spec/fixtures/forms/test_validator.json
  24. 4
      spec/helpers/tasklist_helper_spec.rb
  25. 26
      spec/models/case_log_spec.rb
  26. 2
      spec/models/form/question_spec.rb
  27. 18
      spec/models/form_spec.rb
  28. 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

12
app/helpers/tasklist_helper.rb

@ -35,11 +35,11 @@ module TasklistHelper
end end
def subsection_link(subsection, case_log) def subsection_link(subsection, case_log)
next_page_path = if subsection.status(case_log) != :cannot_start_yet if subsection.status(case_log) != :cannot_start_yet
first_page_or_check_answers(subsection, case_log) next_page_path = first_page_or_check_answers(subsection, case_log).to_s
else govuk_link_to(subsection.label, next_page_path.dasherize, aria: { describedby: subsection.id.dasherize })
"#" else
end subsection.label
govuk_link_to(subsection.label, next_page_path.to_s.dasherize, class: "task-name") end
end end
end end

13
app/models/case_log.rb

@ -135,6 +135,9 @@ class CaseLog < ApplicationRecord
enum postcode_known: POLAR, _suffix: true enum postcode_known: POLAR, _suffix: true
enum la_known: POLAR, _suffix: true enum la_known: POLAR, _suffix: true
enum net_income_known: NET_INCOME_KNOWN, _suffix: true enum net_income_known: NET_INCOME_KNOWN, _suffix: true
enum household_charge: POLAR, _suffix: true
enum is_carehome: POLAR, _suffix: true
enum nocharge: POLAR, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing].freeze OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing].freeze
@ -239,12 +242,16 @@ private
case net_income_known case net_income_known
when "Yes – the household has a weekly income" when "Yes – the household has a weekly income"
self.incfreq = "Weekly" self.incfreq = "Weekly"
self.incref = nil
when "Yes – the household has a monthly income" when "Yes – the household has a monthly income"
self.incfreq = "Monthly" self.incfreq = "Monthly"
self.incref = nil
when "Yes – the household has a yearly income" when "Yes – the household has a yearly income"
self.incfreq = "Yearly" self.incfreq = "Yearly"
self.incref = nil
when "Tenant prefers not to say" when "Tenant prefers not to say"
self.incref = 1 self.incref = 1
self.incfreq = nil
end end
self.hhmemb = other_hhmemb + 1 if other_hhmemb.present? self.hhmemb = other_hhmemb + 1 if other_hhmemb.present?
self.renttype = RENT_TYPE_MAPPING[rent_type] self.renttype = RENT_TYPE_MAPPING[rent_type]
@ -253,6 +260,8 @@ private
self.totelder = get_totelder self.totelder = get_totelder
self.totadult = get_totadult self.totadult = get_totadult
self.tcharge = brent.to_i + scharge.to_i + pscharge.to_i + supcharg.to_i self.tcharge = brent.to_i + scharge.to_i + pscharge.to_i + supcharg.to_i
self.has_benefits = get_has_benefits
self.nocharge = household_charge == "Yes" ? "No" : "Yes"
end end
def process_postcode_changes! def process_postcode_changes!
@ -303,6 +312,10 @@ private
end end
end end
def get_has_benefits
return "Yes" if HAS_BENEFITS_OPTIONS.include?(hb)
end
def all_fields_completed? def all_fields_completed?
mandatory_fields.none? { |field| public_send(field).nil? if respond_to?(field) } mandatory_fields.none? { |field| public_send(field).nil? if respond_to?(field) }
end end

26
app/models/constants/case_log.rb

@ -206,15 +206,14 @@ module Constants::CaseLog
PERIOD = { PERIOD = {
"Weekly for 52 weeks" => 1, "Weekly for 52 weeks" => 1,
"Fortnightly" => 2, "Every 2 weeks" => 2,
"Four-weekly" => 3, "Every 4 weeks" => 3,
"Calendar monthly" => 4, "Every calendar month" => 4,
"Weekly for 50 weeks" => 5, "Weekly for 50 weeks" => 5,
"Weekly for 49 weeks" => 6, "Weekly for 49 weeks" => 6,
"Weekly for 48 weeks" => 7, "Weekly for 48 weeks" => 7,
"Weekly for 47 weeks" => 8, "Weekly for 47 weeks" => 8,
"Weekly for 46 weeks" => 9, "Weekly for 46 weeks" => 9,
"Weekly for 53 weeks" => 10,
}.freeze }.freeze
LATIME = { LATIME = {
@ -229,13 +228,13 @@ module Constants::CaseLog
}.freeze }.freeze
HOUSING_BENEFIT = { HOUSING_BENEFIT = {
"Housing Benefit, but not Universal Credit" => 1, "Housing benefit" => 1,
"Universal Credit with housing element, but not Housing Benefit" => 6, "Universal Credit with housing element (excluding housing benefit)" => 6,
"Universal Credit without housing element and no Housing Benefit" => 7, "Universal Credit (without housing element)" => 7,
"Universal Credit and Housing Benefit" => 8, "Housing benefit and Universal Credit (without housing element)" => 8,
"Not Housing Benefit or Universal Credit" => 9, "None" => 9,
"Dont know" => 3, "Don't know" => 3,
"Prefer not to say" => 100, "Tenant prefers not to say" => 100,
}.freeze }.freeze
REASON = { REASON = {
@ -1077,4 +1076,9 @@ module Constants::CaseLog
"Yes – the household has a yearly income" => 2, "Yes – the household has a yearly income" => 2,
"Tenant prefers not to say" => 3, "Tenant prefers not to say" => 3,
}.freeze }.freeze
HAS_BENEFITS_OPTIONS = ["Housing benefit",
"Universal Credit with housing element (excluding housing benefit)",
"Universal Credit (without housing element)",
"Housing benefit and Universal Credit (without housing element)"].freeze
end end

6
app/models/form.rb

@ -59,11 +59,13 @@ class Form
end end
def invalidated_questions(case_log) def invalidated_questions(case_log)
(invalidated_page_questions(case_log) + invalidated_conditional_questions(case_log)).uniq invalidated_page_questions(case_log) + invalidated_conditional_questions(case_log)
end end
def invalidated_page_questions(case_log) def invalidated_page_questions(case_log)
invalidated_pages(case_log).flat_map(&:questions) || [] 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) || []
invalidated_pages(case_log).flat_map(&:questions).reject { |q| enabled_question_ids.include?(q.id) } || []
end end
def invalidated_conditional_questions(case_log) def invalidated_conditional_questions(case_log)

6
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|
!case_log[question].nil? && case_log[question] == value conditions_set.all? do |question, value|
value.nil? ? case_log[question] == value : !case_log[question].nil? && case_log[question] == value
end
end end
end end
end end

6
app/models/form/subsection.rb

@ -18,8 +18,10 @@ 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|
form.get_subsection(subsection_id).status(case_log) == dependent_status.to_sym conditions_set.all? do |subsection_id, dependent_status|
form.get_subsection(subsection_id).status(case_log) == dependent_status.to_sym
end
end end
end end

14
app/models/validations/financial_validations.rb

@ -38,15 +38,15 @@ module Validations::FinancialValidations
def validate_hbrentshortfall(record) def validate_hbrentshortfall(record)
is_present = record.hbrentshortfall.present? is_present = record.hbrentshortfall.present?
is_yes = record.hbrentshortfall == "Yes" is_yes = record.hbrentshortfall == "Yes"
hb_donotknow = record.hb == "Dont know" hb_donotknow = record.hb == "Don't know"
hb_no_hb_or_uc = record.hb == "Not Housing Benefit or Universal Credit" hb_none = record.hb == "None"
hb_uc_no_hb = record.hb == "Universal Credit without housing element and no Housing Benefit" hb_uc_no_hb = record.hb == "Universal Credit (without housing element)"
hb_no_uc = record.hb == "Housing Benefit, but not Universal Credit" hb_no_uc = record.hb == "Housing benefit"
hb_uc_no_he_hb = record.hb == "Universal Credit with housing element, but not Housing Benefit" hb_uc_no_he_hb = record.hb == "Universal Credit with housing element (excluding housing benefit)"
hb_and_uc = record.hb == "Universal Credit and Housing Benefit" hb_and_uc = record.hb == "Housing benefit and Universal Credit (without housing element)"
conditions = [ conditions = [
{ condition: is_yes && (hb_donotknow || hb_no_hb_or_uc || hb_uc_no_hb), error: I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") }, { condition: is_yes && (hb_donotknow || hb_none || hb_uc_no_hb), error: I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") },
{ condition: (hb_no_uc || hb_uc_no_he_hb || hb_and_uc) && !is_present, error: I18n.t("validations.financial.hbrentshortfall.amount_required") }, { condition: (hb_no_uc || hb_uc_no_he_hb || hb_and_uc) && !is_present, error: I18n.t("validations.financial.hbrentshortfall.amount_required") },
] ]

11
app/views/case_logs/_tasklist.html.erb

@ -8,10 +8,13 @@
</h2> </h2>
<ul class="app-task-list__items"> <ul class="app-task-list__items">
<% section.subsections.map do |subsection| %> <% section.subsections.map do |subsection| %>
<li class="app-task-list__item" id=<%= subsection.id %>> <% subsection_status = subsection.status(@case_log) %>
<% subsection_status = subsection.status(@case_log) %> <li class="app-task-list__item">
<%= subsection_link(subsection, @case_log) %> <span class="app-task-list__task-name">
<strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>"> <%= subsection_link(subsection, @case_log) %>
</span>
<strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>"
id=<%= subsection.id.dasherize %>>
<%= TasklistHelper::STATUSES[subsection_status] %> <%= TasklistHelper::STATUSES[subsection_status] %>
</strong> </strong>
</li> </li>

779
config/forms/2021_2022.json

File diff suppressed because it is too large Load Diff

7
db/migrate/20220110115720_add_has_benefits_field.rb

@ -0,0 +1,7 @@
class AddHasBenefitsField < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :has_benefits, :string
end
end
end

7
db/migrate/20220110161957_add_nocharge_field.rb

@ -0,0 +1,7 @@
class AddNochargeField < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :nocharge, :integer
end
end
end

8
db/migrate/20220111140400_add_care_home_charge_fields.rb

@ -0,0 +1,8 @@
class AddCareHomeChargeFields < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :is_carehome, :integer
t.column :chcharge, :decimal
end
end
end

7
db/migrate/20220112151048_add_household_charge_field.rb

@ -0,0 +1,7 @@
class AddHouseholdChargeField < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :household_charge, :integer
end
end
end

7
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_01_07_103143) do ActiveRecord::Schema.define(version: 2022_01_12_151048) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -178,6 +178,11 @@ ActiveRecord::Schema.define(version: 2022_01_07_103143) do
t.integer "totelder" t.integer "totelder"
t.integer "totadult" t.integer "totadult"
t.integer "net_income_known" t.integer "net_income_known"
t.string "has_benefits"
t.integer "nocharge"
t.integer "is_carehome"
t.decimal "chcharge"
t.integer "household_charge"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
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"

2
docs/api/DLUHC-CORE-Data.v1.json

@ -323,7 +323,7 @@
"earnings": 1000, "earnings": 1000,
"incfreq": "Monthly", "incfreq": "Monthly",
"benefits": "Some", "benefits": "Some",
"hb": "Universal Credit with housing element, but not Housing Benefit", "hb": "Universal Credit with housing element (excluding housing benefit)",
"period": "Weekly", "period": "Weekly",
"brent": 200, "brent": 200,
"scharge": 50, "scharge": 50,

6
spec/factories/case_log.rb

@ -72,7 +72,7 @@ FactoryBot.define do
wchair { "Yes" } wchair { "Yes" }
earnings { 68 } earnings { 68 }
benefits { "Some" } benefits { "Some" }
period { "Fortnightly" } period { "Every 2 weeks" }
brent { 200 } brent { 200 }
scharge { 50 } scharge { 50 }
pscharge { 40 } pscharge { 40 }
@ -148,6 +148,10 @@ FactoryBot.define do
armedforces { 1 } armedforces { 1 }
builtype { 1 } builtype { 1 }
unitletas { 2 } unitletas { 2 }
household_charge { "Yes" }
has_benefits { "Yes" }
is_carehome { "No" }
chcharge { 7 }
end end
created_at { Time.zone.now } created_at { Time.zone.now }
updated_at { Time.zone.now } updated_at { Time.zone.now }

2
spec/features/form/helpers.rb

@ -12,7 +12,7 @@ module Helpers
click_button("Save and continue") click_button("Save and continue")
choose("case-log-benefits-all-field") choose("case-log-benefits-all-field")
click_button("Save and continue") click_button("Save and continue")
choose("case-log-hb-prefer-not-to-say-field") choose("case-log-hb-tenant-prefers-not-to-say-field")
click_button("Save and continue") click_button("Save and continue")
end end

18
spec/features/form/validations_spec.rb

@ -102,24 +102,6 @@ RSpec.describe "validations" do
end end
end end
describe "Compound validations" do
context "when you select two compatible answers, that become incompatible if the first answer changes", js: true do
it "clears the second answer on change of the first" do
case_log.update!(other_hhmemb: 1, relat2: "Partner", age2: 32, sex2: "Female", ecstat2: "Not seeking work")
visit("/logs/#{id}/conditional-question")
choose("case-log-preg-occ-yes-field", allow_label_click: true)
click_button("Save and continue")
choose("case-log-cbl-yes-field", allow_label_click: true)
click_button("Save and continue")
page.go_back
click_link("Back")
choose("case-log-preg-occ-no-field", allow_label_click: true)
click_button("Save and continue")
expect(case_log.reload.cbl).to be_nil
end
end
end
describe "Soft Validation" do describe "Soft Validation" do
context "given a weekly net income that is above the expected amount for the given economic status but below the hard max" do context "given a weekly net income that is above the expected amount for the given economic status but below the hard max" do
let(:case_log) do let(:case_log) do

10
spec/fixtures/complete_case_log.json vendored

@ -77,8 +77,8 @@
"net_income_known": "Yes – the household has a weekly income", "net_income_known": "Yes – the household has a weekly income",
"earnings": 150, "earnings": 150,
"benefits": "Some", "benefits": "Some",
"hb": "Universal Credit with housing element, but not Housing Benefit", "hb": "Universal Credit with housing element (excluding housing benefit)",
"period": "Fortnightly", "period": "Every 2 weeks",
"brent": 200, "brent": 200,
"scharge": 50, "scharge": 50,
"pscharge": 40, "pscharge": 40,
@ -144,6 +144,10 @@
"property_wheelchair_accessible": "Yes", "property_wheelchair_accessible": "Yes",
"void_or_renewal_date": "05/05/2020", "void_or_renewal_date": "05/05/2020",
"tenant_same_property_renewal": "Yes", "tenant_same_property_renewal": "Yes",
"new_build_handover_date": "01/01/2019" "new_build_handover_date": "01/01/2019",
"has_benefits": "Yes",
"household_charge": "Yes",
"is_carehome": "Yes",
"chcharge": "6"
} }
} }

24
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,11 +321,11 @@
} }
} }
}, },
"depends_on": { "preg_occ": "Yes" } "depends_on": [{ "preg_occ": "Yes" }, { "wchair" : "Yes" }]
}, },
"conditional_question_no_page": { "conditional_question_no_page": {
"questions": { "questions": {
"conditional_question_no_question": { "cbl": {
"check_answer_label": "Has the condition not been met?", "check_answer_label": "Has the condition not been met?",
"header": "Has the next condition not been met?", "header": "Has the next condition not been met?",
"type": "radio", "type": "radio",
@ -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" }]
} }
} }
} }
@ -417,11 +417,11 @@
"header": "Is the tenant likely to be in receipt of any of these housing-related benefits?", "header": "Is the tenant likely to be in receipt of any of these housing-related benefits?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Housing Benefit, but not Universal Credit", "0": "Housing benefit",
"1": "Prefer not to say" "1": "Tenant prefers not to say"
}, },
"conditional_for": { "conditional_for": {
"conditional_question": ["Housing Benefit, but not Universal Credit"] "conditional_question": ["Housing benefit"]
} }
}, },
"conditional_question": { "conditional_question": {
@ -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",
@ -462,7 +462,7 @@
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Weekly for 52 weeks", "0": "Weekly for 52 weeks",
"1": "Fortnightly" "1": "Every 2 weeks"
} }
}, },
"brent": { "brent": {
@ -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": "",

4
spec/helpers/tasklist_helper_spec.rb

@ -67,8 +67,8 @@ RSpec.describe TasklistHelper do
allow(subsection).to receive(:status).with(case_log).and_return(:cannot_start_yet) allow(subsection).to receive(:status).with(case_log).and_return(:cannot_start_yet)
end end
it "returns a # link" do it "returns the label instead of a link" do
expect(subsection_link(subsection, case_log)).to match(/#/) expect(subsection_link(subsection, case_log)).to match(subsection.label)
end end
end end
end end

26
spec/models/case_log_spec.rb

@ -1038,6 +1038,8 @@ RSpec.describe Form, type: :model do
other_hhmemb: 6, other_hhmemb: 6,
rent_type: "London living rent", rent_type: "London living rent",
needstype: "General needs", needstype: "General needs",
hb: "Housing benefit",
hbrentshortfall: "No",
}) })
end end
@ -1218,5 +1220,29 @@ RSpec.describe Form, type: :model do
expect(record_from_db["totadult"]).to eq(3) expect(record_from_db["totadult"]).to eq(3)
end end
end end
it "correctly derives and saves has_benefits" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select has_benefits from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["has_benefits"]).to eq("Yes")
end
end
describe "resetting invalidated fields" do
context "when a question that has already been answered, no longer has met dependencies" do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: "Yes", preg_occ: "No") }
it "clears the answer" do
expect { case_log.update!(preg_occ: nil) }.to change { case_log.cbl }.from("Yes").to(nil)
end
end
context "two pages with the same question key, only one's dependency is met" do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: "Yes", preg_occ: "No") }
it "does not clear the answer" do
expect(case_log.cbl).to eq("Yes")
end
end
end end
end end

2
spec/models/form/question_spec.rb

@ -145,7 +145,7 @@ RSpec.describe Form::Question, type: :model do
end end
it "knows whether it is enabled or not for met conditions" do it "knows whether it is enabled or not for met conditions" do
case_log.hb = "Housing Benefit, but not Universal Credit" case_log.hb = "Housing benefit"
expect(subject.enabled?(case_log)).to be true expect(subject.enabled?(case_log)).to be true
end end
end end

18
spec/models/form_spec.rb

@ -31,4 +31,22 @@ RSpec.describe Form, type: :model do
expect(form.next_page_redirect_path(previous_conditional_page, case_log)).to eq("case_log_conditional_question_no_page_path") expect(form.next_page_redirect_path(previous_conditional_page, case_log)).to eq("case_log_conditional_question_no_page_path")
end end
end end
describe "invalidated_page_questions" do
context "dependencies not met" do
let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question dependent_question declaration] }
it "returns an array of question keys whose pages conditions are not met" do
expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid)
end
end
context "two pages with the same question, only one has dependencies met" do
let(:expected_invalid) { %w[la_known conditional_question_no_second_question dependent_question declaration] }
it "returns an array of question keys whose pages conditions are not met" do
case_log["preg_occ"] = "No"
expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid)
end
end
end
end end

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