update Webhooks UI
This commit is contained in:
committed by
Pete Matsyburka
parent
4ea863592b
commit
fd3530ac62
@@ -44,7 +44,9 @@ RSpec.describe 'Template' do
|
||||
|
||||
it 'archives a template' do
|
||||
expect do
|
||||
click_button 'Archive'
|
||||
accept_confirm('Are you sure?') do
|
||||
click_button 'Archive'
|
||||
end
|
||||
end.to change { Template.active.count }.by(-1)
|
||||
|
||||
expect(page).to have_content('Template has been archived')
|
||||
|
||||
@@ -10,22 +10,58 @@ RSpec.describe 'Webhook Settings' do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it 'shows webhook settings page' do
|
||||
it 'shows webhook settings page with empty form when there are no webhooks' do
|
||||
visit settings_webhooks_path
|
||||
|
||||
expect(page).to have_content('Webhooks')
|
||||
expect(page).to have_field('Webhook URL')
|
||||
expect(page).to have_content('Webhook')
|
||||
expect(page).to have_content('Webhook URL')
|
||||
expect(page).to have_field('webhook_url[url]', type: 'url')
|
||||
expect(page).to have_button('Save')
|
||||
|
||||
WebhookUrl::EVENTS.each do |event|
|
||||
expect(page).to have_field(event, type: 'checkbox', disabled: true)
|
||||
expect(page).to have_field(event, type: 'checkbox')
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows list of webhooks when there are more than one' do
|
||||
webhook_urls = create_list(:webhook_url, 2, account:)
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
expect(page).to have_content('Webhooks')
|
||||
expect(page).to have_link('New Webhook')
|
||||
|
||||
webhook_urls.each do |webhook_url|
|
||||
expect(page).to have_content(webhook_url.url)
|
||||
|
||||
within("a[href='#{settings_webhook_path(webhook_url)}']") do
|
||||
webhook_url.events.each do |event|
|
||||
expect(page).to have_content(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows webhook settings page with pre-filled form when there is one webhook' do
|
||||
webhook_url = create(:webhook_url, account:)
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
expect(page).to have_content('Webhook')
|
||||
expect(page).to have_field('webhook_url[url]', type: 'url', with: webhook_url.url)
|
||||
expect(page).to have_button('Save')
|
||||
expect(page).to have_button('Delete')
|
||||
expect(page).to have_link('Add Secret')
|
||||
|
||||
WebhookUrl::EVENTS.each do |event|
|
||||
expect(page).to have_field(event, type: 'checkbox', checked: webhook_url.events.include?(event))
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates the webhook' do
|
||||
visit settings_webhooks_path
|
||||
|
||||
fill_in 'Webhook URL', with: 'https://example.com/webhook'
|
||||
fill_in 'webhook_url[url]', with: 'https://example.com/webhook'
|
||||
|
||||
expect do
|
||||
click_button 'Save'
|
||||
@@ -34,6 +70,8 @@ RSpec.describe 'Webhook Settings' do
|
||||
webhook_url = account.webhook_urls.first
|
||||
|
||||
expect(webhook_url.url).to eq('https://example.com/webhook')
|
||||
expect(page).to have_content('Webhook URL has been saved.')
|
||||
expect(page.current_path).to eq(settings_webhooks_path)
|
||||
end
|
||||
|
||||
it 'updates the webhook' do
|
||||
@@ -41,12 +79,14 @@ RSpec.describe 'Webhook Settings' do
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
fill_in 'Webhook URL', with: 'https://example.org/webhook'
|
||||
fill_in 'webhook_url[url]', with: 'https://example.org/webhook'
|
||||
click_button 'Save'
|
||||
|
||||
webhook_url.reload
|
||||
|
||||
expect(webhook_url.url).to eq('https://example.org/webhook')
|
||||
expect(page).to have_content('Webhook URL has been updated.')
|
||||
expect(page.current_path).to eq(settings_webhook_path(webhook_url))
|
||||
end
|
||||
|
||||
it 'deletes the webhook' do
|
||||
@@ -54,11 +94,14 @@ RSpec.describe 'Webhook Settings' do
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
fill_in 'Webhook URL', with: ''
|
||||
|
||||
expect do
|
||||
click_button 'Save'
|
||||
accept_confirm('Are you sure?') do
|
||||
click_button 'Delete'
|
||||
end
|
||||
end.to change(WebhookUrl, :count).by(-1)
|
||||
|
||||
expect(page).to have_content('Webhook URL has been deleted.')
|
||||
expect(page.current_path).to eq(settings_webhooks_path)
|
||||
end
|
||||
|
||||
it 'updates the webhook events' do
|
||||
@@ -94,6 +137,9 @@ RSpec.describe 'Webhook Settings' do
|
||||
|
||||
expect(webhook_url.secret).to eq({ 'X-Signature' => 'secret-value' })
|
||||
end
|
||||
|
||||
expect(page).to have_link('Edit Secret')
|
||||
expect(page).to have_content('Webhook Secret has been saved.')
|
||||
end
|
||||
|
||||
it 'removes a secret from the webhook' do
|
||||
@@ -113,5 +159,43 @@ RSpec.describe 'Webhook Settings' do
|
||||
|
||||
expect(webhook_url.secret).to eq({})
|
||||
end
|
||||
|
||||
expect(page).to have_link('Add Secret')
|
||||
expect(page).to have_content('Webhook Secret has been saved.')
|
||||
end
|
||||
|
||||
context 'when testing the webhook' do
|
||||
let!(:webhook_url) { create(:webhook_url, account:) }
|
||||
let!(:template) { create(:template, account:, author: user) }
|
||||
let!(:submission) { create(:submission, template:, created_by_user: user) }
|
||||
let!(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], completed_at: Time.current)
|
||||
end
|
||||
|
||||
it 'sends the webhook request' do
|
||||
visit settings_webhooks_path
|
||||
|
||||
expect do
|
||||
click_button 'Test Webhook'
|
||||
end.to change(SendFormCompletedWebhookRequestJob.jobs, :size).by(1)
|
||||
|
||||
args = SendFormCompletedWebhookRequestJob.jobs.last['args'].first
|
||||
|
||||
expect(args['webhook_url_id']).to eq(webhook_url.id)
|
||||
expect(args['submitter_id']).to eq(submitter.id)
|
||||
expect(page).to have_content('Webhook request has been sent.')
|
||||
end
|
||||
|
||||
it "doesn't resend the webhook request when the webhook is doesn't exist" do
|
||||
visit settings_webhooks_path
|
||||
|
||||
webhook_url.destroy
|
||||
|
||||
expect do
|
||||
click_button 'Test Webhook'
|
||||
end.not_to change(SendFormCompletedWebhookRequestJob.jobs, :size)
|
||||
|
||||
expect(page).to have_content('Unable to resend webhook request.')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user