issue_3372_webhooks_admin_view_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue3372WebhooksAdminView, type: :db_migration do
  4. let(:trigger_webhook_config) do
  5. {
  6. 'endpoint' => 'https://example.com/webhook',
  7. 'token' => '53Cr3T',
  8. 'verify_ssl' => false,
  9. }
  10. end
  11. let(:webhook_attributes) do
  12. {
  13. endpoint: trigger_webhook_config['endpoint'],
  14. signature_token: trigger_webhook_config['token'],
  15. ssl_verify: trigger_webhook_config['verify_ssl'],
  16. }
  17. end
  18. let!(:trigger) do
  19. validator = Trigger.validators_on(:perform).find(Validations::VerifyPerformRulesValidator).first
  20. allow(validator).to receive(:validate_each)
  21. trigger = create(:trigger, perform: {
  22. 'notification.webhook' => trigger_webhook_config
  23. })
  24. allow(validator).to receive(:validate_each).and_call_original
  25. trigger
  26. end
  27. it 'Creates Webhook object from mapped Trigger configuration' do
  28. migrate do |migration|
  29. allow(migration).to receive(:create_webhooks_table)
  30. end
  31. expect(Webhook.last).to have_attributes(**webhook_attributes)
  32. end
  33. it 'Migrates Trigger#perform Webhook configuration to new structure' do
  34. migrate do |migration|
  35. allow(migration).to receive(:create_webhooks_table)
  36. end
  37. expect(trigger.reload.perform['notification.webhook']['webhook_id']).to eq(Webhook.last.id)
  38. end
  39. end