+
| ||||
|
+The response was: + +550 5.1.1 The email account that you tried to reach does not exist. Please = +try double-checking the recipient's email address for typos or unnecessary = +spaces. For more information, go to https://support.google.com/mail/?p=3DNo= +SuchUser d2e1a72fcca58-74ce2b0525csor332154b3a.0 - gsmtp + + |
+
Hey, just checking in. Let me know if you got my earlier message.
+ +--00000000000093475906390e1e9b-- diff --git a/spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb b/spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb index 18685a649..abcab1e8f 100644 --- a/spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb +++ b/spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' RSpec.describe Inboxes::FetchImapEmailInboxesJob do let(:account) { create(:account) } let(:suspended_account) { create(:account, status: 'suspended') } + let(:premium_account) { create(:account, custom_attributes: { plan_name: 'Startups' }) } let(:imap_email_channel) do create(:channel_email, imap_enabled: true, account: account) @@ -16,6 +17,19 @@ RSpec.describe Inboxes::FetchImapEmailInboxesJob do create(:channel_email, imap_enabled: false, account: account) end + let(:reauth_required_channel) do + create(:channel_email, imap_enabled: true, account: account) + end + + let(:premium_imap_channel) do + create(:channel_email, imap_enabled: true, account: premium_account) + end + + before do + reauth_required_channel.prompt_reauthorization! + premium_account.custom_attributes['plan_name'] = 'Startups' + end + it 'enqueues the job' do expect { described_class.perform_later }.to have_enqueued_job(described_class) .on_queue('scheduled_jobs') @@ -44,5 +58,11 @@ RSpec.describe Inboxes::FetchImapEmailInboxesJob do described_class.perform_now end + + it 'skips channels requiring reauthorization' do + expect(Inboxes::FetchImapEmailsJob).not_to receive(:perform_later).with(reauth_required_channel) + + described_class.perform_now + end end end diff --git a/spec/listeners/hook_listener_spec.rb b/spec/listeners/hook_listener_spec.rb index 4caa4dafd..3ae031237 100644 --- a/spec/listeners/hook_listener_spec.rb +++ b/spec/listeners/hook_listener_spec.rb @@ -10,6 +10,8 @@ describe HookListener do account: account, inbox: inbox, conversation: conversation) end let!(:event) { Events::Base.new(event_name, Time.zone.now, message: message) } + let(:contact_event) { Events::Base.new('contact.updated', Time.zone.now, contact: conversation.contact) } + let(:conversation_event) { Events::Base.new('conversation.created', Time.zone.now, conversation: conversation) } describe '#message_created' do let(:event_name) { 'message.created' } @@ -42,10 +44,88 @@ describe HookListener do context 'when hook is configured' do it 'triggers hook job' do - hook = create(:integrations_hook, account: account) + hook = create(:integrations_hook, :dialogflow, account: account, inbox: inbox) expect(HookJob).to receive(:perform_later).with(hook, 'message.updated', message: message).once listener.message_updated(event) end end end + + describe 'hook job enqueuing behavior' do + let(:event_name) { 'message.created' } + + context 'when app_id is not in the allowed list' do + it 'does not enqueue the job' do + create(:integrations_hook, account: account, app_id: 'unsupported_app') + expect(HookJob).not_to receive(:perform_later) + + listener.message_created(event) + end + end + + context 'when hook is enabled and app_id is supported' do + it 'enqueues the job for slack' do + hook = create(:integrations_hook, account: account) + expect(HookJob).to receive(:perform_later).with(hook, event_name, message: message) + + listener.message_created(event) + end + + it 'enqueues the job for dialogflow' do + hook = create(:integrations_hook, :dialogflow, account: account, inbox: inbox) + expect(HookJob).to receive(:perform_later).with(hook, event_name, message: message) + + listener.message_created(event) + end + + it 'enqueues the job for google_translate' do + hook = create(:integrations_hook, :google_translate, account: account) + expect(HookJob).to receive(:perform_later).with(hook, event_name, message: message) + + listener.message_created(event) + end + end + + context 'with disabled hook' do + it 'does not enqueue job for disabled hooks' do + create(:integrations_hook, account: account, status: 'disabled', app_id: 'slack') + expect(HookJob).not_to receive(:perform_later) + + listener.message_created(event) + end + end + + context 'with unsupported app_id and event combination' do + it 'does not enqueue job for unsupported app_id' do + create(:integrations_hook, account: account, app_id: 'unsupported_app') + expect(HookJob).not_to receive(:perform_later) + + listener.message_created(event) + end + end + + context 'with leadsquared hook' do + let(:hook) { create(:integrations_hook, :leadsquared, account: account) } + + before do + account.enable_features(:crm_integration) + end + + it 'enqueues the job for conversation.created' do + expect(HookJob) + .to receive(:perform_later) + .with(hook, 'conversation.created', { conversation: conversation }) + + listener.conversation_created(conversation_event) + end + + it 'enqueues the job for contact.updated' do + expect(HookJob) + .to receive(:perform_later) + .with(hook, 'contact.updated', { contact: conversation.contact }) + + listener.contact_updated(contact_event) + end + end + end end diff --git a/spec/mailboxes/imap/imap_mailbox_spec.rb b/spec/mailboxes/imap/imap_mailbox_spec.rb index cc72be18b..fc94c98be 100644 --- a/spec/mailboxes/imap/imap_mailbox_spec.rb +++ b/spec/mailboxes/imap/imap_mailbox_spec.rb @@ -115,6 +115,14 @@ RSpec.describe Imap::ImapMailbox do end end + context 'when the email is bounced' do + let!(:bounced_mail) { create_inbound_email_from_fixture('bounced_gmail.eml') } + + it 'processes the bounced email' do + expect { class_instance.process(bounced_mail.mail, channel) }.to change(Message, :count) + end + end + context 'when a reply for existing email conversation' do let(:prev_conversation) { create(:conversation, account: account, inbox: channel.inbox, assignee: agent) } let(:reply_mail) do diff --git a/spec/services/whatsapp/incoming_message_service_spec.rb b/spec/services/whatsapp/incoming_message_service_spec.rb index 0bcbf2a3e..4035a47df 100644 --- a/spec/services/whatsapp/incoming_message_service_spec.rb +++ b/spec/services/whatsapp/incoming_message_service_spec.rb @@ -267,19 +267,16 @@ describe Whatsapp::IncomingMessageService do ] }] }.with_indifferent_access described_class.new(inbox: whatsapp_channel.inbox, params: params).perform expect(Contact.all.first.name).to eq('Kedar') - expect(whatsapp_channel.inbox.conversations.count).not_to eq(0) - # Two messages are tested deliberately to ensure multiple contact attachments work. m1 = whatsapp_channel.inbox.messages.first - contact_attachments = m1.attachments.first expect(m1.content).to eq('Apple Inc.') - expect(contact_attachments.fallback_title).to eq('+911800') + expect(m1.attachments.first.fallback_title).to eq('+911800') + expect(m1.attachments.first.meta).to eq({}) m2 = whatsapp_channel.inbox.messages.last - contact_attachments = m2.attachments.first expect(m2.content).to eq('Chatwoot') - expect(contact_attachments.fallback_title).to eq('+1 (415) 341-8386') + expect(m2.attachments.first.meta).to eq({ 'firstName' => 'Chatwoot' }) end end