|
3 | 3 | RSpec.describe 'Webhooks API', type: :request do |
4 | 4 | let(:account) { create(:account) } |
5 | 5 | let(:inbox) { create(:inbox, account: account) } |
6 | | - let(:webhook) { create(:webhook, account: account, inbox: inbox, url: 'https://hello.com') } |
| 6 | + let(:webhook) { create(:webhook, account: account, inbox: inbox, url: 'https://hello.com', name: 'My Webhook') } |
7 | 7 | let(:administrator) { create(:user, account: account, role: :administrator) } |
8 | 8 | let(:agent) { create(:user, account: account, role: :agent) } |
9 | 9 |
|
|
49 | 49 | expect(response.parsed_body['payload']['webhook']['url']).to eql 'https://hello.com' |
50 | 50 | end |
51 | 51 |
|
| 52 | + it 'creates webhook with name' do |
| 53 | + post "/api/v1/accounts/#{account.id}/webhooks", |
| 54 | + params: { account_id: account.id, inbox_id: inbox.id, url: 'https://hello.com', name: 'My Webhook' }, |
| 55 | + headers: administrator.create_new_auth_token, |
| 56 | + as: :json |
| 57 | + expect(response).to have_http_status(:success) |
| 58 | + |
| 59 | + expect(response.parsed_body['payload']['webhook']['name']).to eql 'My Webhook' |
| 60 | + end |
| 61 | + |
52 | 62 | it 'throws error when invalid url provided' do |
53 | 63 | post "/api/v1/accounts/#{account.id}/webhooks", |
54 | 64 | params: { account_id: account.id, inbox_id: inbox.id, url: 'javascript:alert(1)' }, |
|
103 | 113 | context 'when it is an authenticated admin user' do |
104 | 114 | it 'updates webhook' do |
105 | 115 | put "/api/v1/accounts/#{account.id}/webhooks/#{webhook.id}", |
106 | | - params: { url: 'https://hello.com' }, |
| 116 | + params: { url: 'https://hello.com', name: 'Another Webhook' }, |
107 | 117 | headers: administrator.create_new_auth_token, |
108 | 118 | as: :json |
109 | 119 | expect(response).to have_http_status(:success) |
110 | 120 | expect(response.parsed_body['payload']['webhook']['url']).to eql 'https://hello.com' |
| 121 | + expect(response.parsed_body['payload']['webhook']['name']).to eql 'Another Webhook' |
111 | 122 | end |
112 | 123 | end |
113 | 124 | end |
|
0 commit comments