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 "when user is not signed in" 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("/account/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("/account/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("/account/sign-in") end end end context "when user is signed in" do describe "#show" do context "with an organisation that the user belongs to" do before do sign_in user get "/organisations/#{organisation.id}", headers:, params: {} end it "redirects to details" do expect(response).to have_http_status(:redirect) end end context "with an 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:, 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 "with a data coordinator user" do context "when we access the details tab" do context "with an organisation that the user belongs to" do before do sign_in user get "/organisations/#{organisation.id}/details", headers:, params: {} end it "shows the tab navigation" do expected_html = "