use webhook urls instead of encrypted configs
This commit is contained in:
committed by
Pete Matsyburka
parent
f669045362
commit
84edb6dbda
@@ -8,24 +8,110 @@ RSpec.describe 'Webhook Settings' do
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
visit settings_webhooks_path
|
||||
end
|
||||
|
||||
it 'shows webhook settings page' do
|
||||
visit settings_webhooks_path
|
||||
|
||||
expect(page).to have_content('Webhooks')
|
||||
expect(page).to have_field('Webhook URL')
|
||||
expect(page).to have_button('Save')
|
||||
|
||||
WebhookUrl::EVENTS.each do |event|
|
||||
expect(page).to have_field(event, type: 'checkbox', disabled: true)
|
||||
end
|
||||
end
|
||||
|
||||
it 'updates the webhook URL' do
|
||||
fill_in 'Webhook URL', with: 'https://example.com'
|
||||
it 'creates the webhook' do
|
||||
visit settings_webhooks_path
|
||||
|
||||
fill_in 'Webhook URL', with: 'https://example.com/webhook'
|
||||
|
||||
expect do
|
||||
click_button 'Save'
|
||||
end.to change(EncryptedConfig, :count).by(1)
|
||||
end.to change(WebhookUrl, :count).by(1)
|
||||
|
||||
encrypted_config = EncryptedConfig.find_by(account:, key: EncryptedConfig::WEBHOOK_URL_KEY)
|
||||
webhook_url = account.webhook_urls.first
|
||||
|
||||
expect(encrypted_config.value).to eq('https://example.com')
|
||||
expect(webhook_url.url).to eq('https://example.com/webhook')
|
||||
end
|
||||
|
||||
it 'updates the webhook' do
|
||||
webhook_url = create(:webhook_url, account:, url: 'https://example.com/webhook')
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
fill_in 'Webhook URL', with: 'https://example.org/webhook'
|
||||
click_button 'Save'
|
||||
|
||||
webhook_url.reload
|
||||
|
||||
expect(webhook_url.url).to eq('https://example.org/webhook')
|
||||
end
|
||||
|
||||
it 'deletes the webhook' do
|
||||
create(:webhook_url, account:)
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
fill_in 'Webhook URL', with: ''
|
||||
|
||||
expect do
|
||||
click_button 'Save'
|
||||
end.to change(WebhookUrl, :count).by(-1)
|
||||
end
|
||||
|
||||
it 'updates the webhook events' do
|
||||
webhook_url = create(:webhook_url, account:)
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
expect(webhook_url.events).not_to include('submission.created')
|
||||
|
||||
check('submission.created')
|
||||
|
||||
webhook_url.reload
|
||||
|
||||
expect(webhook_url.events).to include('submission.created')
|
||||
end
|
||||
|
||||
it 'adds a secret to the webhook' do
|
||||
webhook_url = create(:webhook_url, account:)
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
expect(webhook_url.secret).to be_nil
|
||||
|
||||
click_link 'Add Secret'
|
||||
|
||||
within '#modal' do
|
||||
fill_in 'Key', with: 'X-Signature'
|
||||
fill_in 'Value', with: 'secret-value'
|
||||
|
||||
click_button 'Submit'
|
||||
|
||||
webhook_url.reload
|
||||
|
||||
expect(webhook_url.secret).to eq({ 'X-Signature' => 'secret-value' })
|
||||
end
|
||||
end
|
||||
|
||||
it 'removes a secret from the webhook' do
|
||||
webhook_url = create(:webhook_url, account:, secret: { 'X-Signature' => 'secret-value' })
|
||||
|
||||
visit settings_webhooks_path
|
||||
|
||||
click_link 'Edit Secret'
|
||||
|
||||
within '#modal' do
|
||||
fill_in 'Key', with: ''
|
||||
fill_in 'Value', with: ''
|
||||
|
||||
click_button 'Submit'
|
||||
|
||||
webhook_url.reload
|
||||
|
||||
expect(webhook_url.secret).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user