require "rails_helper" RSpec.describe OrganisationsController, type: :request do let(:organisation) { user.organisation } let(:unauthorised_organisation) { FactoryBot.create(:organisation) } let(:headers) { { "Accept" => "text/html" } } let(:page) { Capybara::Node::Simple.new(response.body) } let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:new_value) { "Test Name 35" } let(:params) { { id: organisation.id, organisation: { name: new_value } } } context "a not signed in user" do describe "#show" do it "does not let you see organisation details from org route" do get "/organisations/#{organisation.id}", headers: headers, params: {} expect(response).to redirect_to("/users/sign-in") end it "does not let you see organisation details from details route" do get "/organisations/#{organisation.id}/details", headers: headers, params: {} expect(response).to redirect_to("/users/sign-in") end it "does not let you see organisation users" do get "/organisations/#{organisation.id}/users", headers: headers, params: {} expect(response).to redirect_to("/users/sign-in") end end end context "a signed in user" do describe "#show" do context "organisation that the user belongs to" do before do sign_in user get "/organisations/#{organisation.id}", headers: headers, params: {} end it "redirects to details" do expect(response).to have_http_status(:redirect) end end context "organisation that are not in scope for the user, i.e. that they do not belong to" do before do sign_in user get "/organisations/#{unauthorised_organisation.id}", headers: headers, params: {} end it "returns not found 404 from org route" do expect(response).to have_http_status(:not_found) end it "shows the 404 view" do expect(page).to have_content("Page not found") end end end context "As a data coordinator user" do context "details tab" do context "organisation that the user belongs to" do before do sign_in user get "/organisations/#{organisation.id}/details", headers: headers, params: {} end it "shows the tab navigation" do expected_html = "