Fix: Find mailbox with cc email (#4372)
This commit is contained in:
29
spec/finders/email_channel_finder_spec.rb
Normal file
29
spec/finders/email_channel_finder_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::EmailChannelFinder do
|
||||
include ActionMailbox::TestHelper
|
||||
let!(:channel_email) { create(:channel_email) }
|
||||
|
||||
describe '#perform' do
|
||||
context 'with cc mail' do
|
||||
let(:reply_cc_mail) { create_inbound_email_from_fixture('reply_cc.eml') }
|
||||
|
||||
it 'return channel with cc email' do
|
||||
channel_email.update(email: 'test@example.com')
|
||||
channel = described_class.new(reply_cc_mail.mail).perform
|
||||
expect(channel).to eq(channel_email)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with to mail' do
|
||||
let(:reply_mail) { create_inbound_email_from_fixture('reply.eml') }
|
||||
|
||||
it 'return channel with to email' do
|
||||
channel_email.update(email: 'test@example.com')
|
||||
reply_mail.mail['to'] = 'test@example.com'
|
||||
channel = described_class.new(reply_mail.mail).perform
|
||||
expect(channel).to eq(channel_email)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
2
spec/fixtures/files/in_reply_to.eml
vendored
2
spec/fixtures/files/in_reply_to.eml
vendored
@@ -5,7 +5,7 @@ Subject: Discussion: Let's debate these attachments
|
||||
Date: Tue, 20 Apr 2020 04:20:20 -0400
|
||||
In-Reply-To: <0CB459E0-0336-41DA-BC88-E6E28C697DDB@chatwoot.com>
|
||||
References: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>
|
||||
Message-Id: <0CB459E0-0336-41DA-BC88-E6E28C697DDB@chatwoot.com>
|
||||
Message-Id: <0CB459E0-0336-41DA-BC88-E6E28C697DDBF@chatwoot.com>
|
||||
X-Mailer: Apple Mail (2.1244.3)
|
||||
|
||||
--Apple-Mail=_33A037C7-4BB3-4772-AE52-FCF2D7535F74
|
||||
|
||||
30
spec/fixtures/files/reply_cc.eml
vendored
Normal file
30
spec/fixtures/files/reply_cc.eml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
MIME-Version: 1.0
|
||||
Date: Thu, 31 Mar 2022 19:25:32 +0530
|
||||
Message-ID: <CAFkiBVw2B=CPf=8=VqBQqssFp7XfGm4u6LpByHuMXWsPZCxPYQ@mail.gmail.com>
|
||||
Subject: Discussion: Let's debate these attachments
|
||||
From: Sony Mathew <sony@chatwoot.com>
|
||||
To: <test123@example.com>
|
||||
Cc: Replies <test@example.com>
|
||||
Content-Type: multipart/alternative; boundary="00000000000001f49e05db8404a8"
|
||||
|
||||
--00000000000001f49e05db8404a8
|
||||
Content-Type: text/plain; charset="UTF-8"
|
||||
|
||||
Hello,
|
||||
|
||||
Find the related inbox.
|
||||
|
||||
--
|
||||
*Sony Mathew*
|
||||
|
||||
--00000000000001f49e05db8404a8
|
||||
Content-Type: text/html; charset="UTF-8"
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
<div dir=3D"ltr">Hello,<div><br></div><div>Find the related inbox.<br clear=
|
||||
=3D"all"><div><br></div>-- <br><div dir=3D"ltr" class=3D"gmail_signature" d=
|
||||
ata-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><d=
|
||||
iv><div><b>Sony Mathew</b><br></div><br></di=
|
||||
v></div></div></div></div></div></div>
|
||||
|
||||
--00000000000001f49e05db8404a8--
|
||||
@@ -6,6 +6,7 @@ RSpec.describe ApplicationMailbox, type: :mailbox do
|
||||
describe 'route the inbound mail to appropriate mailbox' do
|
||||
let(:welcome_mail) { create_inbound_email_from_fixture('welcome.eml') }
|
||||
let(:reply_mail) { create_inbound_email_from_fixture('reply.eml') }
|
||||
let(:reply_cc_mail) { create_inbound_email_from_fixture('reply_cc.eml') }
|
||||
let(:reply_mail_without_uuid) { create_inbound_email_from_fixture('reply.eml') }
|
||||
let(:reply_mail_with_in_reply_to) { create_inbound_email_from_fixture('in_reply_to.eml') }
|
||||
let(:support_mail) { create_inbound_email_from_fixture('support.eml') }
|
||||
@@ -55,6 +56,14 @@ RSpec.describe ApplicationMailbox, type: :mailbox do
|
||||
expect(dbl).to receive(:perform_processing).and_return(true)
|
||||
described_class.route support_mail
|
||||
end
|
||||
|
||||
it 'routes support emails to Support Mailbox with cc email' do
|
||||
channel_email.update(email: 'test@example.com')
|
||||
dbl = double
|
||||
expect(SupportMailbox).to receive(:new).and_return(dbl)
|
||||
expect(dbl).to receive(:perform_processing).and_return(true)
|
||||
described_class.route reply_cc_mail
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -148,6 +148,7 @@ RSpec.describe SupportMailbox, type: :mailbox do
|
||||
expect(conversation_1.messages.count).to eq(1)
|
||||
|
||||
reply_mail_without_uuid.mail['In-Reply-To'] = 'conversation/6bdc3f4d-0bec-4515-a284-5d916fdde489/messages/123'
|
||||
reply_mail_without_uuid.mail['Message-Id'] = '0CB459E0-0336-41DA-BC88-E6E28C697SFC@chatwoot.com'
|
||||
|
||||
described_class.receive reply_mail_without_uuid
|
||||
|
||||
|
||||
Reference in New Issue
Block a user