From d7048cc9c466b4f2bbfc376444dc19bd79a7ed5e Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 19 May 2022 16:36:44 +0100 Subject: [PATCH] Test for displaying logs for specific organisation --- .../requests/organisations_controller_spec.rb | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 1111a42ec..c75338bc6 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -349,11 +349,11 @@ RSpec.describe OrganisationsController, type: :request do end context "with a support user" do - let(:user) { FactoryBot.create(:user, :support) } + let(:support_user) { FactoryBot.create(:user, :support) } before do - allow(user).to receive(:need_two_factor_authentication?).and_return(false) - sign_in user + allow(support_user).to receive(:need_two_factor_authentication?).and_return(false) + sign_in support_user get "/organisations" end @@ -362,6 +362,28 @@ RSpec.describe OrganisationsController, type: :request do expect(page).to have_link organisation.name, href: "organisations/#{organisation.id}/logs" expect(page).to have_link unauthorised_organisation.name, href: "organisations/#{unauthorised_organisation.id}/logs" end + + context "when viewing a specific organisation" do + let(:number_of_org1_case_logs) { 2 } + let(:number_of_org2_case_logs) { 4 } + before do + FactoryBot.create_list(:case_log, number_of_org1_case_logs, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) + FactoryBot.create_list(:case_log, number_of_org2_case_logs, owning_organisation_id: unauthorised_organisation.id, managing_organisation_id: unauthorised_organisation.id) + end + + it "only shows logs for that organisation" do + get "/organisations/#{organisation.id}/logs", headers:, params: {} + + expect(page).to have_content("#{number_of_org1_case_logs} total logs") + organisation.case_logs.map(&:id).each do |case_log_id| + expect(page).to have_link case_log_id.to_s, href: "/logs/#{case_log_id}" + end + + unauthorised_organisation.case_logs.map(&:id).each do |case_log_id| + expect(page).not_to have_link case_log_id.to_s, href: "/logs/#{case_log_id}" + end + end + end end context "when there are more than 20 organisations" do