notification_factory_slack_template_test.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. require 'test_helper'
  2. class NotificationFactorySlackTemplateTest < ActiveSupport::TestCase
  3. test 'notifications template' do
  4. Translation.load('de-de')
  5. groups = Group.where(name: 'Users')
  6. roles = Role.where(name: 'Agent')
  7. agent1 = User.create_or_update(
  8. login: 'notification-template-agent1@example.com',
  9. firstname: 'Notification<b>xxx</b>',
  10. lastname: 'Agent1<b>yyy</b>',
  11. email: 'notification-template-agent1@example.com',
  12. password: 'agentpw',
  13. active: true,
  14. roles: roles,
  15. groups: groups,
  16. preferences: {
  17. locale: 'de-de',
  18. },
  19. updated_by_id: 1,
  20. created_by_id: 1,
  21. )
  22. agent_current_user = User.create_or_update(
  23. login: 'notification-template-current_user@example.com',
  24. firstname: 'Notification Current',
  25. lastname: 'User<b>xxx</b>',
  26. email: 'notification-template-current_user@example.com',
  27. password: 'agentpw',
  28. active: true,
  29. roles: roles,
  30. groups: groups,
  31. preferences: {
  32. locale: 'de-de',
  33. },
  34. updated_by_id: 1,
  35. created_by_id: 1,
  36. )
  37. ticket = Ticket.create(
  38. group_id: Group.lookup(name: 'Users').id,
  39. customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
  40. owner_id: User.lookup(login: '-').id,
  41. title: 'Welcome to Zammad!',
  42. state_id: Ticket::State.lookup(name: 'new').id,
  43. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  44. updated_by_id: 1,
  45. created_by_id: 1,
  46. )
  47. article = Ticket::Article.create(
  48. ticket_id: ticket.id,
  49. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  50. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  51. from: 'Zammad Feedback <feedback@zammad.org>',
  52. content_type: 'text/plain',
  53. body: 'Welcome!
  54. <b>test123</b>',
  55. internal: false,
  56. updated_by_id: 1,
  57. created_by_id: 1,
  58. )
  59. changes = {}
  60. result = NotificationFactory::Slack.template(
  61. template: 'ticket_create',
  62. locale: 'es-us',
  63. objects: {
  64. ticket: ticket,
  65. article: article,
  66. recipient: agent1,
  67. current_user: agent_current_user,
  68. changes: changes,
  69. },
  70. )
  71. assert_match('# Welcome to Zammad!', result[:subject])
  72. assert_match('User<b>xxx</b>', result[:body])
  73. assert_match('Created by', result[:body])
  74. assert_match('<b>test123</b>', result[:body])
  75. assert_no_match('Dein', result[:body])
  76. assert_no_match('longname', result[:body])
  77. assert_match('Current User', result[:body])
  78. article = Ticket::Article.create(
  79. ticket_id: ticket.id,
  80. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  81. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  82. from: 'Zammad Feedback <feedback@zammad.org>',
  83. content_type: 'text/html',
  84. body: 'Welcome!
  85. <b>test123</b>',
  86. internal: false,
  87. updated_by_id: 1,
  88. created_by_id: 1,
  89. )
  90. changes = {
  91. state: %w[aaa bbb],
  92. group: %w[xxx yyy],
  93. }
  94. result = NotificationFactory::Slack.template(
  95. template: 'ticket_update',
  96. locale: 'es-us',
  97. objects: {
  98. ticket: ticket,
  99. article: article,
  100. recipient: agent1,
  101. current_user: agent_current_user,
  102. changes: changes,
  103. },
  104. )
  105. assert_match('# Welcome to Zammad!', result[:subject])
  106. assert_match('User<b>xxx</b>', result[:body])
  107. assert_match('state: aaa -> bbb', result[:body])
  108. assert_match('group: xxx -> yyy', result[:body])
  109. assert_no_match('Dein', result[:body])
  110. assert_no_match('longname', result[:body])
  111. assert_match('Current User', result[:body])
  112. end
  113. end