<%= f.govuk_text_field :search, value: params[:search], label: { text: 'Search' }, hint: { text: 'Search by name, email, passport number or unique reference number (URN)' } %>
@@ -10,7 +5,7 @@
- <%= f.govuk_select :status, statuses, label: { text: "Filter by application status" } %>
+ <%= f.govuk_select :status, application_statuses_options(selected: params[:status], all_statuses: true), label: { text: "Filter by application status" } %>
@@ -25,9 +20,6 @@
<%= f.govuk_submit 'Search', secondary: true %>
- <% if session[:filter_status].present? %>
- <%= link_to "Download QA CSV", download_qa_csv_applicants_path, class: "govuk-button" %>
- <% end %>
<% end %>
<%= govuk_table(classes: "applicants-table") do |table|
diff --git a/app/views/system_admin/reports/index.html.erb b/app/views/system_admin/reports/index.html.erb
index 57c2bb57..5e78d0f7 100644
--- a/app/views/system_admin/reports/index.html.erb
+++ b/app/views/system_admin/reports/index.html.erb
@@ -38,3 +38,23 @@
<%= link_to "Download", report_path(:applications), class: "govuk-button" %>
+
+
+
QA reports
+
+ Download a QA CSV file
+
+
+
+ <%= form_with(url: report_path(:qa), method: :get) do |f| %>
+
+
+ <%= f.govuk_select :status, application_statuses_options, label: { text: "Filter by application status" } %>
+
+
+ <%= f.govuk_submit 'Download', class: "govuk-button"%>
+
+
+ <% end %>
+
+
diff --git a/config/routes.rb b/config/routes.rb
index 8358f046..ad1fdbab 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -25,12 +25,7 @@
end
scope module: :system_admin, path: "system-admin" do
- resources :applicants, only: %i[index show edit update] do
- collection do
- get :download_qa_csv
- end
- end
-
+ resources :applicants, only: %i[index show edit update]
resources :users, except: %i[show]
resource :settings, only: %i[edit update]
get "/dashboard", to: "dashboard#show"
diff --git a/spec/features/admin_console/download_qa_csv_file_spec.rb b/spec/features/admin_console/download_qa_csv_file_spec.rb
deleted file mode 100644
index 35fc74a8..00000000
--- a/spec/features/admin_console/download_qa_csv_file_spec.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-require "rails_helper"
-
-describe "Download QA CSV functionality" do
- include AdminHelpers
-
- it "shows the 'Download QA CSV' button only if a status filter is applied" do
- given_there_are_few_applications
- given_i_am_signed_as_an_admin
- when_i_am_in_the_applications_list_page
- then_i_should_not_see_the_download_button
- when_i_filter_by_a_status
- then_i_should_see_the_download_button
- end
-
- it "marks applications as qa before generating the csv" do
- given_there_are_few_applications
- given_i_am_signed_as_an_admin
- when_i_am_in_the_applications_list_page
- when_i_filter_by_a_status
- when_i_download_the_csv
-
- then_all_applications_should_be_marked_as_qa
- end
-
- it "generates an empty csv when downloaded twice consecutively" do
- given_there_are_few_applications
- given_i_am_signed_as_an_admin
- when_i_am_in_the_applications_list_page
- when_i_filter_by_a_status
- when_i_download_the_csv
- when_i_am_in_the_applications_list_page
- when_i_filter_by_a_status
- when_i_download_the_csv_again
-
- then_csv_should_be_empty
- end
-
- def given_there_are_few_applications
- create_list(:application, 5)
- end
-
- def when_i_am_in_the_applications_list_page
- visit(applicants_path)
- end
-
- def when_i_filter_by_a_status
- select "Initial checks", from: "status"
- click_button "Search"
- end
-
- def then_i_should_not_see_the_download_button
- expect(page).not_to have_link("Download QA CSV")
- end
-
- def then_i_should_see_the_download_button
- expect(page).to have_link("Download QA CSV")
- end
-
- def when_i_download_the_csv
- click_link "Download QA CSV"
- end
-
- def when_i_download_the_csv_again
- when_i_download_the_csv
- end
-
- def then_all_applications_should_be_marked_as_qa
- Application.all.each do |app|
- expect(app.reload.qa?).to be(true)
- end
- end
-
- def then_csv_should_be_empty
- expect(page.body.lines.count).to eq(1)
- end
-end
diff --git a/spec/features/admin_console/reports_spec.rb b/spec/features/admin_console/reports_spec.rb
index 41e5aec7..f01b734e 100644
--- a/spec/features/admin_console/reports_spec.rb
+++ b/spec/features/admin_console/reports_spec.rb
@@ -29,6 +29,22 @@
then_the_payroll_data_csv_report_is_downloaded
end
+ it "exports Application CSV" do
+ given_i_am_signed_as_an_admin
+ when_i_am_in_the_reports_page
+ and_i_click_on_the_applications_csv_link
+
+ then_the_applications_csv_report_is_downloaded
+ end
+
+ it "exports Qa report CSV" do
+ given_i_am_signed_as_an_admin
+ when_i_am_in_the_reports_page
+ and_i_click_on_the_qa_report_csv_button
+
+ then_the_qa_report_csv_report_is_downloaded
+ end
+
private
def then_the_standing_data_csv_report_is_downloaded
@@ -49,6 +65,18 @@ def then_the_payroll_data_csv_report_is_downloaded
expect(page.response_headers["Content-Disposition"]).to match(/filename="Payroll-Report.*/)
end
+ def then_the_applications_csv_report_is_downloaded
+ expect(page.response_headers["Content-Type"]).to match(/text\/csv/)
+ expect(page.response_headers["Content-Disposition"]).to include "attachment"
+ expect(page.response_headers["Content-Disposition"]).to match(/filename="Applications-Report.*/)
+ end
+
+ def then_the_qa_report_csv_report_is_downloaded
+ expect(page.response_headers["Content-Type"]).to match(/text\/csv/)
+ expect(page.response_headers["Content-Disposition"]).to include "attachment"
+ expect(page.response_headers["Content-Disposition"]).to match(/filename="QA-Report-initial_checks*/)
+ end
+
def and_i_click_on_the_home_office_csv_link
within ".home-office" do
click_on "Download"
@@ -67,6 +95,18 @@ def and_i_click_on_the_payroll_data_csv_link
end
end
+ def and_i_click_on_the_applications_csv_link
+ within ".applications" do
+ click_on "Download"
+ end
+ end
+
+ def and_i_click_on_the_qa_report_csv_button
+ within ".applications-qa" do
+ click_on "Download"
+ end
+ end
+
def when_i_am_in_the_reports_page
visit reports_path
end
diff --git a/spec/services/report_spec.rb b/spec/services/report_spec.rb
new file mode 100644
index 00000000..046ad024
--- /dev/null
+++ b/spec/services/report_spec.rb
@@ -0,0 +1,76 @@
+require "rails_helper"
+
+RSpec.describe Report do
+ subject(:report) { described_class }
+
+ describe "registered reports" do
+ subject(:registered_reports) { described_class::REGISTERED_REPORTS }
+
+ let(:expected_ids) do
+ %i[home_office standing_data payroll applications qa]
+ end
+
+ let(:expected_classes) do
+ [
+ Reports::HomeOffice,
+ Reports::StandingData,
+ Reports::Payroll,
+ Reports::Applications,
+ Reports::QaReport,
+ ]
+ end
+
+ it { expect(registered_reports.keys).to match_array(expected_ids) }
+ it { expect(registered_reports.values).to match_array(expected_classes) }
+ end
+
+ describe ".call" do
+ subject(:service) { described_class.new(report_id, status:) }
+
+ let(:report_id) { "qa" }
+ let(:status) { "initial_checks" }
+
+ context "report_name" do
+ it { expect(service.report_name).to eq("Reports::qareport") }
+ end
+
+ context "filename" do
+ include ActiveSupport::Testing::TimeHelpers
+ it "returns the name of the Report" do
+ frozen_time = Time.zone.local(2023, 7, 17, 12, 30, 45)
+ travel_to frozen_time do
+ expected_name = "QA-Report-initial_checks-2023_07_17-12_30_45.csv"
+
+ expect(service.filename).to eq(expected_name)
+ end
+ end
+ end
+
+ # rubocop:disable RSpec/VerifiedDoubles
+ context "qa report data" do
+ let(:report) { spy(Reports::QaReport) }
+
+ before do
+ allow(Reports::QaReport).to receive(:new).and_return(report)
+ service.data
+ end
+
+ it { expect(Reports::QaReport).to have_received(:new).with(kind_of(Array), status) }
+ it { expect(report).to have_received(:csv) }
+ end
+
+ context "other report data" do
+ let(:report_id) { "home_office" }
+ let(:report) { spy(Reports::HomeOffice) }
+
+ before do
+ allow(Reports::HomeOffice).to receive(:new).and_return(report)
+ service.data
+ end
+
+ it { expect(Reports::HomeOffice).to have_received(:new) }
+ it { expect(report).to have_received(:csv) }
+ end
+ # rubocop:enable RSpec/VerifiedDoubles
+ end
+end