pre_defined_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe(Webhook::PreDefined) do
  4. it 'checks that pre defined webhook list can be used' do
  5. expect(described_class.pre_defined_webhooks.sort_by(&:name)).to include(
  6. Webhook::PreDefined::Mattermost,
  7. Webhook::PreDefined::MicrosoftTeams,
  8. Webhook::PreDefined::RocketChat,
  9. Webhook::PreDefined::Slack
  10. )
  11. end
  12. context 'when definition is used' do
  13. let(:slack_custom_payload) do
  14. # rubocop:disable Lint/InterpolationCheck
  15. JSON.pretty_generate({
  16. mrkdwn: true,
  17. text: '# #{ticket.title}',
  18. attachments: [
  19. {
  20. text: "_[Ticket#\#{ticket.number}](\#{notification.link}): \#{notification.message}_\n\n\#{notification.changes}\n\n\#{notification.body}",
  21. mrkdwn_in: [
  22. 'text'
  23. ],
  24. color: '#{ticket.current_state_color}'
  25. }
  26. ]
  27. })
  28. # rubocop:enable Lint/InterpolationCheck
  29. end
  30. it 'checks that pre defined webhook definitions are returned' do
  31. expect(described_class.pre_defined_webhook_definitions.find { |item| item[:id] == 'Slack' }).to include(
  32. id: 'Slack',
  33. name: 'Slack Notifications',
  34. custom_payload: include(slack_custom_payload),
  35. fields: [],
  36. )
  37. end
  38. end
  39. end