Browse Source

Redirect if year is not given for sales csv

pull/2423/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
4df0259dbd
  1. 2
      app/controllers/organisations_controller.rb
  2. 13
      spec/requests/organisations_controller_spec.rb

2
app/controllers/organisations_controller.rb

@ -186,6 +186,8 @@ class OrganisationsController < ApplicationController
end
def download_sales_csv
redirect_to sales_logs_filters_years_organisation_path(search: search_term, codes_only: codes_only_export?) and return if session_filters["years"].blank? || session_filters["years"].count != 1
organisation_logs = SalesLog.visible.where(owning_organisation_id: @organisation.id)
unpaginated_filtered_logs = filter_manager.filtered_logs(organisation_logs, search_term, session_filters)
codes_only = params.require(:codes_only) == "true"

13
spec/requests/organisations_controller_spec.rb

@ -1677,7 +1677,7 @@ RSpec.describe OrganisationsController, type: :request do
context "when they view the sales logs tab" do
before do
create(:sales_log, owning_organisation: organisation)
create(:sales_log, :in_progress, owning_organisation: organisation)
end
it "has CSV download buttons with the correct paths if at least 1 log exists" do
@ -1688,15 +1688,16 @@ RSpec.describe OrganisationsController, type: :request do
context "when you download the CSV" do
let(:other_organisation) { create(:organisation) }
let(:sales_logs_start_year) { organisation.owned_sales_logs.first.form.start_date.year }
before do
create_list(:sales_log, 2, owning_organisation: organisation)
create(:sales_log, owning_organisation: organisation, status: "pending", skip_update_status: true)
create_list(:sales_log, 2, owning_organisation: other_organisation)
create_list(:sales_log, 2, :in_progress, owning_organisation: organisation)
create(:sales_log, :in_progress, owning_organisation: organisation, status: "pending", skip_update_status: true)
create_list(:sales_log, 2, :in_progress, owning_organisation: other_organisation)
end
it "only includes logs from that organisation" do
get "/organisations/#{organisation.id}/sales-logs/csv-download?codes_only=false"
get "/organisations/#{organisation.id}/sales-logs/csv-download?years[]=#{sales_logs_start_year}&codes_only=false"
expect(page).to have_text("You've selected 3 logs.")
end
@ -1771,7 +1772,7 @@ RSpec.describe OrganisationsController, type: :request do
let!(:sales_log) { create(:sales_log, :in_progress, owning_organisation: organisation, purchid: search_term) }
it "renders a page with the correct header" do
get "/organisations/#{organisation.id}/sales-logs/csv-download?codes_only=false", headers:, params: {}
get "/organisations/#{organisation.id}/sales-logs/csv-download?years[]=#{sales_log.form.start_date.year}&codes_only=false", headers:, params: {}
header = page.find_css("h1")
expect(header.text).to include("Download CSV")
end

Loading…
Cancel
Save