From a91e49ae57fa32e0c57b4bf59df022132b7111b3 Mon Sep 17 00:00:00 2001 From: Piotr Bednarz Date: Wed, 18 Nov 2026 09:59:07 +0100 Subject: [PATCH] Add rejected_at to the thread message delivery --- .../inbound_thread_message_delivery.rb | 2 ++ .../inbound_thread_message_delivery_spec.rb | 26 +++++++++++++-- spec/mailtrap/inbound_threads_api_spec.rb | 32 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/mailtrap/inbound_thread_message_delivery.rb b/lib/mailtrap/inbound_thread_message_delivery.rb index 8d5e95f..552190e 100644 --- a/lib/mailtrap/inbound_thread_message_delivery.rb +++ b/lib/mailtrap/inbound_thread_message_delivery.rb @@ -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 diff --git a/spec/mailtrap/inbound_thread_message_delivery_spec.rb b/spec/mailtrap/inbound_thread_message_delivery_spec.rb index c2794bd..4468e0d 100644 --- a/spec/mailtrap/inbound_thread_message_delivery_spec.rb +++ b/spec/mailtrap/inbound_thread_message_delivery_spec.rb @@ -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 @@ -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 + 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 diff --git a/spec/mailtrap/inbound_threads_api_spec.rb b/spec/mailtrap/inbound_threads_api_spec.rb index 850b2d1..0305be7 100644 --- a/spec/mailtrap/inbound_threads_api_spec.rb +++ b/spec/mailtrap/inbound_threads_api_spec.rb @@ -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' }