diff --git a/app/controllers/api/v1/accounts/conversations_controller.rb b/app/controllers/api/v1/accounts/conversations_controller.rb index 7c21844f5..ab1cae17d 100644 --- a/app/controllers/api/v1/accounts/conversations_controller.rb +++ b/app/controllers/api/v1/accounts/conversations_controller.rb @@ -15,7 +15,7 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro end def meta - result = conversation_finder.perform + result = conversation_finder.perform_meta_only @conversations_count = result[:count] end diff --git a/app/finders/conversation_finder.rb b/app/finders/conversation_finder.rb index d43ed31e7..7821bee49 100644 --- a/app/finders/conversation_finder.rb +++ b/app/finders/conversation_finder.rb @@ -55,6 +55,22 @@ class ConversationFinder } end + def perform_meta_only + set_up + + mine_count, unassigned_count, all_count, = set_count_for_all_conversations + assigned_count = all_count - unassigned_count + + { + count: { + mine_count: mine_count, + assigned_count: assigned_count, + unassigned_count: unassigned_count, + all_count: all_count + } + } + end + private def set_up diff --git a/spec/finders/conversation_finder_spec.rb b/spec/finders/conversation_finder_spec.rb index 0174ccfb0..9427e8157 100644 --- a/spec/finders/conversation_finder_spec.rb +++ b/spec/finders/conversation_finder_spec.rb @@ -190,6 +190,32 @@ describe ConversationFinder do end end + context 'with perform_meta_only' do + let(:params) { { assignee_type: 'assigned' } } + + it 'returns only count without conversations' do + result = conversation_finder.perform_meta_only + expect(result).to have_key(:count) + expect(result).not_to have_key(:conversations) + end + + it 'returns the correct counts' do + result = conversation_finder.perform_meta_only + expect(result[:count]).to eq({ + mine_count: 2, + assigned_count: 3, + unassigned_count: 1, + all_count: 4 + }) + end + + it 'returns same counts as perform' do + meta_result = conversation_finder.perform_meta_only + full_result = conversation_finder.perform + expect(meta_result[:count]).to eq(full_result[:count]) + end + end + context 'with unattended' do let(:params) { { status: 'open', assignee_type: 'me', conversation_type: 'unattended' } }