Skip to content

Commit

Permalink
CAPT-1411 add success/error emails for SLC CSV uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
kenfodder committed Nov 25, 2024
1 parent 9e04734 commit beb7f53
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/jobs/import_student_loans_data_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class ImportStudentLoansDataJob < FileImporterJob
StudentLoansData.delete_all
AnalyticsImporter.import(StudentLoansData)
end
notify_with AdminMailer, success: :slc_csv_processing_success, failure: :slc_csv_processing_error
end
16 changes: 16 additions & 0 deletions app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@ def tps_csv_processing_error(email_address)
reply_to_id: GENERIC_NOTIFY_REPLY_TO_ID
)
end

def slc_csv_processing_success(email_address)
template_mail(
SLC_CSV_PROCESSING_SUCCESS_ID,
to: email_address,
reply_to_id: GENERIC_NOTIFY_REPLY_TO_ID
)
end

def slc_csv_processing_error(email_address)
template_mail(
SLC_CSV_PROCESSING_ERROR_ID,
to: email_address,
reply_to_id: GENERIC_NOTIFY_REPLY_TO_ID
)
end
end
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class ApplicationMailer < Mail::Notify::Mailer
CENSUS_CSV_PROCESSING_SUCCESS_ID = "81862fc7-f842-4f85-a6e7-63dffb931999".freeze
TPS_CSV_PROCESSING_ERROR_ID = "f29753a1-5b9c-4e37-8b5a-43150b3bca64".freeze
TPS_CSV_PROCESSING_SUCCESS_ID = "5d817617-06c3-4df0-b228-f3d25510701e".freeze
SLC_CSV_PROCESSING_ERROR_ID = "f40fa946-963b-4ddd-a896-7c1d6bd7da12".freeze
SLC_CSV_PROCESSING_SUCCESS_ID = "ee4b950a-28bd-417f-a00a-bc592f18f93b".freeze

STUDENT_LOANS = {
CLAIM_RECEIVED_NOTIFY_TEMPLATE_ID: "f9e39fcd-301a-4427-9159-6831fd484e39".freeze,
Expand Down
18 changes: 18 additions & 0 deletions spec/jobs/import_student_loans_data_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
end

context "csv data processes successfully" do
let(:mail) { AdminMailer.slc_csv_processing_success(file_upload.uploaded_by.email) }

it "imports student loans data" do
expect { upload }.to change(StudentLoansData, :count).by(1)
end
Expand All @@ -29,9 +31,18 @@
it "enqueues StudentLoanPlanCheckJob" do
expect { upload }.to have_enqueued_job(StudentLoanPlanCheckJob)
end

it "sends a success email" do
upload

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(mail.template_id).to eq "ee4b950a-28bd-417f-a00a-bc592f18f93b"
end
end

context "csv data encounters an error" do
let(:mail) { AdminMailer.slc_csv_processing_error(file_upload.uploaded_by.email) }

before do
allow(StudentLoansData).to receive(:insert_all).and_raise(ActiveRecord::RecordInvalid)
end
Expand All @@ -54,6 +65,13 @@
expect { upload }.not_to have_enqueued_job(StudentLoanPlanCheckJob)
end

it "sends a error email" do
upload

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(mail.template_id).to eq "f40fa946-963b-4ddd-a896-7c1d6bd7da12"
end

describe "dfe-analytics syncing" do
it "invokes the relevant import entity job" do
expect(AnalyticsImporter).to receive(:import).with(StudentLoansData)
Expand Down

0 comments on commit beb7f53

Please sign in to comment.