From e6e9c42924bece59418c93fb6454ddc13468d2ce Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 4 Jan 2022 14:08:12 +0000 Subject: [PATCH] Do not show the postcode known question in check answers --- app/models/form/question.rb | 7 ++++++- app/models/form/subsection.rb | 2 +- config/forms/2021_2022.json | 3 ++- spec/requests/case_log_controller_spec.rb | 21 ++++++++++++++------- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 725aab815..18c1c6e82 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -2,7 +2,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, - :inferred_answers + :inferred_answers, :hidden_in_check_answers def initialize(id, hsh, page) @id = id @@ -20,6 +20,7 @@ class Form::Question @answer_options = hsh["answer_options"] @conditional_for = hsh["conditional_for"] @inferred_answers = hsh["inferred_answers"] + @hidden_in_check_answers = hsh["hidden_in_check_answers"] @page = page end @@ -49,6 +50,10 @@ class Form::Question conditional_on.map { |condition| evaluate_condition(condition, case_log) }.all? end + def hidden_in_check_answers? + hidden_in_check_answers + end + def update_answer_link_name(case_log) if type == "checkbox" answer_options.keys.any? { |key| case_log[key] == "Yes" } ? "Change" : "Answer" diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index 19700d935..922297bdf 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -52,7 +52,7 @@ class Form::Subsection end def applicable_questions(case_log) - questions.select { |q| q.page.routed_to?(case_log) && q.enabled?(case_log) } + questions.select { |q| q.page.routed_to?(case_log) && q.enabled?(case_log) && !q.hidden_in_check_answers? } end def answered_questions(case_log) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 5e2cfa92b..eedd76873 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1144,7 +1144,8 @@ }, "conditional_for": { "property_postcode": ["Yes"] - } + }, + "hidden_in_check_answers": true }, "property_postcode": { "check_answer_label": "Postcode", diff --git a/spec/requests/case_log_controller_spec.rb b/spec/requests/case_log_controller_spec.rb index d709a503a..ac5da57fb 100644 --- a/spec/requests/case_log_controller_spec.rb +++ b/spec/requests/case_log_controller_spec.rb @@ -242,6 +242,14 @@ RSpec.describe CaseLogsController, type: :request do end context "Check answers" do + let(:postcode_case_log) do + FactoryBot.create(:case_log, + owning_organisation: organisation, + managing_organisation: organisation, + postcode_known: "No") + end + let(:id) { postcode_case_log.id } + before do stub_request(:get, /api.postcodes.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\"}}", headers: {}) @@ -260,16 +268,15 @@ RSpec.describe CaseLogsController, type: :request do expect(CGI.unescape_html(response.body)).to include(expected_inferred_answer) end - it "shows is the postcode is not known" do - case_log = FactoryBot.create(:case_log, - owning_organisation: organisation, - managing_organisation: organisation, - postcode_known: "No") - id = case_log.id + it "does not show do you know the property postcode question" do get "/logs/#{id}/property-information/check-answers" - expect(CGI.unescape_html(response.body)).to include("Not known") expect(CGI.unescape_html(response.body)).not_to include("Do you know the property postcode?") end + + it "shows if the postcode is not known" do + get "/logs/#{id}/property-information/check-answers" + expect(CGI.unescape_html(response.body)).to include("Not known") + end end end