Skip to content

Commit f999c4f

Browse files
authored
Merge pull request #12 from benjaminhouy/main
Add reply_to support to DeliveryMethod
2 parents bc7419f + 3783f24 commit f999c4f

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

lib/userlist/delivery_method.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ def serialize(mail)
1919
{
2020
to: serialize_address(mail.to),
2121
from: serialize_address(mail.from),
22+
reply_to: serialize_address(mail.reply_to),
2223
subject: mail.subject,
2324
body: serialize_body(mail.body)
2425
}.compact
2526
end
2627

2728
def serialize_address(address)
29+
return if address.nil? || Array(address).empty?
30+
2831
Array(address).map(&:to_s)
2932
end
3033

spec/userlist/delivery_method_spec.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,55 @@
104104
delivery_method.deliver!(mail)
105105
end
106106
end
107+
108+
context 'with reply_to address' do
109+
let(:mail) do
110+
Mail.new(
111+
to: 'user@example.com',
112+
from: 'sender@example.com',
113+
reply_to: 'reply@example.com',
114+
subject: 'Test Subject',
115+
body: 'Hello world'
116+
)
117+
end
118+
119+
it 'includes reply_to in the payload' do
120+
expected_payload = {
121+
to: ['user@example.com'],
122+
from: ['sender@example.com'],
123+
reply_to: ['reply@example.com'],
124+
subject: 'Test Subject',
125+
body: { type: :text, content: 'Hello world' },
126+
theme: nil
127+
}
128+
129+
expect(messages).to receive(:push).with(expected_payload)
130+
delivery_method.deliver!(mail)
131+
end
132+
end
133+
134+
context 'without reply_to address' do
135+
let(:mail) do
136+
Mail.new(
137+
to: 'user@example.com',
138+
from: 'sender@example.com',
139+
subject: 'Test Subject',
140+
body: 'Hello world'
141+
)
142+
end
143+
144+
it 'omits reply_to from the payload' do
145+
expected_payload = {
146+
to: ['user@example.com'],
147+
from: ['sender@example.com'],
148+
subject: 'Test Subject',
149+
body: { type: :text, content: 'Hello world' },
150+
theme: nil
151+
}
152+
153+
expect(messages).to receive(:push).with(expected_payload)
154+
delivery_method.deliver!(mail)
155+
end
156+
end
107157
end
108158
end

0 commit comments

Comments
 (0)