Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP-5877: Add ApplicationDigest csv to admin report #7724

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions app/controllers/admin/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ def download_user_feedbacks_report
end
end

def download_application_digest_report
expires_now
respond_to do |format|
format.csv do
tempfile = Tempfile.new("application_digest_report")
headers = ApplicationDigest.first.attributes.keys - %w[id created_at updated_at]

CSV.open(tempfile, "w", write_headers: true, headers: headers) do |csv|
ApplicationDigest.order(created_at: :desc).each do |record|
csv << record.attributes.slice(*headers).values
end
end

send_data tempfile.read, filename: "application_digest_#{timestamp}.csv", content_type: "text/csv"
end
end
end

def timestamp
Time.current.strftime("%FT%T")
end
Expand All @@ -69,19 +87,25 @@ def reports
report_title: "Application Details report ",
report_link: { href: "https://dsdmoj.atlassian.net/wiki/x/JwBOKQE", text: "About this report (opens in new tab)", class: "govuk-link govuk-link--no-visited-state", rel: "noreferrer noopener", target: "_blank" },
path: :admin_application_details_csv_path,
path_text: "Download CSV",
path_text: "Download <span class=\"govuk-visually-hidden\">application details</span>CSV".html_safe,
},
application_digest_download: {
report_title: "Application Digest report",
report_link: nil,
path: :admin_application_digest_csv_path,
path_text: "Download <span class=\"govuk-visually-hidden\">application digest</span>CSV".html_safe,
},
provider_download: {
report_title: "Provider email report",
report_link: nil,
path: :admin_provider_emails_csv_path,
path_text: "Download CSV",
path_text: "Download <span class=\"govuk-visually-hidden\">provider emails</span>CSV".html_safe,
},
user_feedback_download: {
report_title: "User feedback report",
report_link: nil,
path: :admin_user_feedbacks_csv_path,
path_text: "Download CSV",
path_text: "Download <span class=\"govuk-visually-hidden\">user feedback</span>CSV".html_safe,
},
}
end
Expand Down
4 changes: 3 additions & 1 deletion app/views/admin/reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
report[:report_link].present? ? govuk_link_to(report[:report_link][:text], report[:report_link][:href], class: report[:report_link][:class], rel: report[:report_link][:rel], target: report[:report_link][:target]) : ""
end
row.with_cell do
govuk_link_to(report[:path_text], __send__(report[:path], format: :csv))
govuk_link_to(__send__(report[:path], format: :csv)) do
report[:path_text]
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
get "admin_report_application_details", to: "reports#download_application_details_report", as: "application_details_csv"
get "admin_report_provider_emails", to: "reports#download_provider_emails_report", as: "provider_emails_csv"
get "admin_report_user_feedbacks", to: "reports#download_user_feedbacks_report", as: "user_feedbacks_csv"
get "admin_report_application_digest", to: "reports#download_application_digest_report", as: "application_digest_csv"
end

namespace "v1" do
Expand Down
24 changes: 24 additions & 0 deletions spec/requests/admin/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,28 @@
expect(response.body).to match(/My suggested improvement/)
end
end

describe "GET application digest" do
subject(:get_request) { get admin_application_digest_csv_path(format: :csv) }

before do
create(
:application_digest,
firm_name: "An Awesome Firm",
provider_username: "Joe Bloggs",
)
end

it "renders successfully" do
get_request
expect(response).to have_http_status(:ok)
end

it "sends the data" do
get_request
expect(response.body)
.to match(/^legal_aid_application_id,firm_name,provider_username,date_started,date_submitted,days_to_submission,use_ccms,matter_types,proceedings,passported,df_used,earliest_df_date,df_reported_date,working_days_to_report_df,working_days_to_submit_df,employed,hmrc_data_used,referred_to_caseworker,true_layer_path,bank_statements_path,true_layer_data,has_partner,contrary_interest,partner_dwp_challenge,applicant_age,non_means_tested,family_linked,family_linked_lead_or_associated,number_of_family_linked_applications,legal_linked,legal_linked_lead_or_associated,number_of_legal_linked_applications,no_fixed_address,biological_parent,parental_responsibility_agreement,parental_responsibility_court_order,child_subject,parental_responsibility_evidence,autogranted,ecct_routed/)
.and match(/An Awesome Firm,Joe Bloggs/)
end
end
end