From 3f000cecdea3d1338596a726672099f0fbcd25d6 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 8 Dec 2023 09:29:43 +0000 Subject: [PATCH] feat: update tests for different user visibility levels --- .../requests/organisations_controller_spec.rb | 15 +++-- spec/requests/schemes_controller_spec.rb | 58 +++++++++++++++++++ 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index ce6747f41..31360c71c 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -65,10 +65,13 @@ RSpec.describe OrganisationsController, type: :request do let!(:specific_org_scheme) { create(:scheme, owning_organisation: specific_organisation) } let!(:specific_org_locations) { create_list(:location, 3, scheme: specific_org_scheme) } + before do + get "/organisations/#{specific_organisation.id}/schemes", headers:, params: {} + end it "shows scheme and location download links" do - expect(page).to have_link("Download schemes (CSV)", href: csv_download_schemes_path(download_type: "schemes")) - expect(page).to have_link("Download locations (CSV)", href: csv_download_schemes_path(download_type: "locations")) - expect(page).to have_link("Download schemes and locations (CSV)", href: csv_download_schemes_path(download_type: "combined")) + expect(page).to have_link("Download schemes (CSV)", href: schemes_csv_download_organisation_path(specific_organisation, download_type: "schemes")) + expect(page).to have_link("Download locations (CSV)", href: schemes_csv_download_organisation_path(specific_organisation, download_type: "locations")) + expect(page).to have_link("Download schemes and locations (CSV)", href: schemes_csv_download_organisation_path(specific_organisation, download_type: "combined")) end context "when there are no schemes for this organisation" do @@ -86,7 +89,7 @@ RSpec.describe OrganisationsController, type: :request do context "when downloading scheme data" do before do - get csv_download_schemes_path(download_type: "schemes") + get schemes_csv_download_organisation_path(specific_organisation, download_type: "schemes") end it "redirects to the correct download page" do @@ -96,7 +99,7 @@ RSpec.describe OrganisationsController, type: :request do context "when downloading location data" do before do - get csv_download_schemes_path(download_type: "locations") + get schemes_csv_download_organisation_path(specific_organisation, download_type: "locations") end it "redirects to the correct download page" do @@ -106,7 +109,7 @@ RSpec.describe OrganisationsController, type: :request do context "when downloading scheme and location data" do before do - get csv_download_schemes_path(download_type: "combined") + get schemes_csv_download_organisation_path(specific_organisation, download_type: "combined") end it "redirects to the correct download page" do diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 3016c3f4b..3bf6b2c6e 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -191,6 +191,64 @@ RSpec.describe SchemesController, type: :request do expect(page).to have_content("Schemes") end + describe "scheme and location csv downloads" do + let!(:same_org_scheme) { create(:scheme, owning_organisation: user.organisation) } + let!(:same_org_location) { create(:location, scheme: same_org_scheme) } + let!(:specific_organisation) { create(:organisation) } + let!(:specific_org_schemes) { create_list(:scheme, 5, owning_organisation: specific_organisation) } + let!(:specific_org_scheme) { create(:scheme, owning_organisation: specific_organisation) } + let!(:specific_org_locations) { create_list(:location, 3, scheme: specific_org_scheme) } + + it "shows scheme and location download links" do + expect(page).to have_link("Download schemes (CSV)", href: csv_download_schemes_path(download_type: "schemes")) + expect(page).to have_link("Download locations (CSV)", href: csv_download_schemes_path(download_type: "locations")) + expect(page).to have_link("Download schemes and locations (CSV)", href: csv_download_schemes_path(download_type: "combined")) + end + + context "when there are no schemes for any organisation" do + before do + Scheme.destroy_all + get "/schemes" + end + + it "does not display CSV download links" do + expect(page).not_to have_link("Download schemes (CSV)") + expect(page).not_to have_link("Download locations (CSV)") + expect(page).not_to have_link("Download schemes and locations (CSV)") + end + end + + context "when downloading scheme data" do + before do + get csv_download_schemes_path(download_type: "schemes") + end + + it "redirects to the correct download page" do + expect(page).to have_content("You've selected 12 schemes.") + end + end + + context "when downloading location data" do + before do + get csv_download_schemes_path(download_type: "locations") + end + + it "redirects to the correct download page" do + expect(page).to have_content("You've selected 9 locations from 12 schemes.") + end + end + + context "when downloading scheme and location data" do + before do + get csv_download_schemes_path(download_type: "combined") + end + + it "redirects to the correct download page" do + expect(page).to have_content("You've selected 12 schemes with 9 locations.") + end + end + end + it "shows all schemes" do schemes.each do |scheme| expect(page).to have_content(scheme.id_to_display)