Files
assistant-storefront/spec/builders/contact_inbox_with_contact_builder_spec.rb
Liang XJ 092fb2e083
Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
Initial commit: Add logistics and order_detail message types
- Add Logistics component with progress tracking
- Add OrderDetail component for order information
- Support data-driven steps and actions
- Add blue color scale to widget SCSS
- Fix node overflow and progress bar rendering issues
- Add English translations for dashboard components

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 11:16:56 +08:00

128 lines
4.3 KiB
Ruby

require 'rails_helper'
describe ContactInboxWithContactBuilder do
let(:account) { create(:account) }
let(:inbox) { create(:inbox, account: account) }
let(:contact) { create(:contact, email: 'xyc@example.com', phone_number: '+23423424123', account: account, identifier: '123') }
let(:existing_contact_inbox) { create(:contact_inbox, contact: contact, inbox: inbox) }
describe '#perform' do
it 'doesnot create contact if it already exist with source id' do
contact_inbox = described_class.new(
source_id: existing_contact_inbox.source_id,
inbox: inbox,
contact_attributes: {
name: 'Contact',
phone_number: '+1234567890',
email: 'testemail@example.com'
}
).perform
expect(contact_inbox.contact.id).to be(contact.id)
end
it 'creates contact if contact doesnot exist with source id' do
contact_inbox = described_class.new(
source_id: '123456',
inbox: inbox,
contact_attributes: {
name: 'Contact',
phone_number: '+1234567890',
email: 'testemail@example.com',
custom_attributes: { test: 'test' }
}
).perform
expect(contact_inbox.contact.id).not_to eq(contact.id)
expect(contact_inbox.contact.name).to eq('Contact')
expect(contact_inbox.contact.custom_attributes).to eq({ 'test' => 'test' })
expect(contact_inbox.inbox_id).to eq(inbox.id)
end
it 'doesnot create contact if it already exist with identifier' do
contact_inbox = described_class.new(
source_id: '123456',
inbox: inbox,
contact_attributes: {
name: 'Contact',
identifier: contact.identifier,
phone_number: contact.phone_number,
email: 'testemail@example.com'
}
).perform
expect(contact_inbox.contact.id).to be(contact.id)
end
it 'doesnot create contact if it already exist with email' do
contact_inbox = described_class.new(
source_id: '123456',
inbox: inbox,
contact_attributes: {
name: 'Contact',
phone_number: '+1234567890',
email: contact.email
}
).perform
expect(contact_inbox.contact.id).to be(contact.id)
end
it 'doesnot create contact when an uppercase email is passed for an already existing contact email' do
contact_inbox = described_class.new(
source_id: '123456',
inbox: inbox,
contact_attributes: {
name: 'Contact',
phone_number: '+1234567890',
email: contact.email.upcase
}
).perform
expect(contact_inbox.contact.id).to be(contact.id)
end
it 'doesnot create contact if it already exist with phone number' do
contact_inbox = described_class.new(
source_id: '123456',
inbox: inbox,
contact_attributes: {
name: 'Contact',
phone_number: contact.phone_number,
email: 'testemail@example.com'
}
).perform
expect(contact_inbox.contact.id).to be(contact.id)
end
it 'reuses contact if it exists with the same source_id in a Facebook inbox when creating for Instagram inbox' do
instagram_source_id = '123456789'
# Create a Facebook page inbox with a contact using the same source_id
facebook_inbox = create(:inbox, channel_type: 'Channel::FacebookPage', account: account)
facebook_contact = create(:contact, account: account)
facebook_contact_inbox = create(:contact_inbox, contact: facebook_contact, inbox: facebook_inbox, source_id: instagram_source_id)
# Create an Instagram inbox
instagram_inbox = create(:inbox, channel_type: 'Channel::Instagram', account: account)
# Try to create a contact inbox with same source_id for Instagram
contact_inbox = described_class.new(
source_id: instagram_source_id,
inbox: instagram_inbox,
contact_attributes: {
name: 'Instagram User',
email: 'instagram_user@example.com'
}
).perform
# Should reuse the existing contact from Facebook
expect(contact_inbox.contact.id).to eq(facebook_contact.id)
# Make sure the contact inbox is not the same as the Facebook contact inbox
expect(contact_inbox.id).not_to eq(facebook_contact_inbox.id)
expect(contact_inbox.inbox_id).to eq(instagram_inbox.id)
end
end
end