## 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
85 lines
2.8 KiB
Ruby
85 lines
2.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe AccountUser do
|
|
include ActiveJob::TestHelper
|
|
|
|
let!(:account_user) { create(:account_user) }
|
|
let!(:inbox) { create(:inbox, account: account_user.account) }
|
|
|
|
describe 'notification_settings' do
|
|
it 'gets created with the right default settings' do
|
|
expect(account_user.user.notification_settings).not_to be_nil
|
|
|
|
expect(account_user.user.notification_settings.first.email_conversation_creation?).to be(false)
|
|
expect(account_user.user.notification_settings.first.email_conversation_assignment?).to be(true)
|
|
end
|
|
end
|
|
|
|
describe 'permissions' do
|
|
it 'returns the right permissions' do
|
|
expect(account_user.permissions).to eq(['agent'])
|
|
end
|
|
|
|
it 'returns the right permissions for administrator' do
|
|
account_user.administrator!
|
|
expect(account_user.permissions).to eq(['administrator'])
|
|
end
|
|
end
|
|
|
|
describe 'destroy call agent::destroy service' do
|
|
it 'gets created with the right default settings' do
|
|
create(:conversation, account: account_user.account, assignee: account_user.user, inbox: inbox)
|
|
user = account_user.user
|
|
|
|
expect(user.assigned_conversations.count).to eq(1)
|
|
|
|
perform_enqueued_jobs do
|
|
account_user.destroy!
|
|
end
|
|
|
|
expect(user.assigned_conversations.count).to eq(0)
|
|
end
|
|
end
|
|
|
|
describe 'filtered unread count invalidation' do
|
|
let(:account) { create(:account) }
|
|
let(:user) { create(:user) }
|
|
let(:invalidator) { instance_double(Conversations::UnreadCounts::FilteredCountInvalidator, user_visibility_changed!: true) }
|
|
|
|
before do
|
|
allow(Conversations::UnreadCounts::FilteredCountInvalidator).to receive(:new).and_return(invalidator)
|
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
|
end
|
|
|
|
it 'invalidates filtered counts when the user is added to an account' do
|
|
create(:account_user, account: account, user: user)
|
|
|
|
expect(invalidator).to have_received(:user_visibility_changed!).with(user_id: user.id)
|
|
end
|
|
|
|
it 'invalidates filtered counts when the user role changes' do
|
|
account_user = create(:account_user, account: account, user: user)
|
|
|
|
account_user.update!(role: :administrator)
|
|
|
|
expect(invalidator).to have_received(:user_visibility_changed!).with(user_id: user.id).twice
|
|
expect(Rails.configuration.dispatcher).to have_received(:dispatch).with(
|
|
'account.cache_invalidated',
|
|
kind_of(Time),
|
|
account: account,
|
|
cache_keys: account.cache_keys
|
|
)
|
|
end
|
|
|
|
it 'invalidates filtered counts when the user is removed from an account' do
|
|
account_user = create(:account_user, account: account, user: user)
|
|
|
|
account_user.destroy!
|
|
|
|
expect(invalidator).to have_received(:user_visibility_changed!).with(user_id: user.id).twice
|
|
end
|
|
end
|
|
end
|