Browse Source

redirect to scheme when trying to access check answers for confirmed scheme

pull/792/head
Kat 2 years ago
parent
commit
ef9d75accc
  1. 6
      app/controllers/schemes_controller.rb
  2. 32
      spec/features/schemes_spec.rb
  3. 8
      spec/requests/locations_controller_spec.rb
  4. 62
      spec/requests/schemes_controller_spec.rb

6
app/controllers/schemes_controller.rb

@ -84,7 +84,11 @@ class SchemesController < ApplicationController
end end
def check_answers def check_answers
render "schemes/check_answers" if @scheme.confirmed?
redirect_to @scheme
else
render "schemes/check_answers"
end
end end
def edit_name def edit_name

32
spec/features/schemes_spec.rb

@ -274,13 +274,13 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save and continue" click_button "Save and continue"
end end
it "shows the check answers page location tab" do it "shows scheme location tab" do
expect(page.current_url.split("/").last).to eq("check-answers#locations") expect(page.current_url.split("/").last).to eq("locations")
expect(page).to have_content(location_name) expect(page).to have_content(location_name)
end end
it "has the correct action button text" do it "does not have an action button" do
expect(page).to have_button("Save") expect(page).not_to have_button("Save")
expect(page).not_to have_button("Create scheme") expect(page).not_to have_button("Create scheme")
end end
@ -289,8 +289,8 @@ RSpec.describe "Schemes scheme Features" do
click_link("Scheme") click_link("Scheme")
end end
it "does not let you change details other than the name" do 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: 1 assert_selector "a", text: "Change", count: 3
end end
end end
end end
@ -460,6 +460,14 @@ RSpec.describe "Schemes scheme Features" do
fill_in_and_save_second_location fill_in_and_save_second_location
expect(page).to have_content "Check your changes before creating this scheme" expect(page).to have_content "Check your changes before creating this scheme"
end 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 end
context "when viewing locations" do context "when viewing locations" do
@ -819,13 +827,13 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save and continue" click_button "Save and continue"
end end
it "shows the check answers page location tab" do it "shows the scheme location tab" do
expect(page.current_url.split("/").last).to eq("check-answers#locations") expect(page.current_url.split("/").last).to eq("locations")
expect(page).to have_content(location_name) expect(page).to have_content(location_name)
end end
it "has the correct action button text" do it "does not have an action button" do
expect(page).to have_button("Save") expect(page).not_to have_button("Save")
expect(page).not_to have_button("Create scheme") expect(page).not_to have_button("Create scheme")
end end
@ -834,8 +842,8 @@ RSpec.describe "Schemes scheme Features" do
click_link("Scheme") click_link("Scheme")
end end
it "does not let you change details other than the name" do 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: 1 assert_selector "a", text: "Change", count: 3
end end
end end
end end

8
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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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(: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" } } } 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 context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } 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" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }
before do before do
@ -507,7 +507,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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!(:location) { FactoryBot.create(:location, scheme:) }
let(:startdate) { Time.utc(2021, 1, 2) } 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" } } } 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 context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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!(: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" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }

62
spec/requests/schemes_controller_spec.rb

@ -873,7 +873,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support" do context "when signed in as a support" do
let(:user) { FactoryBot.create(:user, :support) } 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 before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -1433,12 +1433,34 @@ RSpec.describe SchemesController, type: :request do
before do before do
sign_in user sign_in user
get "/schemes/#{scheme.id}/check-answers"
end end
it "returns a template for a support" do context "when the scheme is not confirmed" do
expect(response).to have_http_status(:ok) before do
expect(page).to have_content("Check your changes before creating this scheme") 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 end
context "when attempting to access check-answers scheme page for another organisation" do 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 before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
get "/schemes/#{scheme.id}/check-answers"
end end
it "returns a template for a support" do context "when the scheme is not confirmed" do
expect(response).to have_http_status(:ok) before do
expect(page).to have_content("Check your changes before creating this scheme") 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 end
end end

Loading…
Cancel
Save