fix: review comments
This commit is contained in:
@@ -60,6 +60,6 @@ class NotificationFinder
|
||||
end
|
||||
|
||||
def notifications
|
||||
@notifications.page(current_page).per(RESULTS_PER_PAGE).order(last_activity_at: :asc)
|
||||
@notifications.page(current_page).per(RESULTS_PER_PAGE).order(last_activity_at: :desc)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,10 +47,6 @@ class Notification < ApplicationRecord
|
||||
after_create_commit :process_notification_delivery, :dispatch_create_event
|
||||
after_destroy_commit :dispatch_destroy_event
|
||||
|
||||
# TODO: Get rid of default scope
|
||||
# https://stackoverflow.com/a/1834250/939299
|
||||
default_scope { order(last_activity_at: :desc) }
|
||||
|
||||
PRIMARY_ACTORS = ['Conversation'].freeze
|
||||
|
||||
def push_event_data
|
||||
|
||||
@@ -13,50 +13,43 @@ describe NotificationFinder do
|
||||
create(:notification, account: account, user: user, updated_at: DateTime.now.utc + 2.days, last_activity_at: DateTime.now.utc + 2.days)
|
||||
create(:notification, account: account, user: user, updated_at: DateTime.now.utc + 4.days, last_activity_at: DateTime.now.utc + 4.days,
|
||||
notification_type: :conversation_creation)
|
||||
create(:notification, account: account, user: user, updated_at: DateTime.now.utc + 5.days, last_activity_at: DateTime.now.utc + 5.days,
|
||||
notification_type: :conversation_mention)
|
||||
create(:notification, account: account, user: user, updated_at: DateTime.now.utc + 6.days, last_activity_at: DateTime.now.utc + 6.days,
|
||||
notification_type: :participating_conversation_new_message)
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
context 'with snoozed status' do
|
||||
let(:params) { { status: 'snoozed' } }
|
||||
|
||||
it 'filter notifications by status' do
|
||||
result = notification_finder.perform
|
||||
expect(result.length).to be 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'without snoozed status' do
|
||||
context 'when params are empty' do
|
||||
let(:params) { {} }
|
||||
|
||||
it 'returns all notifications' do
|
||||
it 'returns notifications which aren not snoozed' do
|
||||
result = notification_finder.perform
|
||||
expect(result.length).to be 3
|
||||
end
|
||||
end
|
||||
|
||||
context 'when order by last_activity_at' do
|
||||
let(:params) { {} }
|
||||
|
||||
it 'returns all notifications' do
|
||||
it 'orders notifications by last activity at' do
|
||||
result = notification_finder.perform
|
||||
expect(result.first.last_activity_at).to be > result.last.last_activity_at
|
||||
expect(result.first.last_activity_at).to be > result.last.last_activity_at
|
||||
end
|
||||
end
|
||||
|
||||
context 'when order by user notification settings' do
|
||||
let(:params) { {} }
|
||||
|
||||
before do
|
||||
it 'filter notifications by user preferences' do
|
||||
notification_setting = user.notification_settings.find_by(account_id: account.id)
|
||||
notification_setting.selected_email_flags = [:email_conversation_creation]
|
||||
notification_setting.save!
|
||||
end
|
||||
|
||||
it 'returns all notifications' do
|
||||
result = notification_finder.perform
|
||||
expect(result.length).to be 4
|
||||
end
|
||||
end
|
||||
|
||||
context 'when snoozed param is passed' do
|
||||
let(:params) { { status: 'snoozed' } }
|
||||
|
||||
it 'returns only snoozed notifications' do
|
||||
result = notification_finder.perform
|
||||
expect(result.length).to be 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user