From ef9d75accc68bfcbe79d60f1242ddb48b40c566a Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 28 Jul 2022 13:48:58 +0100 Subject: [PATCH] redirect to scheme when trying to access check answers for confirmed scheme --- app/controllers/schemes_controller.rb | 6 ++- spec/features/schemes_spec.rb | 32 ++++++----- spec/requests/locations_controller_spec.rb | 8 +-- spec/requests/schemes_controller_spec.rb | 62 ++++++++++++++++++---- 4 files changed, 82 insertions(+), 26 deletions(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 2bae8ae94..0cbc66fc2 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -84,7 +84,11 @@ class SchemesController < ApplicationController end def check_answers - render "schemes/check_answers" + if @scheme.confirmed? + redirect_to @scheme + else + render "schemes/check_answers" + end end def edit_name diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 2cece714f..ebd63c8d9 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -274,13 +274,13 @@ RSpec.describe "Schemes scheme Features" do click_button "Save and continue" end - it "shows the check answers page location tab" do - expect(page.current_url.split("/").last).to eq("check-answers#locations") + it "shows scheme location tab" do + expect(page.current_url.split("/").last).to eq("locations") expect(page).to have_content(location_name) end - it "has the correct action button text" do - expect(page).to have_button("Save") + it "does not have an action button" do + expect(page).not_to have_button("Save") expect(page).not_to have_button("Create scheme") end @@ -289,8 +289,8 @@ RSpec.describe "Schemes scheme Features" do click_link("Scheme") end - it "does not let you change details other than the name" do - assert_selector "a", text: "Change", count: 1 + it "does not let you change details other than the name, confidential information and Housing stock owned by" do + assert_selector "a", text: "Change", count: 3 end end end @@ -460,6 +460,14 @@ RSpec.describe "Schemes scheme Features" do fill_in_and_save_second_location expect(page).to have_content "Check your changes before creating this scheme" end + + context "when saving a scheme" do + it "shows a confirmation banner" do + fill_in_and_save_location + click_button "Create scheme" + expect(page).to have_content("has been created.") + end + end end context "when viewing locations" do @@ -819,13 +827,13 @@ RSpec.describe "Schemes scheme Features" do click_button "Save and continue" end - it "shows the check answers page location tab" do - expect(page.current_url.split("/").last).to eq("check-answers#locations") + it "shows the scheme location tab" do + expect(page.current_url.split("/").last).to eq("locations") expect(page).to have_content(location_name) end - it "has the correct action button text" do - expect(page).to have_button("Save") + it "does not have an action button" do + expect(page).not_to have_button("Save") expect(page).not_to have_button("Create scheme") end @@ -834,8 +842,8 @@ RSpec.describe "Schemes scheme Features" do click_link("Scheme") end - it "does not let you change details other than the name" do - assert_selector "a", text: "Change", count: 1 + it "does not let you change details other than the name, Confidential information and Housing stock owned by" do + assert_selector "a", text: "Change", count: 3 end end end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index bd0aee42c..903b5b0ce 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -89,7 +89,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } let(:startdate) { Time.utc(2022, 2, 2) } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", startdate:, mobility_type: "A" } } } @@ -268,7 +268,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } - let!(:scheme) { FactoryBot.create(:scheme) } + let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } } before do @@ -507,7 +507,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } let!(:location) { FactoryBot.create(:location, scheme:) } let(:startdate) { Time.utc(2021, 1, 2) } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", startdate:, page: "edit" } } } @@ -639,7 +639,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } let!(:location) { FactoryBot.create(:location, scheme:) } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 8549d79f0..41e6d0f58 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -873,7 +873,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a support" do let(:user) { FactoryBot.create(:user, :support) } - let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -1433,12 +1433,34 @@ RSpec.describe SchemesController, type: :request do before do sign_in user - get "/schemes/#{scheme.id}/check-answers" end - it "returns a template for a support" do - expect(response).to have_http_status(:ok) - expect(page).to have_content("Check your changes before creating this scheme") + context "when the scheme is not confirmed" do + before do + scheme.update!(confirmed: nil) + get "/schemes/#{scheme.id}/check-answers" + end + + it "returns a template for a support" do + expect(response).to have_http_status(:ok) + expect(page).to have_content("Check your changes before creating this scheme") + assert_select "a", text: /Change/, count: 11 + end + end + + context "when the scheme is confirmed" do + before do + scheme.update!(confirmed: true) + get "/schemes/#{scheme.id}/check-answers" + end + + it "redirects to a view scheme page" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).not_to have_content("Check your changes before creating this scheme") + expect(page).to have_content(scheme.service_name) + assert_select "a", text: /Change/, count: 2 + end end context "when attempting to access check-answers scheme page for another organisation" do @@ -1460,12 +1482,34 @@ RSpec.describe SchemesController, type: :request do before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in user - get "/schemes/#{scheme.id}/check-answers" end - it "returns a template for a support" do - expect(response).to have_http_status(:ok) - expect(page).to have_content("Check your changes before creating this scheme") + context "when the scheme is not confirmed" do + before do + scheme.update!(confirmed: nil) + get "/schemes/#{scheme.id}/check-answers" + end + + it "returns a template for a support" do + expect(response).to have_http_status(:ok) + expect(page).to have_content("Check your changes before creating this scheme") + assert_select "a", text: /Change/, count: 11 + end + end + + context "when the scheme is confirmed" do + before do + scheme.update!(confirmed: true) + get "/schemes/#{scheme.id}/check-answers" + end + + it "redirects to a view scheme page" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).not_to have_content("Check your changes before creating this scheme") + expect(page).to have_content(scheme.service_name) + assert_select "a", text: /Change/, count: 3 + end end end end