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
2 changes: 2 additions & 0 deletions lib/mailtrap/inbound_thread_message_delivery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ module Mailtrap
# @attr_reader status [String] The delivery status
# @attr_reader delivered_at [String, nil] Delivery timestamp
# @attr_reader bounced_at [String, nil] Bounce timestamp
# @attr_reader rejected_at [String, nil] Rejection timestamp, e.g. a suppressed recipient
InboundThreadMessageDelivery = Struct.new(
:to,
:status,
:delivered_at,
:bounced_at,
:rejected_at,
keyword_init: true
)
end
26 changes: 24 additions & 2 deletions spec/mailtrap/inbound_thread_message_delivery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
to: 'customer@example.com',
status: 'delivered',
delivered_at: '2026-05-08T11:40:05.000Z',
bounced_at: nil
bounced_at: nil,
rejected_at: nil
)
end

Expand All @@ -16,8 +17,29 @@
to: 'customer@example.com',
status: 'delivered',
delivered_at: '2026-05-08T11:40:05.000Z',
bounced_at: nil
bounced_at: nil,
rejected_at: nil
)
end

context 'when the message was rejected before sending' do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[could] This spec builds the struct directly, so it would still pass if InboundThreadsAPI#get stopped passing rejected_at through (build_delivery slices the response by the struct's members). Consider adding a case to inbound_threads_api_spec.rb that stubs a get response with a non-null delivery.rejected_at and asserts get.messages.first.delivery.rejected_at, the same way the other SDKs test it.

subject(:delivery) do
described_class.new(
to: 'suppressed@example.com',
status: 'not_delivered',
delivered_at: nil,
bounced_at: nil,
rejected_at: '2026-05-08T11:40:01.000Z'
)
end

it 'keeps the rejection timestamp' do
expect(delivery).to have_attributes(
status: 'not_delivered',
delivered_at: nil,
rejected_at: '2026-05-08T11:40:01.000Z'
)
end
end
end
end
32 changes: 32 additions & 0 deletions spec/mailtrap/inbound_threads_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@
end
end

context 'with a sent reply rejected before sending', vcr: false do
let(:delivery) do
{
to: 'suppressed@example.com',
status: 'not_delivered',
delivered_at: nil,
bounced_at: nil,
rejected_at: '2026-05-08T11:40:01.000Z'
}
end

before do
stub_request(:get, "https://mailtrap.io/api/inbound/inboxes/#{inbox_id}/threads/#{thread_id}")
.to_return(
status: 200,
body: {
id: thread_id,
messages: [{ visibility_status: 'available', direction: 'outbound', delivery: }]
}.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end

it 'maps rejected_at on the delivery' do
expect(get.messages.first.delivery).to have_attributes(
status: 'not_delivered',
bounced_at: nil,
rejected_at: '2026-05-08T11:40:01.000Z'
)
end
end

context 'when the thread does not exist' do
let(:thread_id) { 'does-not-exist' }

Expand Down
Loading