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)
55 assert_no_match(/Start tag expected/, email.text_part.body.to_s, "should not include parser error")
56 assert_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should include stack backtrace")
58 ActionMailer::Base.deliveries.clear
61 def test_parse_error_notification
62 trace = create(:trace, :inserted => false, :fixture => "jpg")
63 Rails.logger.silence do
64 TraceImporterJob.perform_now(trace)
67 email = ActionMailer::Base.deliveries.last
68 assert_equal trace.user.email, email.to[0]
69 assert_match(/failure/, email.subject)
70 assert_match(/Start tag expected/, email.text_part.body.to_s, "should include parser error")
71 assert_no_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should not include stack backtrace")
73 ActionMailer::Base.deliveries.clear
76 def test_gz_parse_error_notification
77 trace = create(:trace, :inserted => false, :fixture => "jpg.gz")
78 Rails.logger.silence do
79 TraceImporterJob.perform_now(trace)
82 email = ActionMailer::Base.deliveries.last
83 assert_equal trace.user.email, email.to[0]
84 assert_match(/failure/, email.subject)
85 assert_match(/Start tag expected/, email.text_part.body.to_s, "should include parser error")
86 assert_no_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should not include stack backtrace")
88 ActionMailer::Base.deliveries.clear