fix(sms): allow disabled inbox delivery callbacks
This commit is contained in:
@@ -8,7 +8,7 @@ class Webhooks::SmsEventsJob < ApplicationJob
|
||||
|
||||
channel = Channel::Sms.find_by(phone_number: params[:to])
|
||||
return unless channel
|
||||
return unless channel.inbox.active?
|
||||
return if incoming_event?(params) && !channel.inbox.active?
|
||||
|
||||
process_event_params(channel, params)
|
||||
end
|
||||
@@ -26,4 +26,8 @@ class Webhooks::SmsEventsJob < ApplicationJob
|
||||
def delivery_event?(params)
|
||||
params[:type] == 'message-delivered' || params[:type] == 'message-failed'
|
||||
end
|
||||
|
||||
def incoming_event?(params)
|
||||
params[:type] == 'message-received'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,6 +53,14 @@ RSpec.describe Webhooks::SmsEventsJob do
|
||||
described_class.perform_now(params)
|
||||
end
|
||||
|
||||
it 'does not call Sms::IncomingMessageService for received messages when the inbox is disabled' do
|
||||
sms_channel.inbox.update!(active: false)
|
||||
|
||||
expect(Sms::IncomingMessageService).not_to receive(:new)
|
||||
|
||||
described_class.perform_now(params)
|
||||
end
|
||||
|
||||
it 'calls Sms::DeliveryStatusService if the message type is message-delivered' do
|
||||
params[:type] = 'message-delivered'
|
||||
process_service = double
|
||||
@@ -64,6 +72,20 @@ RSpec.describe Webhooks::SmsEventsJob do
|
||||
described_class.perform_now(params)
|
||||
end
|
||||
|
||||
it 'calls Sms::DeliveryStatusService for delivered messages when the inbox is disabled' do
|
||||
sms_channel.inbox.update!(active: false)
|
||||
params[:type] = 'message-delivered'
|
||||
process_service = double
|
||||
allow(Sms::DeliveryStatusService).to receive(:new).and_return(process_service)
|
||||
allow(process_service).to receive(:perform)
|
||||
|
||||
expect(Sms::DeliveryStatusService).to receive(:new).with(channel: sms_channel,
|
||||
params: params[:message].with_indifferent_access)
|
||||
expect(process_service).to receive(:perform)
|
||||
|
||||
described_class.perform_now(params)
|
||||
end
|
||||
|
||||
it 'calls Sms::DeliveryStatusService if the message type is message-failed' do
|
||||
params[:type] = 'message-failed'
|
||||
process_service = double
|
||||
|
||||
Reference in New Issue
Block a user