2 require "minitest/mock"
4 class TraceImporterJobTest < ActiveJob::TestCase
5 def test_success_notification
6 # Check that the user gets a success notification when the trace has valid points
9 gpx = Minitest::Mock.new
14 trace.stub(:import, gpx) do
15 perform_enqueued_jobs do
16 TraceImporterJob.perform_now(trace)
20 assert_performed_jobs 1
22 email = ActionMailer::Base.deliveries.last
23 assert_equal trace.user.email, email.to[0]
24 assert_match(/success/, email.subject)
27 def test_failure_notification
28 # Check that the user gets a failure notification when the trace has no valid points
29 trace = create(:trace)
31 gpx = Minitest::Mock.new
36 trace.stub(:import, gpx) do
37 perform_enqueued_jobs do
38 TraceImporterJob.perform_now(trace)
42 assert_performed_jobs 1
44 email = ActionMailer::Base.deliveries.last
45 assert_equal trace.user.email, email.to[0]
46 assert_match(/failure/, email.subject)
49 def test_error_notification
50 # Check that the user gets a failure notification when something goes badly wrong
51 trace = create(:trace)
52 trace.stub(:import, -> { raise }) do
53 perform_enqueued_jobs do
54 TraceImporterJob.perform_now(trace)
58 assert_performed_jobs 1
60 email = ActionMailer::Base.deliveries.last
61 assert_equal trace.user.email, email.to[0]
62 assert_match(/failure/, email.subject)