Skip to content
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
49 changes: 49 additions & 0 deletions app/jobs/reports/drop_off_report.rb
Original file line number Diff line number Diff line change
@@ -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
<h2>
Drop Off Report
</h2>
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
1 change: 1 addition & 0 deletions config/application.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/job_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/identity_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 54 additions & 0 deletions spec/jobs/reports/drop_off_report_spec.rb
Original file line number Diff line number Diff line change
@@ -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