Chatwoot/spec/finders/conversation_finder_spec.rb
Sojan Jose b7a583b2c4
Feature: Ability to switch between multiple accounts (#881)
* Feature: Ability to switch between multiple accounts

* Fix rubocop

* Fix assigned inboxes

* fix auth json

* Add account switcher in UI

* fix ordering on administrate

* Add switch accounts to sidebar

* add account id

* Fix schema.rb timestamp

* Revert "add account id"

This reverts commit 27570f50ef584cb9a5f69454f43f630b318c8807.

* Add a check for account

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
2020-05-26 22:38:48 +05:30

62 lines
2 KiB
Ruby

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)
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)
Current.account = account
end
describe '#perform' do
context 'with status' do
let(:params) { { status: 'open', assignee_type: 'me' } }
it 'filter conversations by status' do
result = conversation_finder.perform
expect(result[:conversations].count).to be 2
end
end
context 'with assignee' do
let(:params) { { assignee_type: 'all' } }
it 'filter conversations by assignee' do
result = conversation_finder.perform
expect(result[:conversations].count).to be 3
end
end
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
context 'with pagination' do
let(:params) { { status: 'open', assignee_type: 'me', page: 1 } }
it 'returns paginated conversations' do
create_list(:conversation, 50, account: account, inbox: inbox, assignee: user_1)
result = conversation_finder.perform
expect(result[:conversations].count).to be 25
end
end
end
end