2023-02-21 19:55:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-09 15:57:36 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-03 23:49:53 -04:00
|
|
|
RSpec.describe Webhook do
|
2022-06-09 15:57:36 -04:00
|
|
|
let(:webhook) { Fabricate(:webhook) }
|
|
|
|
|
2023-11-13 17:47:44 -05:00
|
|
|
describe 'Validations' do
|
2024-09-05 11:36:05 -04:00
|
|
|
it { is_expected.to validate_presence_of(:events) }
|
2023-11-13 17:47:44 -05:00
|
|
|
|
|
|
|
it 'requires non-empty events value' do
|
|
|
|
record = described_class.new(events: [])
|
|
|
|
record.valid?
|
|
|
|
|
|
|
|
expect(record).to model_have_error_on_field(:events)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requires valid events value from EVENTS' do
|
|
|
|
record = described_class.new(events: ['account.invalid'])
|
|
|
|
record.valid?
|
|
|
|
|
|
|
|
expect(record).to model_have_error_on_field(:events)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Normalizations' do
|
2024-09-04 01:12:40 -04:00
|
|
|
describe 'events' do
|
|
|
|
it { is_expected.to normalize(:events).from(['account.approved', 'account.created ', '']).to(%w(account.approved account.created)) }
|
2023-11-13 17:47:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-09 15:57:36 -04:00
|
|
|
describe '#rotate_secret!' do
|
|
|
|
it 'changes the secret' do
|
2024-09-03 11:30:13 -04:00
|
|
|
expect { webhook.rotate_secret! }
|
|
|
|
.to change(webhook, :secret)
|
|
|
|
expect(webhook.secret)
|
|
|
|
.to_not be_blank
|
2022-06-09 15:57:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#enable!' do
|
2024-09-03 11:30:13 -04:00
|
|
|
let(:webhook) { Fabricate(:webhook, enabled: false) }
|
2022-06-09 15:57:36 -04:00
|
|
|
|
|
|
|
it 'enables the webhook' do
|
2024-09-03 11:30:13 -04:00
|
|
|
expect { webhook.enable! }
|
|
|
|
.to change(webhook, :enabled?).to(true)
|
2022-06-09 15:57:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#disable!' do
|
2024-09-03 11:30:13 -04:00
|
|
|
let(:webhook) { Fabricate(:webhook, enabled: true) }
|
|
|
|
|
2022-06-09 15:57:36 -04:00
|
|
|
it 'disables the webhook' do
|
2024-09-03 11:30:13 -04:00
|
|
|
expect { webhook.disable! }
|
|
|
|
.to change(webhook, :enabled?).to(false)
|
2022-06-09 15:57:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|