Commit 38f5180454d2b225f430442ad5518ad09a6ca38c
1 parent
55430b7e
adds some tests for notify mentioned users job
Showing
2 changed files
with
97 additions
and
1 deletions
Show diff stats
app/helpers/mention_helper.rb
... | ... | @@ -0,0 +1,96 @@ |
1 | +require_relative "../test_helper" | |
2 | + | |
3 | +class NotifyMentionedUsersJobTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @person1 = fast_create(Person, :identifier => "tester") | |
7 | + @person2 = fast_create(Person, :identifier => "friend") | |
8 | + @person3 = fast_create(Person, :identifier => "third") | |
9 | + @person1.add_friend @person2 | |
10 | + @person1.add_friend @person3 | |
11 | + | |
12 | + process_delayed_job_queue | |
13 | + ProfileFollower.delete_all | |
14 | + ActionTrackerNotification.delete_all | |
15 | + end | |
16 | + | |
17 | + should 'create notify mentioned uses job if scrap content has mentioned users' do | |
18 | + s = Scrap.new | |
19 | + s.sender = @person1 | |
20 | + s.receiver = @person2 | |
21 | + s.content = "Run @third, run!!!" | |
22 | + s.save! | |
23 | + | |
24 | + action_tracker = ActionTracker::Record.create(:user => @person1, :target => s, | |
25 | + :verb => 'notify_mentioned_users', | |
26 | + :params => {"content" => s.content, "url"=>s.receiver.url}) | |
27 | + | |
28 | + job = NotifyMentionedUsersJob.new(action_tracker.id) | |
29 | + job.perform | |
30 | + process_delayed_job_queue | |
31 | + | |
32 | + assert_equal 2, ActionTrackerNotification.count | |
33 | + | |
34 | + notification = ActionTrackerNotification.find_by profile_id: @person3.id | |
35 | + assert_equal action_tracker, notification.action_tracker | |
36 | + end | |
37 | + | |
38 | + should 'create notify mentioned uses job if comment body has mentioned users' do | |
39 | + a = fast_create(Article, :profile_id => @person1.id, :name => "Zombiesss") | |
40 | + | |
41 | + comment = Comment.create!(:author => @person1, :body => 'Run @third, run!!!', :source => a) | |
42 | + action_tracker = ActionTracker::Record.create(:user => @person1, :target => comment, | |
43 | + :verb => 'notify_mentioned_users', | |
44 | + :params => {"body" => comment.body, "url" => comment.url}) | |
45 | + | |
46 | + job = NotifyMentionedUsersJob.new(action_tracker.id) | |
47 | + job.perform | |
48 | + process_delayed_job_queue | |
49 | + | |
50 | + assert_equal 1, ActionTrackerNotification.count | |
51 | + | |
52 | + notification = ActionTrackerNotification.find_by profile_id: @person3.id | |
53 | + assert_equal action_tracker, notification.action_tracker | |
54 | + end | |
55 | + | |
56 | + should 'not create notify mentioned users job if scrap content has no mentioned users' do | |
57 | + s = Scrap.new | |
58 | + s.sender = @person1 | |
59 | + s.receiver = @person2 | |
60 | + s.content = "Run third, run!!!" | |
61 | + s.save! | |
62 | + | |
63 | + action_tracker = ActionTracker::Record.create(:user => @person1, :target => s, | |
64 | + :verb => 'notify_mentioned_users', | |
65 | + :params => {"content" => s.content, "url"=>s.receiver.url}) | |
66 | + | |
67 | + job = NotifyMentionedUsersJob.new(action_tracker.id) | |
68 | + job.perform | |
69 | + process_delayed_job_queue | |
70 | + | |
71 | + assert_equal 1, ActionTrackerNotification.count | |
72 | + assert_not_includes ActionTrackerNotification.all.map{|a|a.action_tracker.verb}, "notify_mentioned_users" | |
73 | + end | |
74 | + | |
75 | + should 'not create notify mentioned users job if comment body has no mentioned users' do | |
76 | + a = fast_create(Article, :profile_id => @person1.id, :name => "Zombiesss") | |
77 | + | |
78 | + comment = Comment.create!(:author => @person1, :body => 'Run third, run!!!', :source => a) | |
79 | + action_tracker = ActionTracker::Record.create(:user => @person1, :target => comment, | |
80 | + :verb => 'notify_mentioned_users', | |
81 | + :params => {"body" => comment.body, "url" => comment.url}) | |
82 | + | |
83 | + job = NotifyMentionedUsersJob.new(action_tracker.id) | |
84 | + job.perform | |
85 | + process_delayed_job_queue | |
86 | + | |
87 | + assert_empty ActionTrackerNotification.all | |
88 | + end | |
89 | + | |
90 | + should 'not create notification from mention if the mentioned users are also followers' do | |
91 | + end | |
92 | + | |
93 | + should 'not show notification from mention on the authors wall' do | |
94 | + end | |
95 | + | |
96 | +end | ... | ... |