2019-12-01 04:46:51 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ::ConversationFinder do
|
|
|
|
subject(:conversation_finder) { described_class.new(user_1, params) }
|
|
|
|
|
|
|
|
let!(:account) { create(:account) }
|
|
|
|
let!(:user_1) { create(:user, account: account) }
|
|
|
|
let!(:user_2) { create(:user, account: account) }
|
2022-02-04 02:25:28 +00:00
|
|
|
let!(:admin) { create(:user, account: account, role: :administrator) }
|
2021-07-14 17:21:27 +00:00
|
|
|
let!(:inbox) { create(:inbox, account: account, enable_auto_assignment: false) }
|
2022-02-04 02:25:28 +00:00
|
|
|
let!(:restricted_inbox) { create(:inbox, account: account) }
|
2019-12-01 04:46:51 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
create(:inbox_member, user: user_1, inbox: inbox)
|
|
|
|
create(:inbox_member, user: user_2, inbox: inbox)
|
2019-12-24 07:57:25 +00:00
|
|
|
create(:conversation, account: account, inbox: inbox, assignee: user_1)
|
|
|
|
create(:conversation, account: account, inbox: inbox, assignee: user_1)
|
|
|
|
create(:conversation, account: account, inbox: inbox, assignee: user_1, status: 'resolved')
|
|
|
|
create(:conversation, account: account, inbox: inbox, assignee: user_2)
|
2021-07-14 17:21:27 +00:00
|
|
|
# unassigned conversation
|
|
|
|
create(:conversation, account: account, inbox: inbox)
|
2020-05-26 17:08:48 +00:00
|
|
|
Current.account = account
|
2019-12-01 04:46:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
context 'with status' do
|
2020-02-26 15:45:01 +00:00
|
|
|
let(:params) { { status: 'open', assignee_type: 'me' } }
|
2019-12-01 04:46:51 +00:00
|
|
|
|
|
|
|
it 'filter conversations by status' do
|
|
|
|
result = conversation_finder.perform
|
2021-07-31 15:49:42 +00:00
|
|
|
expect(result[:conversations].length).to be 2
|
2019-12-01 04:46:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-04 02:25:28 +00:00
|
|
|
context 'with inbox' do
|
|
|
|
let!(:restricted_conversation) { create(:conversation, account: account, inbox_id: restricted_inbox.id) }
|
|
|
|
|
|
|
|
it 'returns conversation from any inbox if its admin' do
|
|
|
|
params = { inbox_id: restricted_inbox.id }
|
|
|
|
result = described_class.new(admin, params).perform
|
|
|
|
|
|
|
|
expect(result[:conversations].map(&:id)).to include(restricted_conversation.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns conversation from inbox if agent is its member' do
|
|
|
|
params = { inbox_id: restricted_inbox.id }
|
|
|
|
create(:inbox_member, user: user_1, inbox: restricted_inbox)
|
|
|
|
result = described_class.new(user_1, params).perform
|
|
|
|
|
|
|
|
expect(result[:conversations].map(&:id)).to include(restricted_conversation.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return conversations from inboxes where agent is not a member' do
|
|
|
|
params = { inbox_id: restricted_inbox.id }
|
|
|
|
result = described_class.new(user_1, params).perform
|
|
|
|
|
|
|
|
expect(result[:conversations].map(&:id)).not_to include(restricted_conversation.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-14 17:21:27 +00:00
|
|
|
context 'with assignee_type all' do
|
2020-02-26 15:45:01 +00:00
|
|
|
let(:params) { { assignee_type: 'all' } }
|
2019-12-01 04:46:51 +00:00
|
|
|
|
2021-07-14 17:21:27 +00:00
|
|
|
it 'filter conversations by assignee type all' do
|
|
|
|
result = conversation_finder.perform
|
2021-07-31 15:49:42 +00:00
|
|
|
expect(result[:conversations].length).to be 4
|
2021-07-14 17:21:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with assignee_type unassigned' do
|
|
|
|
let(:params) { { assignee_type: 'unassigned' } }
|
|
|
|
|
|
|
|
it 'filter conversations by assignee type unassigned' do
|
|
|
|
result = conversation_finder.perform
|
2021-07-31 15:49:42 +00:00
|
|
|
expect(result[:conversations].length).to be 1
|
2021-07-14 17:21:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-29 10:53:39 +00:00
|
|
|
context 'with status all' do
|
|
|
|
let(:params) { { status: 'all' } }
|
|
|
|
|
|
|
|
it 'returns all conversations' do
|
|
|
|
result = conversation_finder.perform
|
|
|
|
expect(result[:conversations].length).to be 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-14 17:21:27 +00:00
|
|
|
context 'with assignee_type assigned' do
|
|
|
|
let(:params) { { assignee_type: 'assigned' } }
|
|
|
|
|
|
|
|
it 'filter conversations by assignee type assigned' do
|
2019-12-01 04:46:51 +00:00
|
|
|
result = conversation_finder.perform
|
2021-07-31 15:49:42 +00:00
|
|
|
expect(result[:conversations].length).to be 3
|
2019-12-01 04:46:51 +00:00
|
|
|
end
|
2021-07-19 13:40:58 +00:00
|
|
|
|
|
|
|
it 'returns the correct meta' do
|
|
|
|
result = conversation_finder.perform
|
|
|
|
expect(result[:count]).to eq({
|
|
|
|
mine_count: 2,
|
|
|
|
assigned_count: 3,
|
|
|
|
unassigned_count: 1,
|
|
|
|
all_count: 4
|
|
|
|
})
|
|
|
|
end
|
2019-12-01 04:46:51 +00:00
|
|
|
end
|
|
|
|
|
2021-01-31 07:10:02 +00:00
|
|
|
context 'with team' do
|
|
|
|
let(:team) { create(:team, account: account) }
|
|
|
|
let(:params) { { team_id: team.id } }
|
|
|
|
|
|
|
|
it 'filter conversations by team' do
|
|
|
|
create(:conversation, account: account, inbox: inbox, team: team)
|
|
|
|
result = conversation_finder.perform
|
2021-07-31 15:49:42 +00:00
|
|
|
expect(result[:conversations].length).to be 1
|
2021-01-31 07:10:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-02 10:59:18 +00:00
|
|
|
context 'with labels' do
|
|
|
|
let(:params) { { labels: ['resolved'] } }
|
|
|
|
|
|
|
|
it 'filter conversations by labels' do
|
|
|
|
conversation = inbox.conversations.first
|
|
|
|
conversation.update_labels('resolved')
|
|
|
|
|
|
|
|
result = conversation_finder.perform
|
2021-07-31 15:49:42 +00:00
|
|
|
expect(result[:conversations].length).to be 1
|
2020-02-02 10:59:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-01 04:46:51 +00:00
|
|
|
context 'with pagination' do
|
2020-02-26 15:45:01 +00:00
|
|
|
let(:params) { { status: 'open', assignee_type: 'me', page: 1 } }
|
2019-12-01 04:46:51 +00:00
|
|
|
|
|
|
|
it 'returns paginated conversations' do
|
2019-12-24 07:57:25 +00:00
|
|
|
create_list(:conversation, 50, account: account, inbox: inbox, assignee: user_1)
|
2019-12-01 04:46:51 +00:00
|
|
|
result = conversation_finder.perform
|
2021-07-31 15:49:42 +00:00
|
|
|
expect(result[:conversations].length).to be 25
|
2019-12-01 04:46:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|