Chatwoot/spec/finders/message_finder_spec.rb
Pranav Raj S cb22b396eb
Feature: Website SDK (#653)
Add SDK functions

Co-authored-by: Sojan <sojan@pepalo.com>
2020-04-03 13:04:58 +05:30

50 lines
1.7 KiB
Ruby

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) }
let!(:contact) { create(:contact, email: nil) }
let!(:conversation) do
create(:conversation, account: account, inbox: inbox, assignee: user, contact: contact)
end
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)
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
expect(result.count).to be 7
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
expect(result.count).to be 5
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
expect(result.count).to be 7
end
end
end
end