2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-04-27 09:21:07 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class NotificationFactoryMailerTemplateTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
test 'notifications template' do
|
|
|
|
|
2021-11-15 15:58:19 +00:00
|
|
|
Translation.sync_locale_from_po('de-de')
|
2016-04-27 09:21:07 +00:00
|
|
|
|
|
|
|
groups = Group.where(name: 'Users')
|
|
|
|
roles = Role.where(name: 'Agent')
|
2018-12-31 19:15:17 +00:00
|
|
|
agent1 = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'notification-template-agent1@example.com',
|
|
|
|
firstname: 'Notification<b>xxx</b>',
|
|
|
|
lastname: 'Agent1<b>yyy</b>',
|
|
|
|
email: 'notification-template-agent1@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
|
|
|
preferences: {
|
2016-04-27 09:21:07 +00:00
|
|
|
locale: 'de-de',
|
|
|
|
},
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
2018-12-31 19:15:17 +00:00
|
|
|
agent_current_user = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'notification-template-current_user@example.com',
|
|
|
|
firstname: 'Notification Current',
|
|
|
|
lastname: 'User',
|
|
|
|
email: 'notification-template-current_user@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
|
|
|
preferences: {
|
2016-04-27 09:21:07 +00:00
|
|
|
locale: 'de-de',
|
|
|
|
},
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'password_reset',
|
2018-12-19 17:31:51 +00:00
|
|
|
locale: 'de-de',
|
2016-04-27 09:21:07 +00:00
|
|
|
objects: {
|
|
|
|
user: agent1,
|
|
|
|
},
|
|
|
|
)
|
2018-11-14 15:14:25 +00:00
|
|
|
assert_match('Zurücksetzen Ihres', result[:subject])
|
2016-04-27 09:21:07 +00:00
|
|
|
assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
|
2018-11-14 15:14:25 +00:00
|
|
|
assert_match('Ihr', result[:body])
|
|
|
|
assert_match('Ihr', result[:body])
|
2016-04-27 09:21:07 +00:00
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_no_match('Your', result[:body])
|
|
|
|
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'password_reset',
|
2018-12-19 17:31:51 +00:00
|
|
|
locale: 'de',
|
2016-04-27 09:21:07 +00:00
|
|
|
objects: {
|
|
|
|
user: agent1,
|
|
|
|
},
|
|
|
|
)
|
2018-11-14 15:14:25 +00:00
|
|
|
assert_match('Zurücksetzen Ihres', result[:subject])
|
2016-04-27 09:21:07 +00:00
|
|
|
assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
|
2018-11-14 15:14:25 +00:00
|
|
|
assert_match('Ihr', result[:body])
|
2016-04-27 09:21:07 +00:00
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_no_match('Your', result[:body])
|
|
|
|
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'password_reset',
|
2018-12-19 17:31:51 +00:00
|
|
|
locale: 'xx-us',
|
2016-04-27 09:21:07 +00:00
|
|
|
objects: {
|
|
|
|
user: agent1,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert_match('Reset your', result[:subject])
|
|
|
|
assert_match('We received a request to reset the password', result[:body])
|
|
|
|
assert_match('Your', result[:body])
|
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
2018-11-14 15:14:25 +00:00
|
|
|
assert_no_match('Ihr', result[:body])
|
2016-04-27 09:21:07 +00:00
|
|
|
|
|
|
|
ticket = Ticket.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
group_id: Group.lookup(name: 'Users').id,
|
|
|
|
customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
|
|
|
|
owner_id: User.lookup(login: '-').id,
|
|
|
|
title: 'Welcome to Zammad!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'new').id,
|
|
|
|
priority_id: Ticket::Priority.lookup(name: '2 normal').id,
|
2016-04-27 09:21:07 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
article = Ticket::Article.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket.id,
|
|
|
|
type_id: Ticket::Article::Type.lookup(name: 'phone').id,
|
|
|
|
sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
|
|
|
|
from: 'Zammad Feedback <feedback@zammad.org>',
|
|
|
|
content_type: 'text/plain',
|
|
|
|
body: 'Welcome!
|
2016-04-27 09:21:07 +00:00
|
|
|
<b>test123</b>',
|
2018-12-19 17:31:51 +00:00
|
|
|
internal: false,
|
2016-04-27 09:21:07 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
changes = {}
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'ticket_create',
|
2018-12-19 17:31:51 +00:00
|
|
|
locale: 'xx-us',
|
2016-04-27 09:21:07 +00:00
|
|
|
objects: {
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket: ticket,
|
|
|
|
article: article,
|
|
|
|
recipient: agent1,
|
2016-04-27 09:21:07 +00:00
|
|
|
current_user: agent_current_user,
|
2018-12-19 17:31:51 +00:00
|
|
|
changes: changes,
|
2016-04-27 09:21:07 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
assert_match('New Ticket', result[:subject])
|
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_match('has been created by', result[:body])
|
|
|
|
assert_match('<b>test123</b>', result[:body])
|
2021-12-16 13:42:09 +00:00
|
|
|
assert_match('Manage your notification settings', result[:body])
|
2016-04-27 09:21:07 +00:00
|
|
|
assert_no_match('Dein', result[:body])
|
|
|
|
assert_no_match('longname', result[:body])
|
|
|
|
assert_match('Current User', result[:body])
|
|
|
|
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'ticket_create',
|
2018-12-19 17:31:51 +00:00
|
|
|
locale: 'de-de',
|
2016-04-27 09:21:07 +00:00
|
|
|
objects: {
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket: ticket,
|
|
|
|
article: article,
|
|
|
|
recipient: agent1,
|
2016-04-27 09:21:07 +00:00
|
|
|
current_user: agent_current_user,
|
2018-12-19 17:31:51 +00:00
|
|
|
changes: changes,
|
2016-04-27 09:21:07 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
assert_match('Neues Ticket', result[:subject])
|
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_match('es wurde ein neues Ticket', result[:body])
|
|
|
|
assert_match('<b>test123</b>', result[:body])
|
2021-12-16 13:42:09 +00:00
|
|
|
assert_match(Translation.translate('de-de', 'Manage your notification settings'), result[:body])
|
2016-04-27 09:21:07 +00:00
|
|
|
assert_no_match('Your', result[:body])
|
|
|
|
assert_no_match('longname', result[:body])
|
|
|
|
assert_match('Current User', result[:body])
|
|
|
|
|
|
|
|
article = Ticket::Article.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket.id,
|
|
|
|
type_id: Ticket::Article::Type.lookup(name: 'phone').id,
|
|
|
|
sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
|
|
|
|
from: 'Zammad Feedback <feedback@zammad.org>',
|
|
|
|
content_type: 'text/html',
|
|
|
|
body: 'Welcome!
|
2016-04-27 09:21:07 +00:00
|
|
|
<b>test123</b>',
|
2018-12-19 17:31:51 +00:00
|
|
|
internal: false,
|
2016-04-27 09:21:07 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
changes = {
|
2017-11-23 08:09:44 +00:00
|
|
|
state: %w[aaa bbb],
|
|
|
|
group: %w[xxx yyy],
|
2016-04-27 09:21:07 +00:00
|
|
|
}
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'ticket_update',
|
2018-12-19 17:31:51 +00:00
|
|
|
locale: 'xx-us',
|
2016-04-27 09:21:07 +00:00
|
|
|
objects: {
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket: ticket,
|
|
|
|
article: article,
|
|
|
|
recipient: agent1,
|
2016-04-27 09:21:07 +00:00
|
|
|
current_user: agent_current_user,
|
2018-12-19 17:31:51 +00:00
|
|
|
changes: changes,
|
2016-04-27 09:21:07 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
assert_match('Updated Ticket', result[:subject])
|
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_match('has been updated by', result[:body])
|
|
|
|
assert_match('<b>test123</b>', result[:body])
|
2021-12-16 13:42:09 +00:00
|
|
|
assert_match('Manage your notification settings', result[:body])
|
2016-04-27 09:21:07 +00:00
|
|
|
assert_no_match('Dein', result[:body])
|
|
|
|
assert_no_match('longname', result[:body])
|
|
|
|
assert_match('Current User', result[:body])
|
|
|
|
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'ticket_update',
|
2018-12-19 17:31:51 +00:00
|
|
|
locale: 'de-de',
|
2016-04-27 09:21:07 +00:00
|
|
|
objects: {
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket: ticket,
|
|
|
|
article: article,
|
|
|
|
recipient: agent1,
|
2016-04-27 09:21:07 +00:00
|
|
|
current_user: agent_current_user,
|
2018-12-19 17:31:51 +00:00
|
|
|
changes: changes,
|
2016-04-27 09:21:07 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
assert_match('Ticket aktualisiert', result[:subject])
|
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_match('wurde von', result[:body])
|
|
|
|
assert_match('<b>test123</b>', result[:body])
|
2021-12-16 13:42:09 +00:00
|
|
|
assert_match(Translation.translate('de-de', 'Manage your notification settings'), result[:body])
|
2016-04-27 09:21:07 +00:00
|
|
|
assert_no_match('Your', result[:body])
|
|
|
|
assert_no_match('longname', result[:body])
|
|
|
|
assert_match('Current User', result[:body])
|
|
|
|
|
2017-11-15 14:06:53 +00:00
|
|
|
Setting.set('locale_default', 'de-de')
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'ticket_update',
|
|
|
|
objects: {
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket: ticket,
|
|
|
|
article: article,
|
|
|
|
recipient: agent1,
|
2017-11-15 14:06:53 +00:00
|
|
|
current_user: agent_current_user,
|
2018-12-19 17:31:51 +00:00
|
|
|
changes: changes,
|
2017-11-15 14:06:53 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
assert_match('Ticket aktualisiert', result[:subject])
|
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_match('wurde von', result[:body])
|
|
|
|
assert_match('<b>test123</b>', result[:body])
|
2021-12-16 13:42:09 +00:00
|
|
|
assert_match(Translation.translate('de-de', 'Manage your notification settings'), result[:body])
|
2017-11-15 14:06:53 +00:00
|
|
|
assert_no_match('Your', result[:body])
|
|
|
|
assert_no_match('longname', result[:body])
|
|
|
|
assert_match('Current User', result[:body])
|
|
|
|
|
|
|
|
Setting.set('locale_default', 'not_existing')
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'ticket_update',
|
|
|
|
objects: {
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket: ticket,
|
|
|
|
article: article,
|
|
|
|
recipient: agent1,
|
2017-11-15 14:06:53 +00:00
|
|
|
current_user: agent_current_user,
|
2018-12-19 17:31:51 +00:00
|
|
|
changes: changes,
|
2017-11-15 14:06:53 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
assert_match('Updated Ticket', result[:subject])
|
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_match('has been updated by', result[:body])
|
|
|
|
assert_match('<b>test123</b>', result[:body])
|
2021-12-16 13:42:09 +00:00
|
|
|
assert_match('Manage your notification settings', result[:body])
|
2017-11-15 14:06:53 +00:00
|
|
|
assert_no_match('Dein', result[:body])
|
|
|
|
assert_no_match('longname', result[:body])
|
|
|
|
assert_match('Current User', result[:body])
|
|
|
|
|
|
|
|
Setting.set('locale_default', 'pt-br')
|
|
|
|
result = NotificationFactory::Mailer.template(
|
|
|
|
template: 'ticket_update',
|
|
|
|
objects: {
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket: ticket,
|
|
|
|
article: article,
|
|
|
|
recipient: agent1,
|
2017-11-15 14:06:53 +00:00
|
|
|
current_user: agent_current_user,
|
2018-12-19 17:31:51 +00:00
|
|
|
changes: changes,
|
2017-11-15 14:06:53 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
assert_match('Chamado atualizado', result[:subject])
|
|
|
|
assert_match('Notification<b>xxx</b>', result[:body])
|
|
|
|
assert_match('foi atualizado por', result[:body])
|
|
|
|
assert_match('<b>test123</b>', result[:body])
|
2021-12-16 13:42:09 +00:00
|
|
|
assert_match('Manage your notification settings', result[:body])
|
2017-11-15 14:06:53 +00:00
|
|
|
assert_no_match('Dein', result[:body])
|
|
|
|
assert_no_match('longname', result[:body])
|
|
|
|
assert_match('Current User', result[:body])
|
|
|
|
|
2016-04-27 09:21:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|