diff --git a/app/jobs/import_student_loans_data_job.rb b/app/jobs/import_student_loans_data_job.rb index 106d6f72eb..b26f672823 100644 --- a/app/jobs/import_student_loans_data_job.rb +++ b/app/jobs/import_student_loans_data_job.rb @@ -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 diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb index b4aee90c6c..217b8a79e7 100644 --- a/app/mailers/admin_mailer.rb +++ b/app/mailers/admin_mailer.rb @@ -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 diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 9b909f23df..e8e0989982 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -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, diff --git a/spec/jobs/import_student_loans_data_job_spec.rb b/spec/jobs/import_student_loans_data_job_spec.rb index 33a3433777..5e497cdc2d 100644 --- a/spec/jobs/import_student_loans_data_job_spec.rb +++ b/spec/jobs/import_student_loans_data_job_spec.rb @@ -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 @@ -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 @@ -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)