rspec tests for lock_to_single_conversation for meta inboxes
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
FBMessage = Struct.new(:sender_id, :attachments, :content, :identifier, :in_reply_to_external_id)
|
||||
|
||||
describe Messages::Facebook::MessageBuilder do
|
||||
subject(:message_builder) { described_class.new(incoming_fb_text_message, facebook_channel.inbox).perform }
|
||||
|
||||
@@ -7,7 +9,11 @@ describe Messages::Facebook::MessageBuilder do
|
||||
stub_request(:post, /graph.facebook.com/)
|
||||
end
|
||||
|
||||
let!(:account) { create(:account) }
|
||||
let!(:facebook_channel) { create(:channel_facebook_page) }
|
||||
let!(:facebook_inbox) { create(:inbox, channel: facebook_channel, account: account, greeting_enabled: false) }
|
||||
let(:contact) { create(:contact, name: 'Jane Dae') }
|
||||
let(:contact_inbox) { create(:contact_inbox, contact_id: contact.id, inbox_id: facebook_inbox.id) }
|
||||
let!(:message_object) { build(:incoming_fb_text_message).to_json }
|
||||
let!(:incoming_fb_text_message) { Integrations::Facebook::MessageParser.new(message_object) }
|
||||
let(:fb_object) { double }
|
||||
@@ -58,5 +64,101 @@ describe Messages::Facebook::MessageBuilder do
|
||||
expect(facebook_channel.inbox.reload.contacts.count).to eq(1)
|
||||
expect(contact.name).to eq(default_name)
|
||||
end
|
||||
|
||||
context 'when lock to single conversation is disabled' do
|
||||
before do
|
||||
facebook_inbox.update!(lock_to_single_conversation: false)
|
||||
stub_request(:get, /graph.facebook.com/)
|
||||
end
|
||||
|
||||
it 'creates a new conversation if existing conversation is not present' do
|
||||
message = FBMessage.new(contact_inbox.source_id, {}, '', '', '')
|
||||
facebook_inbox.reload
|
||||
described_class.new(message, facebook_inbox).perform
|
||||
|
||||
facebook_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(facebook_inbox.conversations.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'will not create a new conversation if last conversation is not resolved' do
|
||||
existing_conversation = create(:conversation, account_id: account.id, inbox_id: facebook_inbox.id, contact_id: contact.id, status: :open)
|
||||
|
||||
message = FBMessage.new(contact_inbox.source_id, {}, '', '', '')
|
||||
facebook_inbox.reload
|
||||
described_class.new(message, facebook_inbox).perform
|
||||
|
||||
facebook_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(facebook_inbox.conversations.last.id).to eq(existing_conversation.id)
|
||||
end
|
||||
|
||||
it 'creates a new conversation if last conversation is resolved' do
|
||||
existing_conversation = create(:conversation, account_id: account.id, inbox_id: facebook_inbox.id, contact_id: contact.id,
|
||||
contact_inbox_id: contact_inbox.id, status: :resolved)
|
||||
|
||||
inital_count = Conversation.count
|
||||
|
||||
message = FBMessage.new(contact_inbox.source_id, {}, '', '', '')
|
||||
facebook_inbox.reload
|
||||
described_class.new(message, facebook_inbox).perform
|
||||
|
||||
facebook_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(facebook_inbox.conversations.last.id).not_to eq(existing_conversation.id)
|
||||
expect(Conversation.count).to eq(inital_count + 1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when lock to single conversation is enabled' do
|
||||
before do
|
||||
facebook_inbox.update!(lock_to_single_conversation: true)
|
||||
stub_request(:get, /graph.facebook.com/)
|
||||
end
|
||||
|
||||
it 'creates a new conversation if existing conversation is not present' do
|
||||
message = FBMessage.new(contact_inbox.source_id, {}, '', '', '')
|
||||
facebook_inbox.reload
|
||||
described_class.new(message, facebook_inbox).perform
|
||||
|
||||
facebook_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(facebook_inbox.conversations.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'will not create a new conversation if last conversation is not resolved' do
|
||||
existing_conversation = create(:conversation, account_id: account.id, inbox_id: facebook_inbox.id, contact_id: contact.id, status: :open)
|
||||
|
||||
message = FBMessage.new(contact_inbox.source_id, {}, '', '', '')
|
||||
facebook_inbox.reload
|
||||
described_class.new(message, facebook_inbox).perform
|
||||
|
||||
facebook_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(facebook_inbox.conversations.last.id).to eq(existing_conversation.id)
|
||||
end
|
||||
|
||||
it 'reopens last conversation if last conversation is resolved' do
|
||||
existing_conversation = create(:conversation, account_id: account.id, inbox_id: facebook_inbox.id, contact_id: contact.id,
|
||||
contact_inbox_id: contact_inbox.id, status: :resolved)
|
||||
|
||||
inital_count = Conversation.count
|
||||
|
||||
message = FBMessage.new(contact_inbox.source_id, {}, '', '', '')
|
||||
facebook_inbox.reload
|
||||
described_class.new(message, facebook_inbox).perform
|
||||
|
||||
facebook_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(facebook_inbox.conversations.last.id).to eq(existing_conversation.id)
|
||||
expect(Conversation.count).to eq(inital_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -183,4 +183,115 @@ describe Messages::Instagram::MessageBuilder do
|
||||
expect(contact.name).to eq('Jane Dae')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when lock to single conversation is disabled' do
|
||||
before do
|
||||
instagram_inbox.update!(lock_to_single_conversation: false)
|
||||
stub_request(:get, /graph.facebook.com/)
|
||||
end
|
||||
|
||||
it 'creates a new conversation if existing conversation is not present' do
|
||||
message = dm_params[:entry][0]['messaging'][0]
|
||||
contact_inbox
|
||||
|
||||
instagram_inbox.reload
|
||||
described_class.new(message, instagram_inbox).perform
|
||||
|
||||
instagram_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(instagram_inbox.conversations.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'will not create a new conversation if last conversation is not resolved' do
|
||||
existing_conversation = create(:conversation, account_id: account.id, inbox_id: instagram_inbox.id, contact_id: contact.id, status: :open,
|
||||
additional_attributes: { type: 'instagram_direct_message', conversation_language: 'en' })
|
||||
|
||||
message = dm_params[:entry][0]['messaging'][0]
|
||||
contact_inbox
|
||||
|
||||
instagram_inbox.reload
|
||||
described_class.new(message, instagram_inbox).perform
|
||||
|
||||
instagram_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
puts "instagram_inbox.conversations: #{instagram_inbox.conversations.last.inspect}"
|
||||
|
||||
expect(instagram_inbox.conversations.last.id).to eq(existing_conversation.id)
|
||||
end
|
||||
|
||||
it 'creates a new conversation if last conversation is resolved' do
|
||||
existing_conversation = create(:conversation, account_id: account.id, inbox_id: instagram_inbox.id, contact_id: contact.id, status: :resolved,
|
||||
additional_attributes: { type: 'instagram_direct_message', conversation_language: 'en' })
|
||||
|
||||
inital_count = Conversation.count
|
||||
message = dm_params[:entry][0]['messaging'][0]
|
||||
contact_inbox
|
||||
|
||||
instagram_inbox.reload
|
||||
described_class.new(message, instagram_inbox).perform
|
||||
|
||||
instagram_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(instagram_inbox.conversations.last.id).not_to eq(existing_conversation.id)
|
||||
expect(Conversation.count).to eq(inital_count + 1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when lock to single conversation is enabled' do
|
||||
before do
|
||||
instagram_inbox.update!(lock_to_single_conversation: true)
|
||||
stub_request(:get, /graph.facebook.com/)
|
||||
end
|
||||
|
||||
it 'creates a new conversation if existing conversation is not present' do
|
||||
message = dm_params[:entry][0]['messaging'][0]
|
||||
contact_inbox
|
||||
|
||||
instagram_inbox.reload
|
||||
described_class.new(message, instagram_inbox).perform
|
||||
|
||||
instagram_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(instagram_inbox.conversations.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'will not create a new conversation if last conversation is not resolved' do
|
||||
existing_conversation = create(:conversation, account_id: account.id, inbox_id: instagram_inbox.id, contact_id: contact.id, status: :open,
|
||||
additional_attributes: { type: 'instagram_direct_message', conversation_language: 'en' })
|
||||
|
||||
message = dm_params[:entry][0]['messaging'][0]
|
||||
contact_inbox
|
||||
|
||||
instagram_inbox.reload
|
||||
described_class.new(message, instagram_inbox).perform
|
||||
|
||||
instagram_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(instagram_inbox.conversations.last.id).to eq(existing_conversation.id)
|
||||
end
|
||||
|
||||
it 'reopens last conversation if last conversation is resolved' do
|
||||
existing_conversation = create(:conversation, account_id: account.id, inbox_id: instagram_inbox.id, contact_id: contact.id, status: :resolved,
|
||||
additional_attributes: { type: 'instagram_direct_message', conversation_language: 'en' })
|
||||
|
||||
inital_count = Conversation.count
|
||||
|
||||
message = dm_params[:entry][0]['messaging'][0]
|
||||
contact_inbox
|
||||
|
||||
instagram_inbox.reload
|
||||
described_class.new(message, instagram_inbox).perform
|
||||
|
||||
instagram_inbox.reload
|
||||
contact_inbox.reload
|
||||
|
||||
expect(instagram_inbox.conversations.last.id).to eq(existing_conversation.id)
|
||||
expect(Conversation.count).to eq(inital_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user