fix: handle missing email channels without raising errors
- Return nil from NewConversationStrategy when channel not found - Update tests to expect nil instead of exceptions - Align BCC test with graceful handling behavior
This commit is contained in:
@@ -8,9 +8,7 @@ class Mailbox::ConversationFinderStrategies::NewConversationStrategy < Mailbox::
|
||||
# It should be used as the last strategy in the chain to ensure emails are never dropped.
|
||||
def find
|
||||
channel = EmailChannelFinder.new(mail).perform
|
||||
|
||||
# Match old SupportMailbox behavior - raise error when no channel found
|
||||
raise 'Email channel/inbox not found' if channel.nil?
|
||||
return nil unless channel # No valid channel found
|
||||
|
||||
@account = channel.account
|
||||
@inbox = channel.inbox
|
||||
|
||||
@@ -687,7 +687,8 @@ RSpec.describe ReplyMailbox do
|
||||
bcc_mail.mail['to'] = nil
|
||||
bcc_mail.mail['bcc'] = 'care@example.com'
|
||||
|
||||
expect { described_class.receive bcc_mail }.to raise_error('Email channel/inbox not found')
|
||||
described_class.receive bcc_mail
|
||||
expect(conversation.present?).to be(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+4
-4
@@ -111,13 +111,13 @@ RSpec.describe Mailbox::ConversationFinderStrategies::NewConversationStrategy do
|
||||
mail.to = ['nonexistent@example.com']
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
it 'returns nil' do
|
||||
strategy = described_class.new(mail)
|
||||
|
||||
expect do
|
||||
strategy.find
|
||||
end.to raise_error('Email channel/inbox not found')
|
||||
.and not_change(Conversation, :count)
|
||||
result = strategy.find
|
||||
expect(result).to be_nil
|
||||
end.not_to change(Conversation, :count)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user