From 1c2bf0e1aded9202f15ea04aca4df54a2fdc7ed9 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Wed, 20 Nov 2024 20:55:49 +0100 Subject: [PATCH] Avoid throwing an error for successful status deliveries --- .../three_sixty_dialog_webhook_controller.rb | 2 +- .../three_sixty_dialog_webhook_spec.rb | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/controllers/whats_app/three_sixty_dialog_webhook_controller.rb b/app/controllers/whats_app/three_sixty_dialog_webhook_controller.rb index de9c911a7..714f23201 100644 --- a/app/controllers/whats_app/three_sixty_dialog_webhook_controller.rb +++ b/app/controllers/whats_app/three_sixty_dialog_webhook_controller.rb @@ -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 diff --git a/spec/requests/whats_app/three_sixty_dialog_webhook_spec.rb b/spec/requests/whats_app/three_sixty_dialog_webhook_spec.rb index 5d3e637fb..7c3820642 100644 --- a/spec/requests/whats_app/three_sixty_dialog_webhook_spec.rb +++ b/spec/requests/whats_app/three_sixty_dialog_webhook_spec.rb @@ -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]) }