feat: Remove restrictions on API channel webhook_url (#2261)

This commit is contained in:
Pranav Raj S
2021-05-13 15:03:25 +05:30
committed by GitHub
parent 35f8d01a0c
commit 836b317b8a
6 changed files with 50 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ describe WebhookListener do
let!(:event) { Events::Base.new(event_name, Time.zone.now, message: message) }
describe '#message_created' do
let(:event_name) { :'conversation.created' }
let(:event_name) { :'message.created' }
context 'when webhook is not configured' do
it 'does not trigger webhook' do
@@ -29,5 +29,39 @@ describe WebhookListener do
listener.message_created(event)
end
end
context 'when inbox is an API Channel' do
it 'triggers webhook if webhook_url is present' do
channel_api = create(:channel_api, account: account)
api_inbox = channel_api.inbox
api_conversation = create(:conversation, account: account, inbox: api_inbox, assignee: user)
api_message = create(
:message,
message_type: 'outgoing',
account: account,
inbox: api_inbox,
conversation: api_conversation
)
api_event = Events::Base.new(event_name, Time.zone.now, message: api_message)
expect(WebhookJob).to receive(:perform_later).with(channel_api.webhook_url, api_message.webhook_data.merge(event: 'message_created')).once
listener.message_created(api_event)
end
it 'does not trigger webhook if webhook_url is not present' do
channel_api = create(:channel_api, webhook_url: nil, account: account)
api_inbox = channel_api.inbox
api_conversation = create(:conversation, account: account, inbox: api_inbox, assignee: user)
api_message = create(
:message,
message_type: 'outgoing',
account: account,
inbox: channel_api.inbox,
conversation: api_conversation
)
api_event = Events::Base.new(event_name, Time.zone.now, message: api_message)
expect(WebhookJob).not_to receive(:perform_later)
listener.message_created(api_event)
end
end
end
end