2021-05-03 14:53:09 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ::Campaigns::CampaignConversationBuilder do
|
|
|
|
let(:account) { create(:account) }
|
|
|
|
let(:inbox) { create(:inbox, account: account) }
|
|
|
|
let(:contact) { create(:contact, account: account, identifier: '123') }
|
|
|
|
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: inbox) }
|
2022-02-04 09:08:18 +00:00
|
|
|
let(:campaign) { create(:campaign, inbox: inbox, account: account, trigger_rules: { url: 'https://test.com' }) }
|
2021-05-03 14:53:09 +00:00
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
it 'creates a conversation with campaign id and message with campaign message' do
|
|
|
|
campaign_conversation = described_class.new(
|
|
|
|
contact_inbox_id: contact_inbox.id,
|
|
|
|
campaign_display_id: campaign.display_id
|
|
|
|
).perform
|
|
|
|
|
|
|
|
expect(campaign_conversation.campaign_id).to eq(campaign.id)
|
|
|
|
expect(campaign_conversation.messages.first.content).to eq(campaign.message)
|
2022-05-09 08:34:52 +00:00
|
|
|
expect(campaign_conversation.messages.first.additional_attributes['campaign_id']).to eq(campaign.id)
|
2021-05-03 14:53:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'will not create a conversation with campaign id if another conversation exists' do
|
|
|
|
create(:conversation, contact_inbox_id: contact_inbox.id, inbox: inbox, account: account)
|
|
|
|
campaign_conversation = described_class.new(
|
|
|
|
contact_inbox_id: contact_inbox.id,
|
|
|
|
campaign_display_id: campaign.display_id
|
|
|
|
).perform
|
|
|
|
|
2022-07-15 02:51:59 +00:00
|
|
|
expect(campaign_conversation).to be_nil
|
2021-05-03 14:53:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|