feat: add references header to reply emails (#11719)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -137,6 +137,99 @@ RSpec.describe ConversationReplyMailer do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with references header' do
|
||||
let(:conversation) { create(:conversation, assignee: agent, inbox: email_channel.inbox, account: account).reload }
|
||||
let(:message) { create(:message, conversation: conversation, account: account, message_type: 'outgoing', content: 'Outgoing Message 2') }
|
||||
let(:mail) { described_class.email_reply(message).deliver_now }
|
||||
|
||||
context 'when starting a new conversation' do
|
||||
let(:first_outgoing_message) do
|
||||
create(:message,
|
||||
conversation: conversation,
|
||||
account: account,
|
||||
message_type: 'outgoing',
|
||||
content: 'First outgoing message')
|
||||
end
|
||||
let(:mail) { described_class.email_reply(first_outgoing_message).deliver_now }
|
||||
|
||||
it 'has only the conversation reference' do
|
||||
# When starting a conversation, references will have the default conversation ID
|
||||
# Extract domain from the actual references header to handle dynamic domain selection
|
||||
actual_domain = mail.references.split('@').last
|
||||
expected_reference = "account/#{account.id}/conversation/#{conversation.uuid}@#{actual_domain}"
|
||||
expect(mail.references).to eq(expected_reference)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when replying to a message with no references' do
|
||||
let(:incoming_message) do
|
||||
create(:message,
|
||||
conversation: conversation,
|
||||
account: account,
|
||||
message_type: 'incoming',
|
||||
source_id: '<incoming-123@example.com>',
|
||||
content: 'Incoming message',
|
||||
content_attributes: {
|
||||
'email' => {
|
||||
'message_id' => 'incoming-123@example.com'
|
||||
}
|
||||
})
|
||||
end
|
||||
let(:reply_message) do
|
||||
create(:message,
|
||||
conversation: conversation,
|
||||
account: account,
|
||||
message_type: 'outgoing',
|
||||
content: 'Reply to incoming')
|
||||
end
|
||||
let(:mail) { described_class.email_reply(reply_message).deliver_now }
|
||||
|
||||
before do
|
||||
incoming_message
|
||||
end
|
||||
|
||||
it 'includes only the in_reply_to id in references' do
|
||||
# References should only have the incoming message ID when no prior references exist
|
||||
expect(mail.references).to eq('incoming-123@example.com')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when replying to a message that has references' do
|
||||
let(:incoming_message_with_refs) do
|
||||
create(:message,
|
||||
conversation: conversation,
|
||||
account: account,
|
||||
message_type: 'incoming',
|
||||
source_id: '<incoming-456@example.com>',
|
||||
content: 'Incoming with references',
|
||||
content_attributes: {
|
||||
'email' => {
|
||||
'message_id' => 'incoming-456@example.com',
|
||||
'references' => ['<ref-1@example.com>', '<ref-2@example.com>']
|
||||
}
|
||||
})
|
||||
end
|
||||
let(:reply_message) do
|
||||
create(:message,
|
||||
conversation: conversation,
|
||||
account: account,
|
||||
message_type: 'outgoing',
|
||||
content: 'Reply to message with refs')
|
||||
end
|
||||
let(:mail) { described_class.email_reply(reply_message).deliver_now }
|
||||
|
||||
before do
|
||||
incoming_message_with_refs
|
||||
end
|
||||
|
||||
it 'includes existing references plus the in_reply_to id' do
|
||||
# Rails returns references as an array when multiple values are present
|
||||
expected_references = ['ref-1@example.com', 'ref-2@example.com', 'incoming-456@example.com']
|
||||
expect(mail.references).to eq(expected_references)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with email reply' do
|
||||
let(:conversation) { create(:conversation, assignee: agent, inbox: email_channel.inbox, account: account).reload }
|
||||
let(:message) { create(:message, conversation: conversation, account: account, message_type: 'outgoing', content: 'Outgoing Message 2') }
|
||||
|
||||
Reference in New Issue
Block a user