From c84088e664060b7caa1887455f8da97c08584936 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Mon, 9 Dec 2024 14:41:32 +0000 Subject: [PATCH] Add reports controller Adds the controller and views for downloading the ops reports. --- app/controllers/admin/reports_controller.rb | 27 ++++++ app/views/admin/claims/index.html.erb | 1 + app/views/admin/reports/index.html.erb | 17 ++++ config/routes.rb | 1 + spec/features/admin/reports_spec.rb | 102 ++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 app/controllers/admin/reports_controller.rb create mode 100644 app/views/admin/reports/index.html.erb create mode 100644 spec/features/admin/reports_spec.rb diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb new file mode 100644 index 000000000..5081b148e --- /dev/null +++ b/app/controllers/admin/reports_controller.rb @@ -0,0 +1,27 @@ +module Admin + class ReportsController < BaseAdminController + before_action :ensure_service_operator + + def index + end + + def show + respond_to do |format| + format.csv do + send_data(report.to_csv, filename: report.filename) + end + end + end + + private + + def report + @report ||= case params[:name] + when "fe-approved-claims-with-failing-provider-verification" + Reports::FeApprovedClaimsWithFailingProviderVerification.new + else + raise ActiveRecord::RecordNotFound + end + end + end +end diff --git a/app/views/admin/claims/index.html.erb b/app/views/admin/claims/index.html.erb index 64f5c251f..d872447b0 100644 --- a/app/views/admin/claims/index.html.erb +++ b/app/views/admin/claims/index.html.erb @@ -16,6 +16,7 @@ <%= link_to "Upload TPS data", new_admin_tps_data_upload_path, class: "govuk-button govuk-button--secondary", data: { module: "govuk-button" }, role: :button %> <%= link_to "Upload SLC data", new_admin_student_loans_data_upload_path, class: "govuk-button govuk-button--secondary", data: { module: "govuk-button" }, role: :button %> <%= link_to "Upload fraud prevention data", new_admin_fraud_risk_csv_upload_path, class: "govuk-button govuk-button--secondary", data: { module: "govuk-button" }, role: :button %> + <%= link_to "Reports", admin_reports_path, class: "govuk-button govuk-button--secondary", data: { module: "govuk-button" }, role: :button %> <%= render "allocations_form" %> diff --git a/app/views/admin/reports/index.html.erb b/app/views/admin/reports/index.html.erb new file mode 100644 index 000000000..8a9d58e73 --- /dev/null +++ b/app/views/admin/reports/index.html.erb @@ -0,0 +1,17 @@ +<% content_for :back_link do %> + <%= govuk_back_link href: admin_claims_path %> +<% end %> + +
+
+

+ Reports +

+ + <%= govuk_button_link_to( + "FE TRI approved claims whereby the provider check status is 'failed'", + admin_report_path("fe-approved-claims-with-failing-provider-verification", format: :csv), + secondary: true + ) %> +
+
diff --git a/config/routes.rb b/config/routes.rb index 3d62b8869..0b94fe93e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -133,6 +133,7 @@ def matches?(request) resources :tps_data_uploads, only: [:new, :create] resources :fraud_risk_csv_uploads, only: [:new, :create] resource :fraud_risk_csv_download, only: :show + resources :reports, only: [:index, :show], param: :name resources :payroll_runs, only: [:index, :new, :create, :show, :destroy] do resources :payment_confirmation_report_uploads, only: [:new, :create] diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb new file mode 100644 index 000000000..93ba372d4 --- /dev/null +++ b/spec/features/admin/reports_spec.rb @@ -0,0 +1,102 @@ +require "rails_helper" + +RSpec.describe "Admin reports" do + around do |example| + travel_to Date.new(2024, 12, 6) do + example.run + end + end + + describe "Approved FE claims with failing provider verification" do + it "returns a CSV report" do + claim = create( + :claim, + :approved, + policy: Policies::FurtherEducationPayments, + first_name: "Elizabeth", + surname: "Hoover", + qa_required: true, + eligibility_attributes: { + award_amount: 2_000, + contract_type: "permanent", + verification: { + assertions: [ + { + name: "contract_type", + outcome: true + }, + { + name: "teaching_responsibilities", + outcome: true + }, + { + name: "further_education_teaching_start_year", + outcome: true + }, + { + name: "teaching_hours_per_week", + outcome: true + }, + { + name: "half_teaching_hours", + outcome: false + }, + { + name: "subjects_taught", + outcome: false + }, + { + name: "subject_to_formal_performance_action", + outcome: true + }, + { + name: "subject_to_disciplinary_action", + outcome: true + } + ] + } + } + ) + + create( + :task, + :failed, + name: "provider_verification", + claim: claim + ) + + sign_in_as_service_operator + + visit admin_claims_path + + click_on "Reports" + + click_on( + "FE TRI approved claims whereby the provider check status is 'failed'" + ) + + csv_data = page.body + + csv = CSV.parse(csv_data, headers: true) + row = csv.first + + expect(row.fetch("Claim reference")).to eq(claim.reference) + expect(row.fetch("Full name")).to eq("Elizabeth Hoover") + expect(row.fetch("Claim amount")).to eq("£2,000") + expect(row.fetch("Claim status")).to eq("Approved awaiting QA") + expect(row.fetch("Decision date")).to eq("06/12/2024") + expect(row.fetch("Decision agent")).to eq("Aaron Admin") + expect(row.fetch("Contract of employment")).to eq("Yes") + expect(row.fetch("Teaching responsibilities")).to eq("Yes") + expect(row.fetch("First 5 years of teaching")).to eq("Yes") + expect(row.fetch("One full term")).to eq("N/A") + expect(row.fetch("Timetabled teaching hours")).to eq("Yes") + expect(row.fetch("Age range taught")).to eq("No") + expect(row.fetch("Subject")).to eq("No") + expect(row.fetch("Course")).to eq("??") + expect(row.fetch("2.5 hours weekly teaching")).to eq("N/A") + expect(row.fetch("Performance")).to eq("Yes") + expect(row.fetch("Disciplinary")).to eq("Yes") + end + end +end