Files
chatwoot/spec/enterprise/finders/conversation_finder_spec.rb
T
Sony MathewandGitHub 66cfb26c77 feat: Add unread count filters feature flag (1/6) (#14885)
## Description

Adds the account-level `unread_count_for_filters` feature flag as the
dark-launch gate for filtered sidebar unread counts. This reuses the
deprecated `quoted_email_reply` flag slot, resets the reused bit for
existing accounts, and removes stale defaults so new accounts do not
reference the old flag.

This also adds the feature where we are now calculating the unread counts for built in filters like mentions, participating and unattended along with unread count for saved filters/folders.

Closes
[CW-7262](https://linear.app/chatwoot/issue/CW-7262/unread-counts-for-filters-folders)

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality not to work as expected)
- [ ] This change requires a documentation update
2026-07-08 23:50:40 +05:30

42 lines
1.8 KiB
Ruby

require 'rails_helper'
RSpec.describe ConversationFinder do
describe '#perform_meta_only' do
let(:account) { create(:account) }
let(:agent) { create(:user, account: account, role: :agent) }
let(:other_agent) { create(:user, account: account, role: :agent) }
let(:inbox) { create(:inbox, account: account) }
before do
Current.account = account
create(:inbox_member, user: agent, inbox: inbox)
account.account_users.find_by(user: agent).update!(
role: :agent,
custom_role: create(:custom_role, account: account, permissions: %w[conversation_participating_manage])
)
end
it 'counts participant-filtered conversations once when assigned conversations have multiple participants' do
assigned_conversation = create(:conversation, account: account, inbox: inbox, assignee: agent)
participating_conversation = create(:conversation, account: account, inbox: inbox, assignee: other_agent)
create(:conversation, account: account, inbox: inbox, assignee: other_agent)
2.times do
participant = create(:user, account: account, role: :agent)
create(:inbox_member, user: participant, inbox: inbox)
create(:conversation_participant, account: account, conversation: assigned_conversation, user: participant)
end
create(:conversation_participant, account: account, conversation: participating_conversation, user: agent)
result = described_class.new(agent, { status: 'open' }).perform_meta_only
expect(result[:count]).to eq({
mine_count: 1,
assigned_count: 2,
unassigned_count: 0,
all_count: 2
})
end
end
end