Skip to content

Commit

Permalink
Avoid throwing an error for successful delivery statuses (#2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 authored Nov 20, 2024
1 parent ea357e7 commit 88bef93
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def message_params
def handle_statuses
statuses = @components[:statuses]
statuses.each do |status|
invalid_recipient_error = status[:errors].select { |error| error[:code].to_i.eql?(INVALID_MESSAGE_RECIPIENT_ERROR_CODE) }
invalid_recipient_error = status[:errors]&.select { |error| error[:code].to_i.eql?(INVALID_MESSAGE_RECIPIENT_ERROR_CODE) }
mark_inactive_contributor_inactive(status) if invalid_recipient_error.present?
handle_errors(status[:errors]) if status[:status].in?(UNSUCCESSFUL_DELIVERY)
end
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/whats_app/three_sixty_dialog_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@
end

describe 'statuses' do
context 'successful delivery' do
let(:successful_delivery) do
[{
'id' => 'valid_message_id',
'status' => 'delivered',
'timestamp' => '1732132030',
'recipient_id' => '49123456789',
'conversation' => {
'id' => 'valid_conversation_id', 'origin' => {
'type' => 'marketing'
}
},
'pricing' => {
'billable' => true, 'pricing_model' => 'CBP', 'category' => 'marketing'
}
}]
end

before { components[:statuses] = successful_delivery }

it 'is successful' do
subject.call
expect(response).to be_successful
end
end

context 'unsuccessful delivery' do
context 'failed delivery' do
let(:user) { create(:user, organizations: [organization]) }
Expand Down

0 comments on commit 88bef93

Please sign in to comment.