]> git.openstreetmap.org Git - rails.git/blob - test/jobs/trace_importer_job_test.rb
Fix text direction for traditional chinese
[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       perform_enqueued_jobs do
16         TraceImporterJob.perform_now(trace)
17       end
18     end
19
20     assert_performed_jobs 1
21
22     email = ActionMailer::Base.deliveries.last
23     assert_equal trace.user.email, email.to[0]
24     assert_match(/success/, email.subject)
25
26     ActionMailer::Base.deliveries.clear
27   end
28
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)
32
33     gpx = Minitest::Mock.new
34     def gpx.actual_points
35       0
36     end
37
38     trace.stub(:import, gpx) do
39       perform_enqueued_jobs do
40         TraceImporterJob.perform_now(trace)
41       end
42     end
43
44     assert_performed_jobs 1
45
46     email = ActionMailer::Base.deliveries.last
47     assert_equal trace.user.email, email.to[0]
48     assert_match(/failure/, email.subject)
49
50     ActionMailer::Base.deliveries.clear
51   end
52
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)
59       end
60     end
61
62     assert_performed_jobs 1
63
64     email = ActionMailer::Base.deliveries.last
65     assert_equal trace.user.email, email.to[0]
66     assert_match(/failure/, email.subject)
67
68     ActionMailer::Base.deliveries.clear
69   end
70 end