diff --git a/spec/mailboxes/reply_mailbox_spec.rb b/spec/mailboxes/reply_mailbox_spec.rb index b8b906494..5be48b67b 100644 --- a/spec/mailboxes/reply_mailbox_spec.rb +++ b/spec/mailboxes/reply_mailbox_spec.rb @@ -342,6 +342,49 @@ RSpec.describe ReplyMailbox do expect(other_conversation.messages.count).to eq(0) end end + + context 'when in_reply_to fails but references has valid conversation' do + before do + reply_mail_with_references.mail['In-Reply-To'] = '' + reply_mail_with_references.mail['References'] = "" + end + + it 'falls back to references header when in_reply_to lookup fails' do + described_class.receive reply_mail_with_references + expect(conversation_1.messages.last.content).to include("Let's talk about these images:") + end + end + + context 'when in_reply_to fails and references has message pattern' do + before do + reply_mail_with_references.mail['In-Reply-To'] = '' + reply_mail_with_references.mail['References'] = '' + end + + it 'falls back to references with message pattern when in_reply_to lookup fails' do + described_class.receive reply_mail_with_references + expect(conversation_1.messages.last.content).to include("Let's talk about these images:") + end + end + + context 'when in_reply_to fails and references has message source_id' do + before do + conversation_1.messages.create!( + source_id: 'valid-message-id@test.com', + account_id: account.id, + message_type: 'outgoing', + inbox_id: email_channel.inbox.id, + content: 'Previous message' + ) + reply_mail_with_references.mail['In-Reply-To'] = '' + reply_mail_with_references.mail['References'] = '' + end + + it 'falls back to references with source_id when in_reply_to lookup fails' do + described_class.receive reply_mail_with_references + expect(conversation_1.messages.last.content).to include("Let's talk about these images:") + end + end end end end