From b47c7a5d91b44982935cb9a13c9a02647c22ec9f Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:33:55 +0000 Subject: [PATCH] Cldc 810 outside of the uk addresses (#323) * Move previous_la into conditional question for la_known, add a hing and reset la if la_known is not Yes" * update location json * Update previous la known separately --- app/models/case_log.rb | 8 +++---- config/forms/2021_2022.json | 44 ++++++++++++++---------------------- spec/models/case_log_spec.rb | 17 ++++++++++++-- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 21d60a872..43da733c9 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -309,15 +309,15 @@ private end def reset_location_fields! - reset_location(is_la_inferred, "la", "is_la_inferred", "property_postcode", "postcode", "postcod2") + reset_location(is_la_inferred, "la", "is_la_inferred", "property_postcode", "postcode", "postcod2", la_known) end def reset_previous_location_fields! - reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "previous_postcode", "ppostc1", "ppostc2") + reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "previous_postcode", "ppostc1", "ppostc2", previous_la_known) end - def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key) - if is_inferred + def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key, is_la_known) + if is_inferred || is_la_known != "Yes" self[la_key] = nil end self[is_inferred_key] = false diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 1084da3ef..f218a8023 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -236,19 +236,11 @@ "0": { "value": "No" } + }, + "conditional_for": { + "la": ["Yes"] } - } - }, - "depends_on": [ - { - "is_la_inferred": false - } - ] - }, - "select_local_authority": { - "header": "", - "description": "", - "questions": { + }, "la": { "check_answer_label": "Local Authority", "header": "Select a local authority", @@ -577,7 +569,6 @@ }, "depends_on": [ { - "la_known": "Yes", "is_la_inferred": false } ] @@ -2487,7 +2478,7 @@ } } }, - "previous_la_known": { + "previous_la": { "header": "", "description": "", "questions": { @@ -2496,22 +2487,19 @@ "header": "Do you know the local authority of the household’s last settled accommodation?", "hint_text": "This is also known as the household’s ’last settled home’.", "type": "radio", + "hidden_in_check_answers": true, "answer_options": { "1": { "value": "Yes" }, "0": { "value": "No" } + }, + "conditional_for": { + "prevloc": ["Yes"] } - } - }, - "depends_on": [{ "is_previous_la_inferred": false }] - }, - "previous_la": { - "header": "", - "description": "", - "questions": { + }, "prevloc": { "check_answer_label": "Location of household’s last settled accommodation", - "header": "Which local authority area did the household live in immediately before this letting?", - "hint_text": "Includes temporary accommodation.", + "header": "Select a local authority", + "hint_text": "Select ‘Northern Ireland’, ‘Scotland’, ‘Wales’ or ‘Outside the UK’ if the household’s last settled home was outside England.", "type": "select", "answer_options": { "": "Select an option", @@ -2898,12 +2886,14 @@ "S92000003": "Scotland", "W92000004": "Wales", "9300000XX": "Outside UK" + }, + "inferred_check_answers_value": { + "condition": { "previous_la_known": "No" }, + "value": "Not known" } } }, - "depends_on": [ - { "previous_la_known": "Yes", "is_previous_la_inferred": false } - ] + "depends_on": [{ "is_previous_la_inferred": false }] }, "reasonable_preference": { "header": "", diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 89875c2b4..f76bb8da8 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -339,7 +339,7 @@ RSpec.describe CaseLog do it "changes the LA if property postcode changes from not known to known and provided" do address_case_log.update!({ postcode_known: "No" }) - address_case_log.update!({ la: "Westminster" }) + address_case_log.update!({ la_known: "Yes", la: "Westminster" }) record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0] expect(record_from_db["property_postcode"]).to eq(nil) @@ -395,9 +395,22 @@ RSpec.describe CaseLog do expect(record_from_db["prevloc"]).to eq(nil) end + it "correctly resets la if la is not known" do + address_case_log.update!({ previous_postcode_known: "No" }) + address_case_log.update!({ previous_la_known: "Yes", prevloc: "Scotland" }) + record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0] + expect(record_from_db["prevloc"]).to eq("S92000003") + expect(address_case_log.prevloc).to eq("Scotland") + + address_case_log.update!({ previous_la_known: "No" }) + record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0] + expect(address_case_log.prevloc).to eq(nil) + expect(record_from_db["prevloc"]).to eq(nil) + end + it "changes the prevloc if previous postcode changes from not known to known and provided" do address_case_log.update!({ previous_postcode_known: "No" }) - address_case_log.update!({ prevloc: "Westminster" }) + address_case_log.update!({ previous_la_known: "Yes", prevloc: "Westminster" }) record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0] expect(record_from_db["previous_postcode"]).to eq(nil)