feat: IMAP Email Channel (#3298)
This change allows the user to configure both IMAP and SMTP for an email inbox. IMAP enables the user to see emails in Chatwoot. And user can use SMTP to reply to an email conversation. Users can use the default settings to send and receive emails for email inboxes if both IMAP and SMTP are disabled. Fixes #2520
This commit is contained in:
27
spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb
Normal file
27
spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Inboxes::FetchImapEmailInboxesJob, type: :job do
|
||||
let(:account) { create(:account) }
|
||||
let(:imap_email_channel) do
|
||||
create(:channel_email, imap_enabled: true, imap_address: 'imap.gmail.com', imap_port: 993, imap_email: 'imap@gmail.com',
|
||||
imap_password: 'password', account: account)
|
||||
end
|
||||
let(:email_inbox) { create(:inbox, channel: imap_email_channel, account: account) }
|
||||
|
||||
it 'enqueues the job' do
|
||||
expect { described_class.perform_later }.to have_enqueued_job(described_class)
|
||||
.on_queue('low')
|
||||
end
|
||||
|
||||
context 'when called' do
|
||||
it 'fetch all the email channels' do
|
||||
imap_email_inboxes = double
|
||||
allow(imap_email_inboxes).to receive(:all).and_return([email_inbox])
|
||||
allow(Inbox).to receive(:where).and_return(imap_email_inboxes)
|
||||
|
||||
expect(Inboxes::FetchImapEmailsJob).to receive(:perform_later).with(imap_email_channel).once
|
||||
|
||||
described_class.perform_now
|
||||
end
|
||||
end
|
||||
end
|
||||
37
spec/jobs/inboxes/fetch_imap_emails_job_spec.rb
Normal file
37
spec/jobs/inboxes/fetch_imap_emails_job_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Inboxes::FetchImapEmailsJob, type: :job do
|
||||
let(:account) { create(:account) }
|
||||
let(:imap_email_channel) do
|
||||
create(:channel_email, imap_enabled: true, imap_address: 'imap.gmail.com', imap_port: 993, imap_email: 'imap@gmail.com',
|
||||
imap_password: 'password', imap_inbox_synced_at: Time.now.utc - 10, account: account)
|
||||
end
|
||||
let(:email_inbox) { create(:inbox, channel: imap_email_channel, account: account) }
|
||||
|
||||
it 'enqueues the job' do
|
||||
expect { described_class.perform_later }.to have_enqueued_job(described_class)
|
||||
.on_queue('low')
|
||||
end
|
||||
|
||||
context 'when imap fetch latest 10 emails' do
|
||||
it 'check for the new emails' do
|
||||
mail_date = Time.now.utc
|
||||
mail = Mail.new do
|
||||
to 'test@outlook.com'
|
||||
from 'test@gmail.com'
|
||||
subject :test.to_s
|
||||
body 'hello'
|
||||
date mail_date
|
||||
end
|
||||
|
||||
allow(Mail).to receive(:find).and_return([mail])
|
||||
imap_mailbox = double
|
||||
allow(Imap::ImapMailbox).to receive(:new).and_return(imap_mailbox)
|
||||
expect(imap_mailbox).to receive(:process).with(mail, imap_email_channel).once
|
||||
|
||||
described_class.perform_now(imap_email_channel)
|
||||
|
||||
expect(imap_email_channel.reload.imap_inbox_synced_at).to be > mail_date
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user