1
0

webhook_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 'requires presence of events' do
  7. record = described_class.new(events: nil)
  8. record.valid?
  9. expect(record).to model_have_error_on_field(:events)
  10. end
  11. it 'requires non-empty events value' do
  12. record = described_class.new(events: [])
  13. record.valid?
  14. expect(record).to model_have_error_on_field(:events)
  15. end
  16. it 'requires valid events value from EVENTS' do
  17. record = described_class.new(events: ['account.invalid'])
  18. record.valid?
  19. expect(record).to model_have_error_on_field(:events)
  20. end
  21. end
  22. describe 'Normalizations' do
  23. it 'cleans up events values' do
  24. record = described_class.new(events: ['account.approved', 'account.created ', ''])
  25. expect(record.events).to eq(%w(account.approved account.created))
  26. end
  27. end
  28. describe '#rotate_secret!' do
  29. it 'changes the secret' do
  30. previous_value = webhook.secret
  31. webhook.rotate_secret!
  32. expect(webhook.secret).to_not be_blank
  33. expect(webhook.secret).to_not eq previous_value
  34. end
  35. end
  36. describe '#enable!' do
  37. before do
  38. webhook.disable!
  39. end
  40. it 'enables the webhook' do
  41. webhook.enable!
  42. expect(webhook.enabled?).to be true
  43. end
  44. end
  45. describe '#disable!' do
  46. it 'disables the webhook' do
  47. webhook.disable!
  48. expect(webhook.enabled?).to be false
  49. end
  50. end
  51. end