mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Consolidate likes notifications. (#6879)
This commit is contained in:
@@ -250,6 +250,32 @@ describe Notification do
|
||||
end
|
||||
end
|
||||
|
||||
describe '.get_liked_by' do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
PostActionNotifier.enable
|
||||
end
|
||||
|
||||
it 'should return the right notifications' do
|
||||
expect(Notification.get_liked_by(user)).to eq([])
|
||||
|
||||
expect do
|
||||
PostAlerter.post_created(Fabricate(:basic_reply,
|
||||
user: user,
|
||||
topic: post.topic
|
||||
))
|
||||
|
||||
PostAction.act(user, post, PostActionType.types[:like])
|
||||
end.to change { Notification.count }.by(2)
|
||||
|
||||
expect(Notification.get_liked_by(user)).to contain_exactly(
|
||||
Notification.find_by(notification_type: Notification.types[:liked])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# pulling this out cause I don't want an observer
|
||||
|
||||
@@ -296,6 +296,74 @@ describe PostAction do
|
||||
expect(Notification.exists?(id: notification.id)).to eq(false)
|
||||
end
|
||||
|
||||
describe 'likes consolidation' do
|
||||
let(:liker) { Fabricate(:user) }
|
||||
let(:likee) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
SiteSetting.likes_notification_consolidation_threshold = 3
|
||||
end
|
||||
|
||||
it 'should consolidate likes notification when the threshold is reached' do
|
||||
freeze_time
|
||||
|
||||
expect do
|
||||
4.times do
|
||||
PostAction.act(
|
||||
liker,
|
||||
Fabricate(:post, user: likee),
|
||||
PostActionType.types[:like]
|
||||
)
|
||||
end
|
||||
end.to change { likee.reload.notifications.count }.by(1)
|
||||
|
||||
notification = likee.notifications.last
|
||||
|
||||
expect(notification.notification_type).to eq(
|
||||
Notification.types[:liked_consolidated]
|
||||
)
|
||||
|
||||
data = JSON.parse(notification.data)
|
||||
|
||||
expect(data["username"]).to eq(liker.username)
|
||||
expect(data["display_username"]).to eq(liker.username)
|
||||
expect(data["count"]).to eq(4)
|
||||
|
||||
notification.update!(read: true)
|
||||
|
||||
expect do
|
||||
2.times do
|
||||
PostAction.act(
|
||||
liker,
|
||||
Fabricate(:post, user: likee),
|
||||
PostActionType.types[:like]
|
||||
)
|
||||
end
|
||||
end.to_not change { likee.reload.notifications.count }
|
||||
|
||||
data = JSON.parse(notification.reload.data)
|
||||
|
||||
expect(notification.read).to eq(false)
|
||||
expect(data["count"]).to eq(6)
|
||||
|
||||
freeze_time(
|
||||
SiteSetting.likes_notification_consolidation_window_mins.minutes.since
|
||||
)
|
||||
|
||||
expect do
|
||||
PostAction.act(
|
||||
liker,
|
||||
Fabricate(:post, user: likee),
|
||||
PostActionType.types[:like]
|
||||
)
|
||||
end.to change { likee.reload.notifications.count }.by(1)
|
||||
|
||||
notification = likee.notifications.last
|
||||
|
||||
expect(notification.notification_type).to eq(Notification.types[:liked])
|
||||
end
|
||||
end
|
||||
|
||||
it "should not generate a notification if liker has been muted" do
|
||||
mutee = Fabricate(:user)
|
||||
MutedUser.create!(user_id: post.user.id, muted_user_id: mutee.id)
|
||||
|
||||
Reference in New Issue
Block a user