Browse Source

update lettings controller specs

pull/858/head
Kat 3 years ago
parent
commit
a82ab60276
  1. 2
      app/controllers/lettings_logs_controller.rb
  2. 22
      spec/requests/lettings_logs_controller_spec.rb

2
app/controllers/lettings_logs_controller.rb

@ -70,7 +70,7 @@ class LettingsLogsController < LogsController
end end
def download_csv def download_csv
unpaginated_filtered_logs = filtered_lettings_logs(current_user.lettings_logs, search_term, @session_filters) unpaginated_filtered_logs = filtered_logs(current_user.lettings_logs, search_term, @session_filters)
render "download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: email_csv_lettings_logs_path } render "download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: email_csv_lettings_logs_path }
end end

22
spec/requests/lettings_logs_controller_spec.rb

@ -400,8 +400,8 @@ RSpec.describe LettingsLogsController, type: :request do
it "includes the search on the CSV link" do it "includes the search on the CSV link" do
search_term = "foo" search_term = "foo"
get "/logs?search=#{search_term}", headers: headers, params: {} get "/lettings-logs?search=#{search_term}", headers: headers, params: {}
expect(page).to have_link("Download (CSV)", href: "/logs/csv-download?search=#{search_term}") expect(page).to have_link("Download (CSV)", href: "/lettings-logs/csv-download?search=#{search_term}")
end end
context "when more than one results with matching postcode" do context "when more than one results with matching postcode" do
@ -476,7 +476,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "shows a table of logs" do it "shows a table of logs" do
expect(CGI.unescape_html(response.body)).to match(/<article class="app-log-summary">/) expect(CGI.unescape_html(response.body)).to match(/<article class="app-log-summary">/)
expect(CGI.unescape_html(response.body)).to match(/logs/) expect(CGI.unescape_html(response.body)).to match(/lettings-logs/)
end end
it "only shows lettings logs for your organisation" do it "only shows lettings logs for your organisation" do
@ -513,7 +513,7 @@ RSpec.describe LettingsLogsController, type: :request do
end end
it "shows the CSV download link" do it "shows the CSV download link" do
expect(page).to have_link("Download (CSV)", href: "/logs/csv-download") expect(page).to have_link("Download (CSV)", href: "/lettings-logs/csv-download")
end end
it "does not show the organisation filter" do it "does not show the organisation filter" do
@ -757,7 +757,7 @@ RSpec.describe LettingsLogsController, type: :request do
before do before do
sign_in user sign_in user
get "/logs/csv-download?search=#{search_term}", headers: get "/lettings-logs/csv-download?search=#{search_term}", headers:
end end
it "returns http success" do it "returns http success" do
@ -782,7 +782,7 @@ RSpec.describe LettingsLogsController, type: :request do
end end
it "confirms that the user will receive an email with the requested CSV" do it "confirms that the user will receive an email with the requested CSV" do
get "/logs/csv-confirmation" get "/lettings-logs/csv-confirmation"
expect(CGI.unescape_html(response.body)).to include("We're sending you an email") expect(CGI.unescape_html(response.body)).to include("We're sending you an email")
end end
end end
@ -965,24 +965,24 @@ RSpec.describe LettingsLogsController, type: :request do
it "creates an E-mail job" do it "creates an E-mail job" do
expect { expect {
post "/logs/email-csv", headers:, params: {} post "/lettings-logs/email-csv", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, {}, false) }.to enqueue_job(EmailCsvJob).with(user, nil, {}, false)
end end
it "redirects to the confirmation page" do it "redirects to the confirmation page" do
post "/logs/email-csv", headers:, params: {} post "/lettings-logs/email-csv", headers:, params: {}
expect(response).to redirect_to(csv_confirmation_lettings_logs_path) expect(response).to redirect_to(csv_confirmation_lettings_logs_path)
end end
it "passes the search term" do it "passes the search term" do
expect { expect {
post "/logs/email-csv?search=#{lettings_log.id}", headers:, params: {} post "/lettings-logs/email-csv?search=#{lettings_log.id}", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, lettings_log.id.to_s, {}, false) }.to enqueue_job(EmailCsvJob).with(user, lettings_log.id.to_s, {}, false)
end end
it "passes filter parameters" do it "passes filter parameters" do
expect { expect {
post "/logs/email-csv?status[]=completed", headers:, params: {} post "/lettings-logs/email-csv?status[]=completed", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, { "status" => %w[completed] }, false) }.to enqueue_job(EmailCsvJob).with(user, nil, { "status" => %w[completed] }, false)
end end
@ -990,7 +990,7 @@ RSpec.describe LettingsLogsController, type: :request do
postcode = "XX1 1TG" postcode = "XX1 1TG"
expect { expect {
post "/logs/email-csv?status[]=completed&search=#{postcode}", headers:, params: {} post "/lettings-logs/email-csv?status[]=completed&search=#{postcode}", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, postcode, { "status" => %w[completed] }, false) }.to enqueue_job(EmailCsvJob).with(user, postcode, { "status" => %w[completed] }, false)
end end
end end

Loading…
Cancel
Save