From 53a63936b0b2bf1b12242cc406baa0a234c203ee Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Mon, 18 Nov 2024 12:42:40 +0000 Subject: [PATCH] Only direct via secondary client group page when newly required --- app/controllers/schemes_controller.rb | 8 ++--- spec/features/schemes_spec.rb | 7 ---- spec/requests/schemes_controller_spec.rb | 42 +++++++++++++++++++++--- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index f4e9ddc46..be5d3f7ef 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -145,7 +145,7 @@ class SchemesController < ApplicationController if @scheme.errors.empty? && @scheme.update(scheme_params) @scheme.update!(secondary_client_group: nil) if @scheme.has_other_client_group == "No" if scheme_params[:confirmed] == "true" || @scheme.confirmed? - if check_answers && confirm_secondary_page?(page) + if check_answers && should_direct_via_secondary_client_group_page?(page) redirect_to scheme_secondary_client_group_path(@scheme, referrer: "check-answers") else @scheme.locations.update!(confirmed: true) @@ -157,7 +157,7 @@ class SchemesController < ApplicationController redirect_to scheme_path(@scheme) end elsif check_answers - if confirm_secondary_page?(page) + if should_direct_via_secondary_client_group_page?(page) redirect_to scheme_secondary_client_group_path(@scheme, referrer: "check-answers") else redirect_to scheme_check_answers_path(@scheme) @@ -249,8 +249,8 @@ private end end - def confirm_secondary_page?(page) - page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" + def should_direct_via_secondary_client_group_page?(page) + page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" && @scheme.secondary_client_group.nil? end def current_template(page) diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 8f162c8a6..33ab00b34 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -727,13 +727,6 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content "Check your changes before creating this scheme" end - it "keeps the provider answer when switching between other provider options" do - click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?referrer=check-answers", match: :first) - choose "Yes" - click_button "Save changes" - expect(find_field("Offenders and people at risk of offending")).to be_checked - end - it "does not display the answer if it's changed to the same support provider" do click_link("Change", href: "/schemes/#{scheme.id}/details?referrer=check-answers", match: :first) choose "The same organisation that owns the housing stock" diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index d93bc873d..19ede5cc4 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -1405,10 +1405,11 @@ RSpec.describe SchemesController, type: :request do expect(scheme_to_update.reload.has_other_client_group).to eq("Yes") end - context "when updating from check answers page with the answer YES" do + context "when updating from check answers page with the answer YES and no secondary client group set" do + let(:scheme_to_update) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, secondary_client_group: nil) } let(:params) { { scheme: { has_other_client_group: "Yes", page: "confirm-secondary", check_answers: "true" } } } - it "renders check answers page after successful update" do + it "renders secondary client group page after successful update" do follow_redirect! expect(response).to have_http_status(:ok) expect(page).to have_content("What is the other client group?") @@ -1420,6 +1421,22 @@ RSpec.describe SchemesController, type: :request do end end + context "when updating from check answers page with the answer YES and a secondary client group set" do + let(:scheme_to_update) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, secondary_client_group: "F") } + let(:params) { { scheme: { has_other_client_group: "Yes", page: "confirm-secondary", check_answers: "true" } } } + + it "renders check answers page after successful update" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Check your changes before creating this scheme") + end + + it "updates a scheme with valid params" do + follow_redirect! + expect(scheme_to_update.reload.has_other_client_group).to eq("Yes") + end + end + context "when updating from check answers page with the answer NO" do let(:params) { { scheme: { has_other_client_group: "No", page: "confirm-secondary", check_answers: "true" } } } @@ -1716,10 +1733,11 @@ RSpec.describe SchemesController, type: :request do expect(scheme_to_update.reload.has_other_client_group).to eq("Yes") end - context "when updating from check answers page with the answer YES" do + context "when updating from check answers page with the answer YES and no existing secondary client group set" do + let(:scheme_to_update) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, secondary_client_group: nil) } let(:params) { { scheme: { has_other_client_group: "Yes", page: "confirm-secondary", check_answers: "true" } } } - it "renders check answers page after successful update" do + it "renders secondary client group page after successful update" do follow_redirect! expect(response).to have_http_status(:ok) expect(page).to have_content("What is the other client group?") @@ -1731,6 +1749,22 @@ RSpec.describe SchemesController, type: :request do end end + context "when updating from check answers page with the answer YES and an existing secondary client group set" do + let(:scheme_to_update) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, secondary_client_group: "F") } + let(:params) { { scheme: { has_other_client_group: "Yes", page: "confirm-secondary", check_answers: "true" } } } + + it "renders check answers page after successful update" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Check your changes before creating this scheme") + end + + it "updates a scheme with valid params" do + follow_redirect! + expect(scheme_to_update.reload.has_other_client_group).to eq("Yes") + end + end + context "when updating from check answers page with the answer NO" do let(:params) { { scheme: { has_other_client_group: "No", page: "confirm-secondary", check_answers: "true" } } }