2019-01-25 21:53:06 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe UserSystemNotification do
|
2019-05-08 20:22:52 +08:00
|
|
|
let(:user_system_notification) { build :user_system_notification }
|
2019-01-25 21:53:06 +08:00
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
expect(user_system_notification).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Associations' do
|
2019-07-26 18:40:36 +08:00
|
|
|
it { should belong_to :user }
|
|
|
|
it { should belong_to :system_notification }
|
2019-01-25 21:53:06 +08:00
|
|
|
end
|
2019-02-19 18:08:59 +08:00
|
|
|
|
|
|
|
describe 'Methods' do
|
2019-05-08 20:22:52 +08:00
|
|
|
let(:user) { create :user }
|
2019-02-19 18:08:59 +08:00
|
|
|
let(:notifcation_one) { create :system_notification }
|
|
|
|
let(:notifcation_two) { create :system_notification }
|
|
|
|
let(:notifcation_three) { create :system_notification, :show_on_login }
|
|
|
|
|
|
|
|
it 'make_as_seen update seen_at' do
|
|
|
|
usn = create :user_system_notification,
|
|
|
|
user: user,
|
|
|
|
system_notification: notifcation_one
|
|
|
|
notifications_to_update = [usn.system_notification_id]
|
2019-02-21 23:15:13 +08:00
|
|
|
user.user_system_notifications.mark_as_seen
|
2019-02-19 18:08:59 +08:00
|
|
|
expect(UserSystemNotification.find(usn.id).seen_at).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'make_as_read update read_at' do
|
|
|
|
usn = create :user_system_notification,
|
|
|
|
user: user,
|
|
|
|
system_notification: notifcation_one
|
|
|
|
user.user_system_notifications.mark_as_read(usn.system_notification_id)
|
|
|
|
expect(UserSystemNotification.find(usn.id).read_at).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'show_on_login method only check any notifications' do
|
|
|
|
usn = create :user_system_notification,
|
|
|
|
user: user,
|
|
|
|
system_notification: notifcation_three
|
|
|
|
result = user.user_system_notifications.show_on_login
|
|
|
|
expect(result).not_to be_nil
|
|
|
|
expect(UserSystemNotification.find(usn.id).seen_at).to be_nil
|
|
|
|
expect(UserSystemNotification.find(usn.id).read_at).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'show_on_login method update notification read and seen time' do
|
|
|
|
usn = create :user_system_notification,
|
|
|
|
user: user,
|
|
|
|
system_notification: notifcation_three
|
|
|
|
result = user.user_system_notifications.show_on_login(true)
|
|
|
|
expect(result).not_to be_nil
|
|
|
|
expect(UserSystemNotification.find(usn.id).seen_at).not_to be_nil
|
|
|
|
expect(UserSystemNotification.find(usn.id).read_at).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-01-25 21:53:06 +08:00
|
|
|
end
|