2019-12-15 11:29:12 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ::MessageFinder do
|
|
|
|
subject(:message_finder) { described_class.new(conversation, params) }
|
|
|
|
|
|
|
|
let!(:account) { create(:account) }
|
|
|
|
let!(:user) { create(:user, account: account) }
|
|
|
|
let!(:inbox) { create(:inbox, account: account) }
|
2020-04-03 07:34:58 +00:00
|
|
|
let!(:contact) { create(:contact, email: nil) }
|
|
|
|
let!(:conversation) do
|
|
|
|
create(:conversation, account: account, inbox: inbox, assignee: user, contact: contact)
|
|
|
|
end
|
2019-12-15 11:29:12 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
create(:message, account: account, inbox: inbox, conversation: conversation)
|
|
|
|
create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation)
|
|
|
|
create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation)
|
2020-06-09 18:24:35 +00:00
|
|
|
# this outgoing message creates 2 additional messages because of the email hook execution service
|
2019-12-15 11:29:12 +00:00
|
|
|
create(:message, message_type: 'outgoing', account: account, inbox: inbox, conversation: conversation)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
context 'with filter_internal_messages false' do
|
|
|
|
let(:params) { { filter_internal_messages: false } }
|
|
|
|
|
|
|
|
it 'filter conversations by status' do
|
|
|
|
result = message_finder.perform
|
2020-06-09 18:24:35 +00:00
|
|
|
expect(result.count).to be 6
|
2019-12-15 11:29:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with filter_internal_messages true' do
|
|
|
|
let(:params) { { filter_internal_messages: true } }
|
|
|
|
|
|
|
|
it 'filter conversations by status' do
|
|
|
|
result = message_finder.perform
|
2020-06-09 18:24:35 +00:00
|
|
|
expect(result.count).to be 4
|
2019-12-15 11:29:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with before attribute' do
|
|
|
|
let!(:outgoing) { create(:message, message_type: 'outgoing', account: account, inbox: inbox, conversation: conversation) }
|
|
|
|
let(:params) { { before: outgoing.id } }
|
|
|
|
|
|
|
|
it 'filter conversations by status' do
|
|
|
|
result = message_finder.perform
|
2020-06-09 18:24:35 +00:00
|
|
|
expect(result.count).to be 6
|
2019-12-15 11:29:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|