@@ -99,6 +99,53 @@ describe ::ContactInboxBuilder do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'sms inbox' do
|
||||
let!(:sms_channel) { create(:channel_sms, account: account) }
|
||||
let!(:sms_inbox) { create(:inbox, channel: sms_channel, account: account) }
|
||||
|
||||
it 'does not create contact inbox when contact inbox already exists with the source id provided' do
|
||||
existing_contact_inbox = create(:contact_inbox, contact: contact, inbox: sms_inbox, source_id: contact.phone_number)
|
||||
contact_inbox = described_class.new(
|
||||
contact_id: contact.id,
|
||||
inbox_id: sms_inbox.id,
|
||||
source_id: contact.phone_number
|
||||
).perform
|
||||
|
||||
expect(contact_inbox.id).to be(existing_contact_inbox.id)
|
||||
end
|
||||
|
||||
it 'does not create contact inbox when contact inbox already exists with phone number and source id is not provided' do
|
||||
existing_contact_inbox = create(:contact_inbox, contact: contact, inbox: sms_inbox, source_id: contact.phone_number)
|
||||
contact_inbox = described_class.new(
|
||||
contact_id: contact.id,
|
||||
inbox_id: sms_inbox.id
|
||||
).perform
|
||||
|
||||
expect(contact_inbox.id).to be(existing_contact_inbox.id)
|
||||
end
|
||||
|
||||
it 'creates a new contact inbox when different source id is provided' do
|
||||
existing_contact_inbox = create(:contact_inbox, contact: contact, inbox: sms_inbox, source_id: contact.phone_number)
|
||||
contact_inbox = described_class.new(
|
||||
contact_id: contact.id,
|
||||
inbox_id: sms_inbox.id,
|
||||
source_id: '+224213223422'
|
||||
).perform
|
||||
|
||||
expect(contact_inbox.id).not_to be(existing_contact_inbox.id)
|
||||
expect(contact_inbox.source_id).not_to be('+224213223422')
|
||||
end
|
||||
|
||||
it 'creates a contact inbox with contact phone number when source id not provided and no contact inbox exists' do
|
||||
contact_inbox = described_class.new(
|
||||
contact_id: contact.id,
|
||||
inbox_id: sms_inbox.id
|
||||
).perform
|
||||
|
||||
expect(contact_inbox.source_id).not_to be(contact.phone_number)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'email inbox' do
|
||||
let!(:email_channel) { create(:channel_email, account: account) }
|
||||
let!(:email_inbox) { create(:inbox, channel: email_channel, account: account) }
|
||||
|
||||
Reference in New Issue
Block a user