@@ -373,13 +373,18 @@ def test_post_grades
373373 body : { "{\" GradeObjectType\" :1,\" PointsNumerator\" :60}" => nil } ,
374374 ) . to_return ( status : 200 , headers : { } )
375375
376- d2l = D2lAssessmentMapping . create ( unit : unit , org_unit_id : '12345' )
376+ D2lAssessmentMapping . create ( unit : unit , org_unit_id : '12345' )
377377 UserOauthToken . create ( user : unit . main_convenor_user , provider : :d2l , token : 'test' , expires_at : 30 . minutes . from_now )
378378
379379 # result = D2lIntegration.post_grades(unit, unit.main_convenor_user)
380380 D2lPostGradesJob . perform_async ( unit . id , unit . main_convenor_user . id )
381381 D2lPostGradesJob . drain
382382
383+ assert_equal 1 , ActionMailer ::Base . deliveries . count
384+ mail = ActionMailer ::Base . deliveries . first
385+ assert_equal [ unit . main_convenor_user . email ] , mail . to
386+ assert_includes mail . body . parts [ 0 ] . body . raw_source , "has completed"
387+
383388 assert File . exist? ( D2lIntegration . result_file_path ( unit ) )
384389 result = File . read ( D2lIntegration . result_file_path ( unit ) ) . split ( "\n " )
385390
@@ -404,6 +409,19 @@ def test_post_grades
404409 assert_includes result [ 1 ] , "Success,#{ p1 . student . student_id } ,#{ p1 . grade } ,Posted grade for #{ p1 . student . username } "
405410 end
406411
412+ def test_mail_on_fail
413+ unit = FactoryBot . create ( :unit , with_students : false )
414+ D2lAssessmentMapping . create ( unit : unit , org_unit_id : '54321' )
415+
416+ D2lPostGradesJob . perform_async ( unit . id , unit . main_convenor_user . id )
417+ D2lPostGradesJob . drain
418+
419+ assert_equal 1 , ActionMailer ::Base . deliveries . count
420+ mail = ActionMailer ::Base . deliveries . first
421+ assert_equal [ unit . main_convenor_user . email ] , mail . to
422+ assert_includes mail . body . raw_source , "has failed"
423+ end
424+
407425 def test_request_grade_transfer
408426 unit = FactoryBot . create ( :unit , with_students : false )
409427
0 commit comments