From 6916e7e0b6ed5f08b9f25de480a920fbc60d0cd0 Mon Sep 17 00:00:00 2001 From: Alex Bradley Date: Thu, 9 May 2024 12:08:50 -0400 Subject: [PATCH 1/3] fix error in report job where nil email array returns false changelog: Internal, IdV, Fix error Identity report job with empty email array --- app/jobs/reports/identity_verification_report.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/reports/identity_verification_report.rb b/app/jobs/reports/identity_verification_report.rb index 8101c0c85e8..ff9539fe0d5 100644 --- a/app/jobs/reports/identity_verification_report.rb +++ b/app/jobs/reports/identity_verification_report.rb @@ -16,7 +16,7 @@ def perform(report_date) save_report(REPORT_NAME, csv, extension: 'csv') - if emails.empty? + if emails.compact.empty? Rails.logger.warn 'No email addresses received - Identity Verification Report NOT SENT' return false end From f5f865792eb6fef5f76b7bcb22ab249d419eb915 Mon Sep 17 00:00:00 2001 From: Alex Bradley Date: Fri, 10 May 2024 11:45:59 -0400 Subject: [PATCH 2/3] add regression test for job --- app/jobs/reports/identity_verification_report.rb | 4 ++-- spec/jobs/reports/identity_verification_report_spec.rb | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/jobs/reports/identity_verification_report.rb b/app/jobs/reports/identity_verification_report.rb index ff9539fe0d5..e3c335649f5 100644 --- a/app/jobs/reports/identity_verification_report.rb +++ b/app/jobs/reports/identity_verification_report.rb @@ -16,7 +16,7 @@ def perform(report_date) save_report(REPORT_NAME, csv, extension: 'csv') - if emails.compact.empty? + if emails.empty? Rails.logger.warn 'No email addresses received - Identity Verification Report NOT SENT' return false end @@ -54,7 +54,7 @@ def preamble end def emails - [IdentityConfig.store.team_ada_email] + [IdentityConfig.store.team_ada_email].compact end def reports diff --git a/spec/jobs/reports/identity_verification_report_spec.rb b/spec/jobs/reports/identity_verification_report_spec.rb index 6e0a6d4ad05..4f72028f556 100644 --- a/spec/jobs/reports/identity_verification_report_spec.rb +++ b/spec/jobs/reports/identity_verification_report_spec.rb @@ -5,11 +5,12 @@ before do allow(IdentityConfig.store).to receive(:s3_reports_enabled).and_return(true) - allow(IdentityConfig.store).to receive(:team_ada_email).and_return('ada@example.com') end describe '#perform' do it 'gets a CSV from the report maker, saves it to S3, and sends email to team' do + allow(IdentityConfig.store).to receive(:team_ada_email).and_return('ada@example.com') + reports = Reporting::EmailableReport.new( title: 'Identity Verification Metrics', @@ -61,6 +62,12 @@ subject.perform(report_date) end + + it 'does not send report in email if the email field is empty' do + allow(IdentityConfig.store).to receive(:team_ada_email).and_return(nil) + + expect(ReportMailer).to_not receive(:tables_report) + end end describe '#report_maker' do From 0a1a921c15d084a46860e8dca6f8273101163ecf Mon Sep 17 00:00:00 2001 From: Alex Bradley Date: Fri, 10 May 2024 14:10:39 -0400 Subject: [PATCH 3/3] actually perform the job in the test --- .../reports/identity_verification_report_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/jobs/reports/identity_verification_report_spec.rb b/spec/jobs/reports/identity_verification_report_spec.rb index 4f72028f556..3303cf97d9d 100644 --- a/spec/jobs/reports/identity_verification_report_spec.rb +++ b/spec/jobs/reports/identity_verification_report_spec.rb @@ -66,7 +66,21 @@ it 'does not send report in email if the email field is empty' do allow(IdentityConfig.store).to receive(:team_ada_email).and_return(nil) + report_maker = double( + Reporting::IdentityVerificationReport, + to_csv: 'I am a CSV, see', + identity_verification_emailable_report: 'I am a report', + ) + allow(subject).to receive(:report_maker).and_return(report_maker) + expect(subject).to receive(:save_report).with( + 'identity-verification-report', + 'I am a CSV, see', + extension: 'csv', + ) + expect(ReportMailer).to_not receive(:tables_report) + + subject.perform(report_date) end end