chore: Get all notification API improvments (#8549)

Co-authored-by: Sojan Jose <sojan@chatwoot.com>
This commit is contained in:
Muhsin Keloth
2024-01-17 09:02:18 +05:30
committed by GitHub
parent e67f8824d9
commit 818424259f
10 changed files with 176 additions and 31 deletions

View File

@@ -0,0 +1,67 @@
require 'rails_helper'
describe NotificationFinder do
subject(:notification_finder) { described_class.new(user, account, params) }
let!(:account) { create(:account) }
let!(:user) { create(:user, account: account) }
before do
create(:notification, account: account, user: user, updated_at: DateTime.now.utc + 1.day, last_activity_at: DateTime.now.utc + 1.day,
read_at: DateTime.now.utc)
create(:notification, account: account, user: user, snoozed_until: DateTime.now.utc + 3.days, updated_at: DateTime.now.utc,
last_activity_at: DateTime.now.utc)
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, read_at: DateTime.now.utc)
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 'when params are empty' do
let(:params) { {} }
it 'returns all the notifications' do
result = notification_finder.perform
expect(result.length).to be 6
end
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
end
it 'returns unread count' do
result = notification_finder.unread_count
expect(result).to be 4
end
it 'returns count' do
result = notification_finder.count
expect(result).to be 6
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
it 'returns unread count' do
result = notification_finder.unread_count
expect(result).to be 1
end
it 'returns count' do
result = notification_finder.count
expect(result).to be 1
end
end
end
end