1
0

webhook_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Webhook do
  4. let(:webhook) { Fabricate(:webhook) }
  5. describe 'Validations' do
  6. it { is_expected.to validate_presence_of(:events) }
  7. it 'requires non-empty events value' do
  8. record = described_class.new(events: [])
  9. record.valid?
  10. expect(record).to model_have_error_on_field(:events)
  11. end
  12. it 'requires valid events value from EVENTS' do
  13. record = described_class.new(events: ['account.invalid'])
  14. record.valid?
  15. expect(record).to model_have_error_on_field(:events)
  16. end
  17. end
  18. describe 'Normalizations' do
  19. describe 'events' do
  20. it { is_expected.to normalize(:events).from(['account.approved', 'account.created ', '']).to(%w(account.approved account.created)) }
  21. end
  22. end
  23. describe '#rotate_secret!' do
  24. it 'changes the secret' do
  25. expect { webhook.rotate_secret! }
  26. .to change(webhook, :secret)
  27. expect(webhook.secret)
  28. .to_not be_blank
  29. end
  30. end
  31. describe '#enable!' do
  32. let(:webhook) { Fabricate(:webhook, enabled: false) }
  33. it 'enables the webhook' do
  34. expect { webhook.enable! }
  35. .to change(webhook, :enabled?).to(true)
  36. end
  37. end
  38. describe '#disable!' do
  39. let(:webhook) { Fabricate(:webhook, enabled: true) }
  40. it 'disables the webhook' do
  41. expect { webhook.disable! }
  42. .to change(webhook, :enabled?).to(false)
  43. end
  44. end
  45. end