diff --git a/app/jobs/reports/drop_off_report.rb b/app/jobs/reports/drop_off_report.rb new file mode 100644 index 00000000000..cfd382c74a3 --- /dev/null +++ b/app/jobs/reports/drop_off_report.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'reporting/drop_off_report' + +module Reports + class DropOffReport < BaseReport + REPORT_NAME = 'drop-off-report' + + attr_accessor :report_date + + def perform(report_date) + self.report_date = report_date + + subject = "Drop Off Report - #{report_date.to_date}" + JSON.parse(configs).each do |config| + reports = [report_maker(config['issuers']).as_emailable_reports] + config['emails'].each do |email| + ReportMailer.tables_report( + email: email, + subject: subject, + message: preamble, + reports: reports, + attachment_format: :csv, + ).deliver_now + end + end + end + + def preamble + <<~HTML.html_safe # rubocop:disable Rails/OutputSafety +

+ Drop Off Report +

+ HTML + end + + def configs + IdentityConfig.store.drop_off_report_config + end + + def report_maker(issuers) + Reporting::DropOffReport.new( + issuers: issuers, + time_range: report_date.all_month, + slice: 1.month, + ) + end + end +end diff --git a/config/application.yml.default b/config/application.yml.default index 228d7775106..0469cd05184 100644 --- a/config/application.yml.default +++ b/config/application.yml.default @@ -97,6 +97,7 @@ doc_auth_selfie_desktop_test_mode: false doc_auth_sdk_capture_orientation: '{"horizontal": 100, "vertical": 0}' doc_auth_supported_country_codes: '["US", "GU", "VI", "AS", "MP", "PR", "USA" ,"GUM", "VIR", "ASM", "MNP", "PRI"]' doc_capture_request_valid_for_minutes: 15 +drop_off_report_config: '[{"emails":["ursula@example.com"],"issuers":"urn:gov:gsa:openidconnect.profiles:sp:sso:agency_name:app_name"}]' email_from: no-reply@login.gov email_from_display_name: Login.gov email_registrations_per_ip_limit: 20 diff --git a/config/initializers/job_configurations.rb b/config/initializers/job_configurations.rb index 0d0d2368bf5..0a245848e7d 100644 --- a/config/initializers/job_configurations.rb +++ b/config/initializers/job_configurations.rb @@ -217,6 +217,12 @@ cron: cron_24h, args: -> { [Time.zone.yesterday.end_of_day] }, }, + # Monthly drop of report + drop_off_report: { + class: 'Reports::DropOffReport', + cron: cron_24h, + args: -> { [Time.zone.today] }, + }, }.compact end # rubocop:enable Metrics/BlockLength diff --git a/lib/identity_config.rb b/lib/identity_config.rb index de4ed292e4f..87e472b033b 100644 --- a/lib/identity_config.rb +++ b/lib/identity_config.rb @@ -130,6 +130,7 @@ def self.store config.add(:doc_auth_vendor_randomize_percent, type: :integer) config.add(:doc_capture_polling_enabled, type: :boolean) config.add(:doc_capture_request_valid_for_minutes, type: :integer) + config.add(:drop_off_report_config, type: :json) config.add(:domain_name, type: :string) config.add(:email_from, type: :string) config.add(:email_from_display_name, type: :string) diff --git a/spec/jobs/reports/drop_off_report_spec.rb b/spec/jobs/reports/drop_off_report_spec.rb new file mode 100644 index 00000000000..98c06221274 --- /dev/null +++ b/spec/jobs/reports/drop_off_report_spec.rb @@ -0,0 +1,54 @@ +require 'rails_helper' + +RSpec.describe Reports::DropOffReport do + let(:report_date) { Date.new(2023, 12, 12).in_time_zone('UTC') } + let(:report_config) do + '[{"emails":["ursula@example.com"], + "issuers":"urn:gov:gsa:openidconnect.profiles:sp:sso:agency_name:app_name"}]' + end + + before do + allow(IdentityConfig.store).to receive(:drop_off_report_config).and_return(report_config) + end + + describe '#perform' do + it 'gets a CSV from the report maker, and sends email' do + reports = Reporting::EmailableReport.new( + title: 'Drop Off Report', + table: [ + ['Term', 'Description', 'Definition', 'Calculated'], + ['1', '2', '3', '4'], + ], + filename: 'drop_off_report', + ) + + report_maker = double( + Reporting::DropOffReport, + to_csvs: 'I am a CSV, see', + as_emailable_reports: reports, + ) + + allow(subject).to receive(:report_maker).and_return(report_maker) + + expect(ReportMailer).to receive(:tables_report).once.with( + email: 'ursula@example.com', + subject: 'Drop Off Report - 2023-12-12', + reports: anything, + message: anything, + attachment_format: :csv, + ).and_call_original + + subject.perform(report_date) + end + end + + describe '#report_maker' do + it 'is a drop off report maker with the right time range' do + report_date = Date.new(2023, 12, 25).in_time_zone('UTC') + + subject.report_date = report_date + + expect(subject.report_maker([]).time_range).to eq(report_date.all_month) + end + end +end