Browse Source

feat: update tests for different user visibility levels

pull/2083/head
natdeanlewissoftwire 2 years ago
parent
commit
3f000cecde
  1. 15
      spec/requests/organisations_controller_spec.rb
  2. 58
      spec/requests/schemes_controller_spec.rb

15
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

58
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)

Loading…
Cancel
Save