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)
26 ActionMailer::Base.deliveries.clear
29 def test_failure_notification
30 # Check that the user gets a failure notification when the trace has no valid points
31 trace = create(:trace)
33 gpx = Minitest::Mock.new
38 trace.stub(:import, gpx) do
39 perform_enqueued_jobs do
40 TraceImporterJob.perform_now(trace)
44 assert_performed_jobs 1
46 email = ActionMailer::Base.deliveries.last
47 assert_equal trace.user.email, email.to[0]
48 assert_match(/failure/, email.subject)
50 ActionMailer::Base.deliveries.clear
53 def test_error_notification
54 # Check that the user gets a failure notification when something goes badly wrong
55 trace = create(:trace)
56 trace.stub(:import, -> { raise }) do
57 perform_enqueued_jobs do
58 TraceImporterJob.perform_now(trace)
62 assert_performed_jobs 1
64 email = ActionMailer::Base.deliveries.last
65 assert_equal trace.user.email, email.to[0]
66 assert_match(/failure/, email.subject)
68 ActionMailer::Base.deliveries.clear