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 TraceImporterJob.perform_now(trace)
18 email = ActionMailer::Base.deliveries.last
19 assert_equal trace.user.email, email.to[0]
20 assert_match(/success/, email.subject)
22 ActionMailer::Base.deliveries.clear
25 def test_failure_notification
26 # Check that the user gets a failure notification when the trace has no valid points
27 trace = create(:trace)
29 gpx = Minitest::Mock.new
34 trace.stub(:import, gpx) do
35 TraceImporterJob.perform_now(trace)
38 email = ActionMailer::Base.deliveries.last
39 assert_equal trace.user.email, email.to[0]
40 assert_match(/failure/, email.subject)
42 ActionMailer::Base.deliveries.clear
45 def test_error_notification
46 # Check that the user gets a failure notification when something goes badly wrong
47 trace = create(:trace)
48 trace.stub(:import, -> { raise }) do
49 TraceImporterJob.perform_now(trace)
52 email = ActionMailer::Base.deliveries.last
53 assert_equal trace.user.email, email.to[0]
54 assert_match(/failure/, email.subject)
56 ActionMailer::Base.deliveries.clear