This reverts #14610 so conversation unread counts are again controlled by the `conversation_unread_counts` feature flag across the API, ActionCable broadcasts, notifier/listener paths, and dashboard sidebar fetching. ## Closes - None ## What changed - Restores feature-flag checks for conversation unread count reads and broadcasts. - Restores the dashboard feature flag constant and sidebar/store behavior for disabled unread counts. - Restores the specs that cover disabled-feature behavior. ## How to test - In an account with `conversation_unread_counts` enabled, verify sidebar unread counts are fetched and updated in real time. - Disable `conversation_unread_counts` for the account and verify unread count requests/broadcasts are skipped.
49 lines
1.7 KiB
Ruby
49 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Conversations::UnreadCounts::Notifier do
|
|
let!(:conversation) { create(:conversation) }
|
|
let(:refresher) { instance_double(Conversations::UnreadCounts::Refresher, perform: refresh_result) }
|
|
let(:refresh_result) { true }
|
|
|
|
before do
|
|
conversation.account.enable_features!(:conversation_unread_counts)
|
|
allow(Conversations::UnreadCounts::Refresher).to receive(:new).and_return(refresher)
|
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
|
end
|
|
|
|
it 'dispatches unread count changed event after a successful refresh' do
|
|
described_class.new(conversation).perform
|
|
|
|
expect(Rails.configuration.dispatcher).to have_received(:dispatch).with(
|
|
'conversation.unread_count_changed',
|
|
kind_of(Time),
|
|
conversation: conversation
|
|
)
|
|
end
|
|
|
|
context 'when refresh does not change unread count memberships' do
|
|
let(:refresh_result) { false }
|
|
|
|
it 'does not dispatch unread count changed event' do
|
|
described_class.new(conversation).perform
|
|
|
|
expect(Rails.configuration.dispatcher).not_to have_received(:dispatch)
|
|
end
|
|
end
|
|
|
|
context 'when conversation unread counts feature is disabled' do
|
|
before do
|
|
conversation.account.disable_features!(:conversation_unread_counts)
|
|
allow(Conversations::UnreadCounts::Store).to receive(:clear_account!)
|
|
end
|
|
|
|
it 'does not refresh, clear cache, or dispatch unread count changed event' do
|
|
described_class.new(conversation).perform
|
|
|
|
expect(Conversations::UnreadCounts::Refresher).not_to have_received(:new)
|
|
expect(Conversations::UnreadCounts::Store).not_to have_received(:clear_account!)
|
|
expect(Rails.configuration.dispatcher).not_to have_received(:dispatch)
|
|
end
|
|
end
|
|
end
|