notification_factory_slack_template_test.rb 3.6 KB

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