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) }
|
|
|
|
let!(:inbox) { create(:inbox, account: account) }
|
|
|
|
|
|
|
|
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)
|
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
|
|
|
|
expect(result[:conversations].count).to be 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with assignee' do
|
2020-02-26 15:45:01 +00:00
|
|
|
let(:params) { { assignee_type: 'all' } }
|
2019-12-01 04:46:51 +00:00
|
|
|
|
|
|
|
it 'filter conversations by assignee' do
|
|
|
|
result = conversation_finder.perform
|
|
|
|
expect(result[:conversations].count).to be 3
|
|
|
|
end
|
|
|
|
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
|
|
|
|
expect(result[:conversations].count).to be 1
|
|
|
|
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
|
|
|
|
expect(result[:conversations].count).to be 1
|
|
|
|
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
|
|
|
|
expect(result[:conversations].count).to be 25
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|