notification_factory_mailer_template_test.rb 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. require 'test_helper'
  2. class NotificationFactoryMailerTemplateTest < 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!(
  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!(
  23. login: 'notification-template-current_user@example.com',
  24. firstname: 'Notification Current',
  25. lastname: 'User',
  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. result = NotificationFactory::Mailer.template(
  38. template: 'password_reset',
  39. locale: 'de-de',
  40. objects: {
  41. user: agent1,
  42. },
  43. )
  44. assert_match('Zurücksetzen Ihres', result[:subject])
  45. assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
  46. assert_match('Ihr', result[:body])
  47. assert_match('Ihr', result[:body])
  48. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  49. assert_no_match('Your', result[:body])
  50. result = NotificationFactory::Mailer.template(
  51. template: 'password_reset',
  52. locale: 'de',
  53. objects: {
  54. user: agent1,
  55. },
  56. )
  57. assert_match('Zurücksetzen Ihres', result[:subject])
  58. assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
  59. assert_match('Ihr', result[:body])
  60. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  61. assert_no_match('Your', result[:body])
  62. result = NotificationFactory::Mailer.template(
  63. template: 'password_reset',
  64. locale: 'xx-us',
  65. objects: {
  66. user: agent1,
  67. },
  68. )
  69. assert_match('Reset your', result[:subject])
  70. assert_match('We received a request to reset the password', result[:body])
  71. assert_match('Your', result[:body])
  72. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  73. assert_no_match('Ihr', result[:body])
  74. ticket = Ticket.create(
  75. group_id: Group.lookup(name: 'Users').id,
  76. customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
  77. owner_id: User.lookup(login: '-').id,
  78. title: 'Welcome to Zammad!',
  79. state_id: Ticket::State.lookup(name: 'new').id,
  80. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  81. updated_by_id: 1,
  82. created_by_id: 1,
  83. )
  84. article = Ticket::Article.create(
  85. ticket_id: ticket.id,
  86. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  87. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  88. from: 'Zammad Feedback <feedback@zammad.org>',
  89. content_type: 'text/plain',
  90. body: 'Welcome!
  91. <b>test123</b>',
  92. internal: false,
  93. updated_by_id: 1,
  94. created_by_id: 1,
  95. )
  96. changes = {}
  97. result = NotificationFactory::Mailer.template(
  98. template: 'ticket_create',
  99. locale: 'xx-us',
  100. objects: {
  101. ticket: ticket,
  102. article: article,
  103. recipient: agent1,
  104. current_user: agent_current_user,
  105. changes: changes,
  106. },
  107. )
  108. assert_match('New Ticket', result[:subject])
  109. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  110. assert_match('has been created by', result[:body])
  111. assert_match('&lt;b&gt;test123&lt;/b&gt;', result[:body])
  112. assert_match('Manage your notifications settings', result[:body])
  113. assert_no_match('Dein', result[:body])
  114. assert_no_match('longname', result[:body])
  115. assert_match('Current User', result[:body])
  116. result = NotificationFactory::Mailer.template(
  117. template: 'ticket_create',
  118. locale: 'de-de',
  119. objects: {
  120. ticket: ticket,
  121. article: article,
  122. recipient: agent1,
  123. current_user: agent_current_user,
  124. changes: changes,
  125. },
  126. )
  127. assert_match('Neues Ticket', result[:subject])
  128. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  129. assert_match('es wurde ein neues Ticket', result[:body])
  130. assert_match('&lt;b&gt;test123&lt;/b&gt;', result[:body])
  131. assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
  132. assert_no_match('Your', result[:body])
  133. assert_no_match('longname', result[:body])
  134. assert_match('Current User', result[:body])
  135. article = Ticket::Article.create(
  136. ticket_id: ticket.id,
  137. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  138. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  139. from: 'Zammad Feedback <feedback@zammad.org>',
  140. content_type: 'text/html',
  141. body: 'Welcome!
  142. <b>test123</b>',
  143. internal: false,
  144. updated_by_id: 1,
  145. created_by_id: 1,
  146. )
  147. changes = {
  148. state: %w[aaa bbb],
  149. group: %w[xxx yyy],
  150. }
  151. result = NotificationFactory::Mailer.template(
  152. template: 'ticket_update',
  153. locale: 'xx-us',
  154. objects: {
  155. ticket: ticket,
  156. article: article,
  157. recipient: agent1,
  158. current_user: agent_current_user,
  159. changes: changes,
  160. },
  161. )
  162. assert_match('Updated Ticket', result[:subject])
  163. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  164. assert_match('has been updated by', result[:body])
  165. assert_match('<b>test123</b>', result[:body])
  166. assert_match('Manage your notifications settings', result[:body])
  167. assert_no_match('Dein', result[:body])
  168. assert_no_match('longname', result[:body])
  169. assert_match('Current User', result[:body])
  170. result = NotificationFactory::Mailer.template(
  171. template: 'ticket_update',
  172. locale: 'de-de',
  173. objects: {
  174. ticket: ticket,
  175. article: article,
  176. recipient: agent1,
  177. current_user: agent_current_user,
  178. changes: changes,
  179. },
  180. )
  181. assert_match('Ticket aktualisiert', result[:subject])
  182. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  183. assert_match('wurde von', result[:body])
  184. assert_match('<b>test123</b>', result[:body])
  185. assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
  186. assert_no_match('Your', result[:body])
  187. assert_no_match('longname', result[:body])
  188. assert_match('Current User', result[:body])
  189. Setting.set('locale_default', 'de-de')
  190. result = NotificationFactory::Mailer.template(
  191. template: 'ticket_update',
  192. objects: {
  193. ticket: ticket,
  194. article: article,
  195. recipient: agent1,
  196. current_user: agent_current_user,
  197. changes: changes,
  198. },
  199. )
  200. assert_match('Ticket aktualisiert', result[:subject])
  201. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  202. assert_match('wurde von', result[:body])
  203. assert_match('<b>test123</b>', result[:body])
  204. assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
  205. assert_no_match('Your', result[:body])
  206. assert_no_match('longname', result[:body])
  207. assert_match('Current User', result[:body])
  208. Setting.set('locale_default', 'not_existing')
  209. result = NotificationFactory::Mailer.template(
  210. template: 'ticket_update',
  211. objects: {
  212. ticket: ticket,
  213. article: article,
  214. recipient: agent1,
  215. current_user: agent_current_user,
  216. changes: changes,
  217. },
  218. )
  219. assert_match('Updated Ticket', result[:subject])
  220. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  221. assert_match('has been updated by', result[:body])
  222. assert_match('<b>test123</b>', result[:body])
  223. assert_match('Manage your notifications settings', result[:body])
  224. assert_no_match('Dein', result[:body])
  225. assert_no_match('longname', result[:body])
  226. assert_match('Current User', result[:body])
  227. Setting.set('locale_default', 'pt-br')
  228. result = NotificationFactory::Mailer.template(
  229. template: 'ticket_update',
  230. objects: {
  231. ticket: ticket,
  232. article: article,
  233. recipient: agent1,
  234. current_user: agent_current_user,
  235. changes: changes,
  236. },
  237. )
  238. assert_match('Chamado atualizado', result[:subject])
  239. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  240. assert_match('foi atualizado por', result[:body])
  241. assert_match('<b>test123</b>', result[:body])
  242. assert_match('Manage your notifications settings', result[:body])
  243. assert_no_match('Dein', result[:body])
  244. assert_no_match('longname', result[:body])
  245. assert_match('Current User', result[:body])
  246. end
  247. end