Browse Source

replicate request specs from lettings for sales and organisations controllers

pull/1657/head
Arthur Campbell 3 years ago
parent
commit
c96db5251e
  1. 40
      spec/requests/organisations_controller_spec.rb
  2. 32
      spec/requests/sales_logs_controller_spec.rb

40
spec/requests/organisations_controller_spec.rb

@ -1221,26 +1221,43 @@ RSpec.describe OrganisationsController, type: :request do
end end
end end
end end
context "when they view the lettings logs tab" do
let(:tenancycode) { "42" }
before do
create(:lettings_log, owning_organisation: organisation, tenancycode:)
end end
context "when there is at least one log visible" do
before do
get lettings_logs_organisation_path(organisation, search: tenancycode)
end end
context "when the user is a support user" do it "shows the delete logs button with the correct path" do
let(:user) { create(:user, :support) } expect(page).to have_link "Delete logs", href: delete_lettings_logs_organisation_path(search: tenancycode)
end
before do it "has CSV download buttons with the correct paths" do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) expect(page).to have_link "Download (CSV)", href: lettings_logs_csv_download_organisation_path(organisation, codes_only: false, search: tenancycode)
sign_in user expect(page).to have_link "Download (CSV, codes only)", href: lettings_logs_csv_download_organisation_path(organisation, codes_only: true, search: tenancycode)
end
end end
context "when they view the lettings logs tab" do context "when there are no visible logs" do
before do before do
create(:lettings_log, owning_organisation: organisation) LettingsLog.destroy_all
get lettings_logs_organisation_path(organisation)
end end
it "has CSV download buttons with the correct paths if at least 1 log exists" do it "does not show the delete logs button " do
get "/organisations/#{organisation.id}/lettings-logs" expect(page).not_to have_link "Delete logs"
expect(page).to have_link("Download (CSV)", href: "/organisations/#{organisation.id}/lettings-logs/csv-download?codes_only=false") end
expect(page).to have_link("Download (CSV, codes only)", href: "/organisations/#{organisation.id}/lettings-logs/csv-download?codes_only=true")
it "does not show the csv download buttons" do
expect(page).not_to have_link "Download (CSV)"
expect(page).not_to have_link "Download (CSV, codes only)"
end
end end
context "when you download the CSV" do context "when you download the CSV" do
@ -1429,6 +1446,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
end end
end end
end
describe "GET #data_sharing_agreement" do describe "GET #data_sharing_agreement" do
context "when not signed in" do context "when not signed in" do

32
spec/requests/sales_logs_controller_spec.rb

@ -112,9 +112,11 @@ RSpec.describe SalesLogsController, type: :request do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation } let(:organisation) { user.organisation }
let(:other_organisation) { FactoryBot.create(:organisation) } let(:other_organisation) { FactoryBot.create(:organisation) }
let(:purchaser_code) { "coop123" }
let!(:sales_log) do let!(:sales_log) do
FactoryBot.create( FactoryBot.create(
:sales_log, :sales_log,
purchid: purchaser_code,
owning_organisation: organisation, owning_organisation: organisation,
) )
end end
@ -175,6 +177,36 @@ RSpec.describe SalesLogsController, type: :request do
end end
end end
context "and the state of filters and search is such that display_delete_logs returns true" do
before do
allow_any_instance_of(LogListHelper).to receive(:display_delete_logs?).and_return(true) # rubocop:disable RSpec/AnyInstance
end
it "displays the delete logs button with the correct path if there are logs visibile" do
get sales_logs_path(search: purchaser_code)
expect(page).to have_link "Delete logs", href: delete_logs_sales_logs_path(search: purchaser_code)
end
it "does not display the delete logs button if there are no logs displayed" do
SalesLog.destroy_all
get sales_logs_path(search: "gibberish_e9o87tvbyc4875g")
expect(page).not_to have_selector "article.app-log-summary"
expect(page).not_to have_link "Delete logs"
end
end
context "and the state of filters and search is such that display_delete_logs returns false" do
before do
allow_any_instance_of(LogListHelper).to receive(:display_delete_logs?).and_return(false) # rubocop:disable RSpec/AnyInstance
end
it "does not display the delete logs button even if there are logs displayed" do
get sales_logs_path
expect(page).to have_selector "article.app-log-summary"
expect(page).not_to have_link "Delete logs"
end
end
context "when there is a pending log" do context "when there is a pending log" do
let!(:invisible_log) do let!(:invisible_log) do
FactoryBot.create( FactoryBot.create(

Loading…
Cancel
Save