Files
chatwoot/spec/finders/notification_finder_spec.rb
Muhsin Keloth cd06b2b337 fix: Inbox view Read/Snoozed display filters (#8907)
* fix: Notification filters

* Update notification_finder.rb

* Update notification_finder.rb

* Update notification_finder.rb

* fix: spec

* fix: specs

* Update notification_finder.rb

* fix: add more fixes

* Update notification_finder.rb

* fix: specs

* chore: better comments

* chore: removed filtering

* chore: refactoring

* fix: review fixes

* fix: API call

* chore: Minor fix

* Rename spec

* Fix params getting undefined

* Fix finder

---------

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: iamsivin <iamsivin@gmail.com>
Co-authored-by: Pranav <pranav@chatwoot.com>
2024-02-17 13:59:25 +05:30

81 lines
2.3 KiB
Ruby

require 'rails_helper'
RSpec.describe NotificationFinder do
let!(:account) { create(:account) }
let!(:user) { create(:user, account: account) }
let(:notification_finder) { described_class.new(user, account, params) }
before do
create(:notification, :snoozed, account: account, user: user)
create_list(:notification, 2, :read, account: account, user: user)
create_list(:notification, 3, account: account, user: user)
end
describe '#notifications' do
subject { notification_finder.notifications }
context 'with default params (empty)' do
let(:params) { {} }
it 'returns all unread and unsnoozed notifications, ordered by last activity' do
expect(subject.size).to eq(3)
expect(subject).to match_array(subject.sort_by(&:last_activity_at).reverse)
end
end
context 'with params including read and snoozed statuses' do
let(:params) { { includes: %w[read snoozed] } }
it 'returns all notifications, including read and snoozed' do
expect(subject.size).to eq(6)
end
end
context 'with params including only read status' do
let(:params) { { includes: ['read'] } }
it 'returns all notifications expect the snoozed' do
expect(subject.size).to eq(5)
end
end
context 'with params including only snoozed status' do
let(:params) { { includes: ['snoozed'] } }
it 'rreturns all notifications only expect the read' do
expect(subject.size).to eq(4)
end
end
context 'with ascending sort order' do
let(:params) { { sort_order: :asc } }
it 'returns notifications in ascending order by last activity' do
expect(subject.first.last_activity_at).to be < subject.last.last_activity_at
end
end
end
describe 'counts' do
subject { notification_finder }
context 'without specific filters' do
let(:params) { {} }
it 'correctly reports unread and total counts' do
expect(subject.unread_count).to eq(3)
expect(subject.count).to eq(3)
end
end
context 'with filters applied' do
let(:params) { { includes: %w[read snoozed] } }
it 'adjusts counts based on included statuses' do
expect(subject.unread_count).to eq(4)
expect(subject.count).to eq(6)
end
end
end
end