DEV: Add test (#8960)

Follow-up to 3ad07aacfa.
This commit is contained in:
Dan Ungureanu 2020-02-14 10:19:40 +02:00 committed by GitHub
parent e90f9e5cc4
commit 9aeb9f0ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -122,15 +122,29 @@ describe Notification do
end
describe 'message bus' do
fab!(:user) { Fabricate(:user) }
it 'updates the notification count on create' do
Notification.any_instance.expects(:refresh_notification_count).returns(nil)
Fabricate(:notification)
end
it 'works' do
messages = MessageBus.track_publish do
user.notifications.create!(notification_type: Notification.types[:mentioned], data: '{}')
user.notifications.create!(notification_type: Notification.types[:mentioned], data: '{}')
end
expect(messages.size).to eq(2)
expect(messages[0].channel).to eq("/notification/#{user.id}")
expect(messages[0].data[:unread_notifications]).to eq(1)
expect(messages[1].channel).to eq("/notification/#{user.id}")
expect(messages[1].data[:unread_notifications]).to eq(2)
end
it 'works for partial model instances' do
NotificationEmailer.disable
partial_user = User.select(:id).find_by(id: Fabricate(:user).id)
partial_user = User.select(:id).find_by(id: user.id)
partial_user.notifications.create!(notification_type: Notification.types[:mentioned], data: '{}')
end