Skip to content

Commit c4209b2

Browse files
astrogecoshilenpatel1
authored andcommitted
Add refactor for 'plain' verification report
See ##12670
1 parent 4523a40 commit c4209b2

File tree

3 files changed

+149
-168
lines changed

3 files changed

+149
-168
lines changed

app/jobs/reports/irs_verification_report.rb

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
module Reports
77
class IrsVerificationReport < BaseReport
8-
REPORT_NAME = 'irs-verification-report'
8+
# REPORT_NAME = 'sp-verification-report'
99

10-
attr_reader :report_date, :report_receiver
10+
attr_reader :report_date, :report_receiver, :report_name, :report_title
1111

1212
def initialize(init_date = nil, init_receiver = :internal, *args, **rest)
1313
@report_date = init_date
@@ -19,24 +19,40 @@ def perform(perform_date = Time.zone.yesterday.end_of_day, perform_receiver = :i
1919
@report_date = perform_date
2020
@report_receiver = perform_receiver.to_sym
2121

22-
email_addresses = emails
22+
IdentityConfig.store.sp_verification_report_configs.each do |report_config|
23+
send_report(report_config)
24+
end
25+
end
26+
27+
def send_report(report_config)
28+
issuers = report_config['issuers']
29+
agency_abbreviation = report_config['agency_abbreviation']
30+
partner_emails = report_config['partner_emails']
31+
internal_emails = report_config['internal_emails']
32+
33+
@report_name = "#{agency_abbreviation.downcase}_verification_report"
34+
@report_title = "#{agency_abbreviation} Verification Report"
35+
36+
email_addresses = emails(internal_emails, partner_emails)
2337
to_emails = email_addresses[:to].select(&:present?)
2438
bcc_emails = email_addresses[:bcc].select(&:present?)
2539

2640
if to_emails.empty? && bcc_emails.empty?
27-
Rails.logger.warn 'No email addresses received - IRS Verification Report NOT SENT'
41+
Rails.logger.warn "No email addresses received - #{@report_title} NOT SENT"
2842
return false
2943
end
3044

31-
reports.each do |report|
45+
emailable_reports = reports(issuers, agency_abbreviation)
46+
47+
emailable_reports.each do |report|
3248
upload_to_s3(report.table, report_name: report.filename)
3349
end
3450

3551
ReportMailer.tables_report(
3652
to: to_emails,
3753
bcc: bcc_emails,
38-
subject: "IRS Verification Report - #{report_date.to_date}",
39-
reports: reports,
54+
subject: "#{@report_title} - #{report_date.to_date}",
55+
reports: emailable_reports,
4056
message: preamble,
4157
attachment_format: :csv,
4258
).deliver_now
@@ -61,41 +77,39 @@ def preamble(env: Identity::Hostdata.env || 'local')
6177
ERB
6278
end
6379

64-
def reports
65-
@reports ||= irs_verification_report.as_emailable_reports
80+
def reports(issuers, agency_abbreviation)
81+
sp_verification_report(issuers, agency_abbreviation).as_emailable_reports
6682
end
6783

6884
def previous_week_range
6985
@report_date.beginning_of_week(:sunday).prev_occurring(:sunday).all_week(:sunday)
7086
end
7187

72-
def irs_verification_report
73-
@irs_verification_report ||= Reporting::IrsVerificationReport.new(
88+
def sp_verification_report(issuers, agency_abbreviation)
89+
Reporting::IrsVerificationReport.new(
7490
time_range: previous_week_range,
75-
issuers: IdentityConfig.store.irs_verification_report_issuers || [],
91+
issuers: issuers || [],
92+
agency_abbreviation: agency_abbreviation,
7693
)
7794
end
7895

79-
def emails
80-
internal_emails = [*IdentityConfig.store.team_daily_reports_emails].select(&:present?)
81-
irs_emails = [*IdentityConfig.store.irs_verification_report_config].select(&:present?)
82-
83-
if report_receiver == :both && irs_emails.empty?
96+
def emails(internal_emails, partner_emails)
97+
if report_receiver == :both && partner_emails.empty?
8498
Rails.logger.warn(
85-
'IRS Verification Report: recipient is :both ' \
86-
'but no external email specified',
99+
"#{@report_title}: recipient is :both " \
100+
"but no external email specified",
87101
)
88102
end
89103

90-
if report_receiver == :both && irs_emails.present?
91-
{ to: irs_emails, bcc: internal_emails }
104+
if report_receiver == :both && partner_emails.present?
105+
{ to: partner_emails, bcc: internal_emails }
92106
else
93107
{ to: internal_emails, bcc: [] }
94108
end
95109
end
96110

97111
def upload_to_s3(report_body, report_name: nil)
98-
_latest, path = generate_s3_paths(REPORT_NAME, 'csv', subname: report_name, now: report_date)
112+
_latest, path = generate_s3_paths(@report_name, 'csv', subname: report_name, now: report_date)
99113

100114
if bucket_name.present?
101115
upload_file_to_s3_bucket(

config/initializers/job_configurations.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@
195195
cron: cron_every_monday_5am,
196196
args: -> { [Time.zone.yesterday.end_of_day, :both] },
197197
},
198+
sp_weekly_verification_report: {
199+
class: 'Reports::IrsVerificationReport',
200+
cron: cron_every_monday_5am,
201+
args: -> { [Time.zone.yesterday.end_of_day, :internal] },
202+
},
198203
# Send Identity Verification report to S3
199204
identity_verification_report: {
200205
class: 'Reports::IdentityVerificationReport',

0 commit comments

Comments
 (0)