]> git.openstreetmap.org Git - rails.git/blob - test/jobs/trace_importer_job_test.rb
Merge remote-tracking branch 'upstream/pull/4482'
[rails.git] / test / jobs / trace_importer_job_test.rb
1 require "test_helper"
2 require "minitest/mock"
3
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
7     trace = create(:trace)
8
9     gpx = Minitest::Mock.new
10     def gpx.actual_points
11       5
12     end
13
14     trace.stub(:import, gpx) do
15       TraceImporterJob.perform_now(trace)
16     end
17
18     email = ActionMailer::Base.deliveries.last
19     assert_equal trace.user.email, email.to[0]
20     assert_match(/success/, email.subject)
21
22     ActionMailer::Base.deliveries.clear
23   end
24
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)
28
29     gpx = Minitest::Mock.new
30     def gpx.actual_points
31       0
32     end
33
34     trace.stub(:import, gpx) do
35       TraceImporterJob.perform_now(trace)
36     end
37
38     email = ActionMailer::Base.deliveries.last
39     assert_equal trace.user.email, email.to[0]
40     assert_match(/failure/, email.subject)
41
42     ActionMailer::Base.deliveries.clear
43   end
44
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)
50     end
51
52     email = ActionMailer::Base.deliveries.last
53     assert_equal trace.user.email, email.to[0]
54     assert_match(/failure/, email.subject)
55
56     ActionMailer::Base.deliveries.clear
57   end
58 end