feat: Add event subscription option to webhooks (#4540)
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -57,6 +57,36 @@ RSpec.describe 'Webhooks API', type: :request do
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)['message']).to eql 'Url is invalid'
|
||||
end
|
||||
|
||||
it 'throws error if subscription events are invalid' do
|
||||
post "/api/v1/accounts/#{account.id}/webhooks",
|
||||
params: { url: 'https://hello.com', subscriptions: ['conversation_random_event'] },
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)['message']).to eql 'Subscriptions Invalid events'
|
||||
end
|
||||
|
||||
it 'throws error if subscription events are empty' do
|
||||
post "/api/v1/accounts/#{account.id}/webhooks",
|
||||
params: { url: 'https://hello.com', subscriptions: [] },
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)['message']).to eql 'Subscriptions Invalid events'
|
||||
end
|
||||
|
||||
it 'use default if subscription events are nil' do
|
||||
post "/api/v1/accounts/#{account.id}/webhooks",
|
||||
params: { url: 'https://hello.com', subscriptions: nil },
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(
|
||||
JSON.parse(response.body)['payload']['webhook']['subscriptions']
|
||||
).to eql %w[conversation_status_changed conversation_updated conversation_created message_created message_updated
|
||||
webwidget_triggered]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user