Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/userlist/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ def serialize(mail)
{
to: serialize_address(mail.to),
from: serialize_address(mail.from),
reply_to: serialize_address(mail.reply_to),
subject: mail.subject,
body: serialize_body(mail.body)
}.compact
end

def serialize_address(address)
return if address.nil? || Array(address).empty?

Array(address).map(&:to_s)
end

Expand Down
50 changes: 50 additions & 0 deletions spec/userlist/delivery_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,55 @@
delivery_method.deliver!(mail)
end
end

context 'with reply_to address' do
let(:mail) do
Mail.new(
to: 'user@example.com',
from: 'sender@example.com',
reply_to: 'reply@example.com',
subject: 'Test Subject',
body: 'Hello world'
)
end

it 'includes reply_to in the payload' do
expected_payload = {
to: ['user@example.com'],
from: ['sender@example.com'],
reply_to: ['reply@example.com'],
subject: 'Test Subject',
body: { type: :text, content: 'Hello world' },
theme: nil
}

expect(messages).to receive(:push).with(expected_payload)
delivery_method.deliver!(mail)
end
end

context 'without reply_to address' do
let(:mail) do
Mail.new(
to: 'user@example.com',
from: 'sender@example.com',
subject: 'Test Subject',
body: 'Hello world'
)
end

it 'omits reply_to from the payload' do
expected_payload = {
to: ['user@example.com'],
from: ['sender@example.com'],
subject: 'Test Subject',
body: { type: :text, content: 'Hello world' },
theme: nil
}

expect(messages).to receive(:push).with(expected_payload)
delivery_method.deliver!(mail)
end
end
end
end