Browse Source

tests for a check-answers

pull/671/head
JG 3 years ago
parent
commit
07a379391c
  1. 132
      spec/requests/schemes_controller_spec.rb

132
spec/requests/schemes_controller_spec.rb

@ -1201,4 +1201,136 @@ RSpec.describe SchemesController, type: :request do
end end
end end
end end
describe "#support" do
context "when not signed in" do
it "redirects to the sign in page" do
get "/schemes/#{1}/support"
expect(response).to redirect_to("/account/sign-in")
end
end
context "when signed in as a data provider" do
let(:user) { FactoryBot.create(:user) }
before do
sign_in user
get "/schemes/#{1}/support"
end
it "returns 401 unauthorized" do
request
expect(response).to have_http_status(:unauthorized)
end
end
context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let!(:another_scheme) { FactoryBot.create(:scheme) }
before do
sign_in user
get "/schemes/#{scheme.id}/support"
end
it "returns a template for a support" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("What support does this scheme provide?")
end
context "when attempting to access secondary-client-group scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/support"
end
it "returns 404 not_found" do
request
expect(response).to have_http_status(:not_found)
end
end
end
context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
get "/schemes/#{scheme.id}/support"
end
it "returns a template for a support" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("What support does this scheme provide?")
end
end
end
describe "#check-answers" do
context "when not signed in" do
it "redirects to the sign in page" do
get "/schemes/#{1}/check-answers"
expect(response).to redirect_to("/account/sign-in")
end
end
context "when signed in as a data provider" do
let(:user) { FactoryBot.create(:user) }
before do
sign_in user
get "/schemes/#{1}/check-answers"
end
it "returns 401 unauthorized" do
request
expect(response).to have_http_status(:unauthorized)
end
end
context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let!(:another_scheme) { FactoryBot.create(:scheme) }
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 updating this scheme")
end
context "when attempting to access check-answers scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/check-answers"
end
it "returns 404 not_found" do
request
expect(response).to have_http_status(:not_found)
end
end
end
context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) }
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 updating this scheme")
end
end
end
end end

Loading…
Cancel
Save