2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-09 21:57:36 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 05:49:53 +02:00
|
|
|
RSpec.describe Webhook do
|
2022-06-09 21:57:36 +02:00
|
|
|
let(:webhook) { Fabricate(:webhook) }
|
|
|
|
|
2023-11-13 23:47:44 +01:00
|
|
|
describe 'Validations' do
|
|
|
|
it 'requires presence of events' do
|
|
|
|
record = described_class.new(events: nil)
|
|
|
|
record.valid?
|
|
|
|
|
|
|
|
expect(record).to model_have_error_on_field(:events)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
it 'cleans up events values' do
|
|
|
|
record = described_class.new(events: ['account.approved', 'account.created ', ''])
|
|
|
|
|
|
|
|
expect(record.events).to eq(%w(account.approved account.created))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-09 21:57:36 +02:00
|
|
|
describe '#rotate_secret!' do
|
|
|
|
it 'changes the secret' do
|
2024-09-03 17:30:13 +02:00
|
|
|
expect { webhook.rotate_secret! }
|
|
|
|
.to change(webhook, :secret)
|
|
|
|
expect(webhook.secret)
|
|
|
|
.to_not be_blank
|
2022-06-09 21:57:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#enable!' do
|
2024-09-03 17:30:13 +02:00
|
|
|
let(:webhook) { Fabricate(:webhook, enabled: false) }
|
2022-06-09 21:57:36 +02:00
|
|
|
|
|
|
|
it 'enables the webhook' do
|
2024-09-03 17:30:13 +02:00
|
|
|
expect { webhook.enable! }
|
|
|
|
.to change(webhook, :enabled?).to(true)
|
2022-06-09 21:57:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#disable!' do
|
2024-09-03 17:30:13 +02:00
|
|
|
let(:webhook) { Fabricate(:webhook, enabled: true) }
|
|
|
|
|
2022-06-09 21:57:36 +02:00
|
|
|
it 'disables the webhook' do
|
2024-09-03 17:30:13 +02:00
|
|
|
expect { webhook.disable! }
|
|
|
|
.to change(webhook, :enabled?).to(false)
|
2022-06-09 21:57:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|