Browse Source

Fix CSV downloads for specific organisations (#2430)

pull/2431/head v0.4.42
kosiakkatrina 8 months ago committed by GitHub
parent
commit
5c34132049
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/controllers/organisations_controller.rb
  2. 31
      spec/requests/organisations_controller_spec.rb

4
app/controllers/organisations_controller.rb

@ -158,7 +158,7 @@ class OrganisationsController < ApplicationController
end end
def email_lettings_csv def email_lettings_csv
EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?) EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?, "lettings", session_filters["years"].first.to_i)
redirect_to lettings_logs_csv_confirmation_organisation_path redirect_to lettings_logs_csv_confirmation_organisation_path
end end
@ -196,7 +196,7 @@ class OrganisationsController < ApplicationController
end end
def email_sales_csv def email_sales_csv
EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?, "sales") EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?, "sales", session_filters["years"].first.to_i)
redirect_to sales_logs_csv_confirmation_organisation_path redirect_to sales_logs_csv_confirmation_organisation_path
end end

31
spec/requests/organisations_controller_spec.rb

@ -1626,6 +1626,7 @@ RSpec.describe OrganisationsController, type: :request do
context "when you download the CSV" do context "when you download the CSV" do
let(:other_organisation) { create(:organisation) } let(:other_organisation) { create(:organisation) }
let!(:lettings_logs) { create_list(:lettings_log, 2, :in_progress, owning_organisation: organisation) } let!(:lettings_logs) { create_list(:lettings_log, 2, :in_progress, owning_organisation: organisation) }
let(:lettings_log_start_year) { lettings_logs[0].form.start_date.year }
before do before do
create(:lettings_log, :in_progress, owning_organisation: organisation, status: "pending", skip_update_status: true) create(:lettings_log, :in_progress, owning_organisation: organisation, status: "pending", skip_update_status: true)
@ -1642,25 +1643,25 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "only includes logs from that organisation" do it "only includes logs from that organisation" do
get "/organisations/#{organisation.id}/lettings-logs/csv-download?years[]=#{lettings_logs[0].form.start_date.year}&codes_only=false" get "/organisations/#{organisation.id}/lettings-logs/csv-download?years[]=#{lettings_log_start_year}&codes_only=false"
expect(page).to have_text("You've selected 3 logs.") expect(page).to have_text("You've selected 3 logs.")
end end
it "provides the organisation to the mail job" do it "provides the organisation to the mail job" do
expect { expect {
post "/organisations/#{organisation.id}/lettings-logs/email-csv?status[]=completed&codes_only=false", headers:, params: {} post "/organisations/#{organisation.id}/lettings-logs/email-csv?years[]=#{lettings_log_start_year}&status[]=completed&codes_only=false", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, { "status" => %w[completed] }, false, organisation, false) }.to enqueue_job(EmailCsvJob).with(user, nil, { "status" => %w[completed], "years" => [lettings_log_start_year.to_s] }, false, organisation, false, "lettings", lettings_log_start_year)
end end
it "provides the export type to the mail job" do it "provides the export type to the mail job" do
codes_only_export_type = false codes_only_export_type = false
expect { expect {
post "/organisations/#{organisation.id}/lettings-logs/email-csv?codes_only=#{codes_only_export_type}", headers:, params: {} post "/organisations/#{organisation.id}/lettings-logs/email-csv?years[]=#{lettings_log_start_year}&codes_only=#{codes_only_export_type}", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, {}, false, organisation, codes_only_export_type) }.to enqueue_job(EmailCsvJob).with(user, nil, { "years" => [lettings_log_start_year.to_s] }, false, organisation, codes_only_export_type, "lettings", lettings_log_start_year)
codes_only_export_type = true codes_only_export_type = true
expect { expect {
post "/organisations/#{organisation.id}/lettings-logs/email-csv?codes_only=#{codes_only_export_type}", headers:, params: {} post "/organisations/#{organisation.id}/lettings-logs/email-csv?years[]=#{lettings_log_start_year}&codes_only=#{codes_only_export_type}", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, {}, false, organisation, codes_only_export_type) }.to enqueue_job(EmailCsvJob).with(user, nil, { "years" => [lettings_log_start_year.to_s] }, false, organisation, codes_only_export_type, "lettings", lettings_log_start_year)
end end
end end
@ -1704,26 +1705,26 @@ RSpec.describe OrganisationsController, type: :request do
it "provides the organisation to the mail job" do it "provides the organisation to the mail job" do
expect { expect {
post "/organisations/#{organisation.id}/sales-logs/email-csv?status[]=completed&codes_only=false", headers:, params: {} post "/organisations/#{organisation.id}/sales-logs/email-csv?years[]=#{sales_logs_start_year}&status[]=completed&codes_only=false", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, { "status" => %w[completed] }, false, organisation, false, "sales") }.to enqueue_job(EmailCsvJob).with(user, nil, { "status" => %w[completed], "years" => [sales_logs_start_year.to_s] }, false, organisation, false, "sales", sales_logs_start_year)
end end
it "provides the log type to the mail job" do it "provides the log type to the mail job" do
log_type = "sales" log_type = "sales"
expect { expect {
post "/organisations/#{organisation.id}/sales-logs/email-csv?status[]=completed&codes_only=false", headers:, params: {} post "/organisations/#{organisation.id}/sales-logs/email-csv?years[]=#{sales_logs_start_year}&status[]=completed&codes_only=false", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, { "status" => %w[completed] }, false, organisation, false, log_type) }.to enqueue_job(EmailCsvJob).with(user, nil, { "status" => %w[completed], "years" => [sales_logs_start_year.to_s] }, false, organisation, false, log_type, sales_logs_start_year)
end end
it "provides the export type to the mail job" do it "provides the export type to the mail job" do
codes_only_export_type = false codes_only_export_type = false
expect { expect {
post "/organisations/#{organisation.id}/sales-logs/email-csv?codes_only=#{codes_only_export_type}", headers:, params: {} post "/organisations/#{organisation.id}/sales-logs/email-csv?years[]=#{sales_logs_start_year}&codes_only=#{codes_only_export_type}", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, {}, false, organisation, codes_only_export_type, "sales") }.to enqueue_job(EmailCsvJob).with(user, nil, { "years" => [sales_logs_start_year.to_s] }, false, organisation, codes_only_export_type, "sales", sales_logs_start_year)
codes_only_export_type = true codes_only_export_type = true
expect { expect {
post "/organisations/#{organisation.id}/sales-logs/email-csv?codes_only=#{codes_only_export_type}", headers:, params: {} post "/organisations/#{organisation.id}/sales-logs/email-csv?years[]=#{sales_logs_start_year}&codes_only=#{codes_only_export_type}", headers:, params: {}
}.to enqueue_job(EmailCsvJob).with(user, nil, {}, false, organisation, codes_only_export_type, "sales") }.to enqueue_job(EmailCsvJob).with(user, nil, { "years" => [sales_logs_start_year.to_s] }, false, organisation, codes_only_export_type, "sales", sales_logs_start_year)
end end
end end
end end

Loading…
Cancel
Save