forked from chatwoot/chatwoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from DigitalTolk/1103-fix-merged-contact
fix: INT-1103 merged contact
- Loading branch information
Showing
3 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
From: Sony Mathew <[email protected]> | ||
Mime-Version: 1.0 (Apple Message framework v1244.3) | ||
Content-Type: multipart/alternative; boundary="Apple-Mail=_33A037C7-4BB3-4772-AE52-FCF2D7535F74" | ||
Subject: Discussion: Let's debate these attachments | ||
Date: Tue, 20 Apr 2020 04:20:20 -0400 | ||
In-Reply-To: <[email protected]> | ||
References: <[email protected]> <test-reference-id> | ||
Message-Id: <[email protected]> | ||
X-Mailer: Apple Mail (2.1244.3) | ||
|
||
--Apple-Mail=_33A037C7-4BB3-4772-AE52-FCF2D7535F74 | ||
Content-Transfer-Encoding: quoted-printable | ||
Content-Type: text/plain; | ||
charset=utf-8 | ||
References Email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ | |
end | ||
|
||
context 'when a reply for existing email conversation' do | ||
let(:prev_conversation) { create(:conversation, account: account, inbox: channel.inbox, assignee: agent) } | ||
let(:prev_conversation) { create(:conversation, account: account, inbox: channel.inbox, assignee: agent, contact: contact) } | ||
let(:reply_mail) do | ||
create_inbound_email_from_mail(from: '[email protected]', to: '[email protected]', subject: 'Hello!', in_reply_to: 'test-in-reply-to') | ||
end | ||
|
@@ -101,6 +101,28 @@ | |
end | ||
end | ||
|
||
context 'when a reply is from a different contact' do | ||
let(:prev_conversation) { create(:conversation, account: account, inbox: channel.inbox, assignee: agent, contact: contact) } | ||
let(:references_email) { create_inbound_email_from_fixture('references.eml') } | ||
|
||
it 'creates a new conversation' do | ||
message = create( | ||
:message, | ||
content: 'Incoming Message', | ||
message_type: 'incoming', | ||
inbox: inbox, | ||
account: account, | ||
conversation: conversation | ||
) | ||
|
||
conversation = message.conversation | ||
conversation.update_column(:contact_id, contact.id) | ||
expect(conversation.messages.size).to eq(1) | ||
|
||
expect { class_instance.process(references_email.mail, inbox.channel) }.to change { Conversation.count }.by(1) | ||
end | ||
end | ||
|
||
context 'when a new conversation with nil in_reply_to' do | ||
let(:prev_conversation) { create(:conversation, account: account, inbox: channel.inbox, assignee: agent) } | ||
let(:reply_mail) do | ||
|
@@ -142,6 +164,7 @@ | |
create_inbound_email_from_mail(from: '[email protected]', to: '[email protected]', subject: 'Hello!', in_reply_to: 'test-in-reply-to') | ||
end | ||
let(:references_email) { create_inbound_email_from_fixture('references.eml') } | ||
let(:references_same_email) { create_inbound_email_from_fixture('references-same.eml') } | ||
|
||
it 'creates new email conversation with incoming in-reply-to' do | ||
class_instance.process(reply_mail.mail, channel) | ||
|
@@ -160,16 +183,18 @@ | |
conversation: conversation | ||
) | ||
conversation = message.conversation | ||
conversation.update_column(:contact_id, contact.id) | ||
|
||
expect(conversation.messages.size).to eq(1) | ||
|
||
class_instance.process(references_email.mail, inbox.channel) | ||
class_instance.process(references_same_email.mail, inbox.channel) | ||
|
||
expect(conversation.messages.size).to eq(2) | ||
expect(conversation.messages.last.content).to eq('References Email') | ||
expect(references_email.mail.references).to include('test-reference-id') | ||
expect(references_same_email.mail.references).to include('test-reference-id') | ||
end | ||
|
||
|
||
it 'append email to conversation with reference id string' do | ||
inbox = Inbox.last | ||
message = create( | ||
|
@@ -182,15 +207,21 @@ | |
conversation: conversation | ||
) | ||
conversation = message.conversation | ||
|
||
conversation.update_column(:contact_id, contact.id) | ||
expect(conversation.messages.size).to eq(1) | ||
|
||
references_email.mail.references = 'test-reference-id-2' | ||
class_instance.process(references_email.mail, inbox.channel) | ||
references_same_email.mail.references = 'test-reference-id-2' | ||
class_instance.process(references_same_email.mail, inbox.channel) | ||
|
||
expect(conversation.messages.size).to eq(2) | ||
expect(conversation.messages.last.content).to eq('References Email') | ||
expect(references_email.mail.references).to include('test-reference-id-2') | ||
expect(references_same_email.mail.references).to include('test-reference-id-2') | ||
end | ||
|
||
context 'when message is from a different contact' do | ||
it 'creates a new conversation' do | ||
expect { class_instance.process(references_email.mail, inbox.channel) }.to change { Conversation.count }.by(1) | ||
end | ||
end | ||
end | ||
|
||
|