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