2021-06-01 12:20:20 +00:00
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
2016-05-03 00:36:44 +00:00
require 'test_helper'
class TicketTriggerTest < ActiveSupport :: TestCase
2018-05-29 15:42:14 +00:00
2021-07-09 13:05:05 +00:00
setup do
2018-05-29 15:42:14 +00:00
Setting . set ( 'ticket_trigger_recursive' , true )
end
2016-05-03 00:36:44 +00:00
test '1 basic' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa loop check' ,
condition : {
2016-11-18 07:25:07 +00:00
'article.subject' = > {
'operator' = > 'contains' ,
2018-12-19 17:31:51 +00:00
'value' = > 'Thanks for your inquiry' ,
2016-11-18 07:25:07 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
'ticket.tags' = > {
2016-11-18 07:25:07 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'should_not_loop' ,
2016-11-18 07:25:07 +00:00
} ,
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2016-11-18 07:25:07 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry - loop check - only once (#{ticket.title})!' ,
2016-11-18 07:25:07 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-11-18 07:25:07 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2016-11-18 07:25:07 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2016-11-18 07:25:07 +00:00
} ,
2016-05-03 00:36:44 +00:00
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2016-05-03 00:36:44 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-05-03 00:36:44 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2016-05-03 00:36:44 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2016-05-03 00:36:44 +00:00
} ,
'ticket.priority_id' = > {
'value' = > Ticket :: Priority . lookup ( name : '3 high' ) . id . to_s ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.tags' = > {
2016-05-03 00:36:44 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'aa, kk' ,
2016-05-03 00:36:44 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-05-03 00:36:44 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto tag 1' ,
condition : {
'ticket.action' = > {
2016-11-18 07:25:07 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2016-11-18 07:25:07 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2016-11-18 07:25:07 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-11-18 07:25:07 +00:00
'ticket.priority_id' = > {
'value' = > Ticket :: Priority . lookup ( name : '3 high' ) . id . to_s ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.tags' = > {
2016-11-18 07:25:07 +00:00
'operator' = > 'remove' ,
2018-12-19 17:31:51 +00:00
'value' = > 'kk' ,
2016-11-18 07:25:07 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-11-18 07:25:07 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto tag 2' ,
condition : {
2016-11-18 07:25:07 +00:00
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2016-11-18 07:25:07 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-11-18 07:25:07 +00:00
'ticket.tags' = > {
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'abc' ,
2016-11-18 07:25:07 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-11-18 07:25:07 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'not matching' ,
condition : {
2016-05-03 00:36:44 +00:00
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'closed' ) . id . to_s ,
2016-05-03 00:36:44 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-05-03 00:36:44 +00:00
'ticket.priority_id' = > {
'value' = > Ticket :: Priority . lookup ( name : '3 high' ) . id . to_s ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-05-03 00:36:44 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'zzz last' ,
condition : {
2016-11-18 07:25:07 +00:00
'article.subject' = > {
'operator' = > 'contains' ,
2018-12-19 17:31:51 +00:00
'value' = > 'some subject 1234' ,
2016-11-18 07:25:07 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
'ticket.tags' = > {
2016-11-18 07:25:07 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'article_create_trigger' ,
2016-11-18 07:25:07 +00:00
} ,
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2016-11-18 07:25:07 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry - 1234 check (#{ticket.title})!' ,
2016-11-18 07:25:07 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-11-18 07:25:07 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2016-05-03 00:36:44 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2016-11-13 18:33:12 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
2016-11-13 18:33:12 +00:00
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
2018-05-29 15:42:14 +00:00
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( %w[ aa kk should_not_loop abc ] , ticket1 . tag_list )
article1 = ticket1 . articles . second
2016-08-24 18:29:56 +00:00
assert_match ( 'Zammad <zammad@localhost>' , article1 . from )
assert_match ( 'nicole.braun@zammad.org' , article1 . to )
2016-05-03 06:19:44 +00:00
assert_match ( 'Thanks for your inquiry (some <b>title</b> äöüß)!' , article1 . subject )
2016-05-03 00:36:44 +00:00
assert_match ( 'Braun<br>some <b>title</b>' , article1 . body )
2016-11-13 18:33:12 +00:00
assert_match ( '> some message <b>note</b><br>> new line' , article1 . body )
2016-05-03 00:36:44 +00:00
assert_equal ( 'text/html' , article1 . content_type )
2018-05-29 15:42:14 +00:00
article1 = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , article1 . from )
assert_match ( 'nicole.braun@zammad.org' , article1 . to )
assert_match ( 'Thanks for your inquiry - loop check - only once (some <b>title</b> äöüß)!' , article1 . subject )
assert_match ( 'some lala' , article1 . body )
assert_equal ( 'text/html' , article1 . content_type )
2016-05-03 00:36:44 +00:00
ticket1 . priority = Ticket :: Priority . lookup ( name : '2 normal' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
2018-05-29 15:42:14 +00:00
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( %w[ aa kk should_not_loop abc ] , ticket1 . tag_list )
2016-05-03 00:36:44 +00:00
ticket1 . state = Ticket :: State . lookup ( name : 'open' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'open' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
2018-05-29 15:42:14 +00:00
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( %w[ aa kk should_not_loop abc ] , ticket1 . tag_list )
2016-05-03 00:36:44 +00:00
ticket1 . state = Ticket :: State . lookup ( name : 'new' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
2018-05-29 15:42:14 +00:00
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( %w[ aa should_not_loop abc ] , ticket1 . tag_list )
2016-05-03 00:36:44 +00:00
2018-01-12 13:59:25 +00:00
ticket2 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some title \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
state : Ticket :: State . lookup ( name : 'open' ) ,
priority : Ticket :: Priority . lookup ( name : '2 normal' ) ,
2016-05-03 00:36:44 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'some title äöüß' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( 'open' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 0 , ticket2 . articles . count , 'ticket2.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket2 . tag_list )
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket2 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( 'open' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 0 , ticket2 . articles . count , 'ticket2.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket2 . tag_list )
2016-05-03 00:36:44 +00:00
2018-01-12 13:59:25 +00:00
ticket3 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß3 " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2016-11-13 18:33:12 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert ( ticket3 , 'ticket3 created' )
2016-11-18 07:25:07 +00:00
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket3 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2016-11-13 18:33:12 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'some <b>title</b> äöüß3' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( '2 normal' , ticket3 . priority . name , 'ticket3.priority verify' )
assert_equal ( 1 , ticket3 . articles . count , 'ticket3.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket3 . tag_list )
2016-11-13 18:33:12 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-11-13 18:33:12 +00:00
2017-03-03 08:28:45 +00:00
ticket3 . reload
2016-11-13 18:33:12 +00:00
assert_equal ( 'some <b>title</b> äöüß3' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( '3 high' , ticket3 . priority . name , 'ticket3.priority verify' )
2018-05-29 15:42:14 +00:00
assert_equal ( 4 , ticket3 . articles . count , 'ticket3.articles verify' )
assert_equal ( %w[ aa kk should_not_loop abc article_create_trigger ] , ticket3 . tag_list )
2016-11-18 07:25:07 +00:00
article3 = ticket3 . articles [ 1 ]
2016-11-13 18:33:12 +00:00
assert_match ( 'Zammad <zammad@localhost>' , article3 . from )
assert_match ( 'nicole.braun@zammad.org' , article3 . to )
assert_match ( 'Thanks for your inquiry (some <b>title</b> äöüß3)!' , article3 . subject )
assert_match ( 'Braun<br>some <b>title</b>' , article3 . body )
assert_match ( '> some message note<br>> new line' , article3 . body )
assert_no_match ( '> some message <b>note</b><br>> new line' , article3 . body )
assert_equal ( 'text/html' , article3 . content_type )
2016-11-18 07:25:07 +00:00
article3 = ticket3 . articles [ 2 ]
assert_match ( 'Zammad <zammad@localhost>' , article3 . from )
assert_match ( 'nicole.braun@zammad.org' , article3 . to )
2018-05-29 15:42:14 +00:00
assert_match ( 'Thanks for your inquiry - loop check - only once (some <b>title</b>' , article3 . subject )
assert_match ( 'some lala' , article3 . body )
2016-11-18 07:25:07 +00:00
assert_equal ( 'text/html' , article3 . content_type )
2018-05-29 15:42:14 +00:00
article4 = ticket3 . articles [ 3 ]
assert_match ( 'Zammad <zammad@localhost>' , article4 . from )
assert_match ( 'nicole.braun@zammad.org' , article4 . to )
assert_match ( 'Thanks for your inquiry - 1234 check (some <b>title</b> äöüß3)!' , article4 . subject )
assert_equal ( 'text/html' , article4 . content_type )
2016-11-18 07:25:07 +00:00
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket3 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject - not 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2016-11-18 07:25:07 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-11-18 07:25:07 +00:00
2017-03-03 08:28:45 +00:00
ticket3 . reload
2016-11-18 07:25:07 +00:00
assert_equal ( 'some <b>title</b> äöüß3' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( '3 high' , ticket3 . priority . name , 'ticket3.priority verify' )
2018-05-29 15:42:14 +00:00
assert_equal ( 5 , ticket3 . articles . count , 'ticket3.articles verify' )
assert_equal ( %w[ aa should_not_loop abc article_create_trigger ] , ticket3 . tag_list )
2016-11-18 07:25:07 +00:00
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket3 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject NOT 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2016-11-18 07:25:07 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-11-18 07:25:07 +00:00
2017-03-03 08:28:45 +00:00
ticket3 . reload
2016-11-18 07:25:07 +00:00
assert_equal ( 'some <b>title</b> äöüß3' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( '3 high' , ticket3 . priority . name , 'ticket3.priority verify' )
2018-05-29 15:42:14 +00:00
assert_equal ( 6 , ticket3 . articles . count , 'ticket3.articles verify' )
assert_equal ( %w[ aa should_not_loop abc article_create_trigger ] , ticket3 . tag_list )
2017-03-03 08:28:45 +00:00
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket3 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-11-13 18:33:12 +00:00
2017-03-03 08:28:45 +00:00
ticket3 . reload
assert_equal ( 'some <b>title</b> äöüß3' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( '3 high' , ticket3 . priority . name , 'ticket3.priority verify' )
2018-05-29 15:42:14 +00:00
assert_equal ( 9 , ticket3 . articles . count , 'ticket3.articles verify' )
assert_equal ( %w[ aa should_not_loop abc article_create_trigger ] , ticket3 . tag_list )
2016-05-03 00:36:44 +00:00
end
test '2 actions - create' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2016-05-03 00:36:44 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2016-05-03 00:36:44 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2016-05-03 00:36:44 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-05-03 00:36:44 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'dasdasdasd' ,
2016-05-03 00:36:44 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'asdasdas' ,
2016-05-03 00:36:44 +00:00
} ,
'ticket.priority_id' = > {
'value' = > Ticket :: Priority . lookup ( name : '3 high' ) . id . to_s ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-05-03 00:36:44 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some title \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2016-05-03 00:36:44 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 0 , ticket1 . articles . count , 'ticket1.articles verify' )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2016-08-24 18:29:56 +00:00
article1 = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , article1 . from )
assert_match ( 'nicole.braun@zammad.org' , article1 . to )
assert_match ( 'asdasdas' , article1 . subject )
assert_match ( 'dasdasdasd' , article1 . body )
assert_equal ( 'text/html' , article1 . content_type )
2016-05-03 00:36:44 +00:00
ticket1 . priority = Ticket :: Priority . lookup ( name : '2 normal' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
ticket1 . state = Ticket :: State . lookup ( name : 'open' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'open' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
ticket1 . state = Ticket :: State . lookup ( name : 'new' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
end
test '2 actions - update' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2016-05-03 00:36:44 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2016-05-03 00:36:44 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2016-05-03 00:36:44 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-05-03 00:36:44 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'dasdasdasd' ,
2016-05-03 00:36:44 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'asdasdas' ,
2016-05-03 00:36:44 +00:00
} ,
'ticket.priority_id' = > {
'value' = > Ticket :: Priority . lookup ( name : '3 high' ) . id . to_s ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-05-03 00:36:44 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some title \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2016-05-03 00:36:44 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 0 , ticket1 . articles . count , 'ticket1.articles verify' )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 0 , ticket1 . articles . count , 'ticket1.articles verify' )
ticket1 . priority = Ticket :: Priority . lookup ( name : '2 normal' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 0 , ticket1 . articles . count , 'ticket1.articles verify' )
ticket1 . state = Ticket :: State . lookup ( name : 'open' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'open' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 0 , ticket1 . articles . count , 'ticket1.articles verify' )
ticket1 . state = Ticket :: State . lookup ( name : 'new' )
2017-03-03 08:28:45 +00:00
ticket1 . save!
2016-05-03 00:36:44 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 00:36:44 +00:00
2017-03-03 08:28:45 +00:00
ticket1 . reload
2016-05-03 00:36:44 +00:00
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
end
2016-05-03 11:03:10 +00:00
test '3 auto replys' do
roles = Role . where ( name : 'Customer' )
2019-06-28 11:38:49 +00:00
User . create! (
2018-12-19 17:31:51 +00:00
login : 'postmaster@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'postmaster@example.com' ,
password : 'customerpw' ,
active : true ,
roles : roles ,
updated_at : '2015-02-05 16:37:00' ,
2016-05-03 11:03:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2019-06-28 11:38:49 +00:00
User . create! (
2018-12-19 17:31:51 +00:00
login : 'ticket-auto-reply-customer2@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer2' ,
email : 'ticket-auto-reply-customer2@example.com' ,
password : 'customerpw' ,
active : true ,
2016-05-03 11:03:10 +00:00
organization_id : nil ,
2018-12-19 17:31:51 +00:00
roles : roles ,
updated_at : '2015-02-05 16:37:00' ,
updated_by_id : 1 ,
created_by_id : 1 ,
2016-05-03 11:03:10 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply - new ticket' ,
condition : {
'ticket.action' = > {
2016-05-03 11:03:10 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2016-05-03 11:03:10 +00:00
} ,
2016-05-03 13:51:07 +00:00
'ticket.state_id' = > {
'operator' = > 'is not' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'closed' ) . id ,
2016-05-03 13:51:07 +00:00
} ,
'article.type_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > [
2016-05-03 13:51:07 +00:00
Ticket :: Article :: Type . lookup ( name : 'email' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'phone' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'web' ) . id ,
] ,
} ,
2016-05-03 11:03:10 +00:00
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-05-03 11:03:10 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > ' < p > Your request ( Ticket ##{ticket.number}) has been received and will be reviewed by our support staff.<p>
2016-05-03 13:51:07 +00:00
< br / >
< p > To provide additional information , please reply to this email or click on the following link :
< a href = " #{ config . http_type } :// #{ config . fqdn } / # ticket/zoom/ #{ ticket . id } " > #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
< / p>
< br / >
< p > < i > < a href = " http://zammad.com " > Zammad < / a>, your customer support system< /i > < / p>',
2016-05-03 11:03:10 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})' ,
2016-05-03 11:03:10 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-05-03 11:03:10 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2019-08-16 15:39:31 +00:00
name : 'auto reply (on follow-up of tickets)' ,
2018-12-19 17:31:51 +00:00
condition : {
'ticket.action' = > {
2016-05-03 13:51:07 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2016-05-03 13:51:07 +00:00
} ,
'article.sender_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Article :: Sender . lookup ( name : 'Customer' ) . id ,
2016-05-03 13:51:07 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.type_id' = > {
2016-05-03 13:51:07 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > [
2016-05-03 13:51:07 +00:00
Ticket :: Article :: Type . lookup ( name : 'email' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'phone' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'web' ) . id ,
] ,
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-05-03 13:51:07 +00:00
'notification.email' = > {
2019-08-16 15:39:31 +00:00
'body' = > ' < p > Your follow - up for ( #{config.ticket_hook}##{ticket.number}) has been received and will be reviewed by our support staff.<p>
2016-05-03 13:51:07 +00:00
< br / >
< p > To provide additional information , please reply to this email or click on the following link :
< a href = " #{ config . http_type } :// #{ config . fqdn } / # ticket/zoom/ #{ ticket . id } " > #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
< / p>
< br / >
< p > < i > < a href = " http://zammad.com " > Zammad < / a>, your customer support system< /i > < / p>',
'recipient' = > 'ticket_customer' ,
2019-08-16 15:39:31 +00:00
'subject' = > 'Thanks for your follow-up (#{ticket.title})' ,
2016-05-03 13:51:07 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
active : true ,
2016-05-03 13:51:07 +00:00
created_by_id : 1 ,
updated_by_id : 1 ,
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'not matching' ,
condition : {
'ticket.action' = > {
2016-05-03 11:03:10 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2016-05-03 11:03:10 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'closed' ) . id . to_s ,
2016-05-03 11:03:10 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-05-03 11:03:10 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > '2some text<br>#{ticket.customer.lastname}<br>#{ticket.title}' ,
2016-05-03 11:03:10 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > '2Thanks for your inquiry (#{ticket.title})!' ,
2016-05-03 11:03:10 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-05-03 11:03:10 +00:00
)
2016-05-03 13:51:07 +00:00
# process mail without Precedence header
2020-02-18 19:51:31 +00:00
content = File . read ( Rails . root . join ( 'test/data/ticket_trigger/mail1.box' ) )
2019-06-28 11:38:49 +00:00
ticket_p , _article_p , _user_p , _mail = Channel :: EmailParser . new . process ( { } , content )
2016-05-03 13:51:07 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title )
assert_equal ( 'Users' , ticket_p . group . name )
assert_equal ( 'new' , ticket_p . state . name )
assert_equal ( 2 , ticket_p . articles . count )
article_p = ticket_p . articles . last
assert_match ( 'Thanks for your inquiry (aaäöüßad asd)' , article_p . subject )
assert_match ( 'Zammad <zammad@localhost>' , article_p . from )
assert_no_match ( 'config\.' , article_p . body )
assert_match ( 'http://zammad.example.com' , article_p . body )
assert_no_match ( 'ticket.' , article_p . body )
assert_match ( ticket_p . number , article_p . body )
assert_equal ( 'text/html' , article_p . content_type )
ticket_p . priority = Ticket :: Priority . lookup ( name : '2 normal' )
2017-03-03 08:28:45 +00:00
ticket_p . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 13:51:07 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title , 'ticket_p.title verify' )
assert_equal ( 'Users' , ticket_p . group . name , 'ticket_p.group verify' )
assert_equal ( 'new' , ticket_p . state . name , 'ticket_p.state verify' )
assert_equal ( '2 normal' , ticket_p . priority . name , 'ticket_p.priority verify' )
assert_equal ( 2 , ticket_p . articles . count , 'ticket_p.articles verify' )
2019-06-28 11:38:49 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket_p . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message note' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2016-05-03 11:03:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 13:51:07 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title , 'ticket_p.title verify' )
assert_equal ( 'Users' , ticket_p . group . name , 'ticket_p.group verify' )
assert_equal ( 'new' , ticket_p . state . name , 'ticket_p.state verify' )
assert_equal ( '2 normal' , ticket_p . priority . name , 'ticket_p.priority verify' )
assert_equal ( 3 , ticket_p . articles . count , 'ticket_p.articles verify' )
2019-06-28 11:38:49 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket_p . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message note' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2016-05-03 13:51:07 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 13:51:07 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title , 'ticket_p.title verify' )
assert_equal ( 'Users' , ticket_p . group . name , 'ticket_p.group verify' )
assert_equal ( 'new' , ticket_p . state . name , 'ticket_p.state verify' )
assert_equal ( '2 normal' , ticket_p . priority . name , 'ticket_p.priority verify' )
assert_equal ( 4 , ticket_p . articles . count , 'ticket_p.articles verify' )
2019-06-28 11:38:49 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket_p . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message note' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2016-05-03 11:03:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 13:51:07 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title , 'ticket_p.title verify' )
assert_equal ( 'Users' , ticket_p . group . name , 'ticket_p.group verify' )
assert_equal ( 'new' , ticket_p . state . name , 'ticket_p.state verify' )
assert_equal ( '2 normal' , ticket_p . priority . name , 'ticket_p.priority verify' )
assert_equal ( 6 , ticket_p . articles . count , 'ticket_p.articles verify' )
article_p = ticket_p . articles . last
2019-08-16 15:39:31 +00:00
assert_match ( 'Thanks for your follow-up (aaäöüßad asd)' , article_p . subject )
2016-05-03 13:51:07 +00:00
assert_match ( 'Zammad <zammad@localhost>' , article_p . from )
assert_no_match ( 'config\.' , article_p . body )
assert_match ( 'http://zammad.example.com' , article_p . body )
assert_no_match ( 'ticket.' , article_p . body )
assert_match ( ticket_p . number , article_p . body )
assert_equal ( 'text/html' , article_p . content_type )
ticket_p . state = Ticket :: State . lookup ( name : 'open' )
2017-03-03 08:28:45 +00:00
ticket_p . save!
2019-06-28 11:38:49 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket_p . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message note' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2016-05-03 13:51:07 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-05-03 13:51:07 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title , 'ticket_p.title verify' )
assert_equal ( 'Users' , ticket_p . group . name , 'ticket_p.group verify' )
assert_equal ( 'open' , ticket_p . state . name , 'ticket_p.state verify' )
assert_equal ( '2 normal' , ticket_p . priority . name , 'ticket_p.priority verify' )
assert_equal ( 8 , ticket_p . articles . count , 'ticket_p.articles verify' )
article_p = ticket_p . articles . last
2019-08-16 15:39:31 +00:00
assert_match ( 'Thanks for your follow-up (aaäöüßad asd)' , article_p . subject )
2016-05-03 13:51:07 +00:00
assert_match ( 'Zammad <zammad@localhost>' , article_p . from )
assert_no_match ( 'config\.' , article_p . body )
assert_match ( 'http://zammad.example.com' , article_p . body )
assert_no_match ( 'ticket.' , article_p . body )
assert_match ( ticket_p . number , article_p . body )
assert_equal ( 'text/html' , article_p . content_type )
2016-05-03 11:03:10 +00:00
# process mail without Precedence header
2020-02-18 19:51:31 +00:00
content = File . read ( Rails . root . join ( 'test/data/ticket_trigger/mail1.box' ) )
2019-06-28 11:38:49 +00:00
ticket_p1 , _article_p1 , _user_p1 , _mail = Channel :: EmailParser . new . process ( { } , content )
2016-05-03 11:03:10 +00:00
2018-05-29 15:42:14 +00:00
assert_not_equal ( ticket_p . id , ticket_p1 . id )
assert_equal ( 'new' , ticket_p1 . state . name )
assert_equal ( 2 , ticket_p1 . articles . count )
2016-05-03 11:03:10 +00:00
# process mail with Precedence header (no auto response)
2020-02-18 19:51:31 +00:00
content = File . read ( Rails . root . join ( 'test/data/ticket_trigger/mail2.box' ) )
2019-06-28 11:38:49 +00:00
ticket_p2 , _article_p2 , _user_p2 , _mail = Channel :: EmailParser . new . process ( { } , content )
2016-05-03 11:03:10 +00:00
2018-05-29 15:42:14 +00:00
assert_not_equal ( ticket_p . id , ticket_p1 . id )
assert_not_equal ( ticket_p . id , ticket_p2 . id )
assert_not_equal ( ticket_p1 . id , ticket_p2 . id )
assert_equal ( 'new' , ticket_p2 . state . name )
assert_equal ( 1 , ticket_p2 . articles . count )
2016-05-03 11:03:10 +00:00
2016-05-06 07:57:04 +00:00
# process mail with abuse@ (no auto response)
2020-02-18 19:51:31 +00:00
content = File . read ( Rails . root . join ( 'test/data/ticket_trigger/mail3.box' ) )
2019-06-28 11:38:49 +00:00
ticket_p3 , _article_p3 , _user_p3 , _mail = Channel :: EmailParser . new . process ( { } , content )
2018-05-29 15:42:14 +00:00
assert_not_equal ( ticket_p . id , ticket_p1 . id )
assert_not_equal ( ticket_p . id , ticket_p2 . id )
assert_not_equal ( ticket_p . id , ticket_p3 . id )
assert_not_equal ( ticket_p1 . id , ticket_p2 . id )
assert_not_equal ( ticket_p1 . id , ticket_p3 . id )
assert_not_equal ( ticket_p2 . id , ticket_p1 . id )
assert_not_equal ( ticket_p2 . id , ticket_p3 . id )
assert_equal ( 'new' , ticket_p3 . state . name )
assert_equal ( 1 , ticket_p3 . articles . count )
2016-05-03 11:03:10 +00:00
end
2016-07-16 21:43:08 +00:00
test '4 has changed' do
roles = Role . where ( name : 'Customer' )
2019-06-28 11:38:49 +00:00
User . create! (
2018-12-19 17:31:51 +00:00
login : 'postmaster@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'postmaster@example.com' ,
password : 'customerpw' ,
active : true ,
roles : roles ,
updated_at : '2015-02-05 16:37:00' ,
2016-07-16 21:43:08 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2019-06-28 11:38:49 +00:00
User . create! (
2018-12-19 17:31:51 +00:00
login : 'ticket-has-changed-customer2@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer2' ,
email : 'ticket-has-changed-customer2@example.com' ,
password : 'customerpw' ,
active : true ,
2016-07-16 21:43:08 +00:00
organization_id : nil ,
2018-12-19 17:31:51 +00:00
roles : roles ,
updated_at : '2015-02-05 16:37:00' ,
updated_by_id : 1 ,
created_by_id : 1 ,
2016-07-16 21:43:08 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2016-07-16 21:43:08 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent1 = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent-has-changed@example.com' ,
firstname : 'Has Changed' ,
lastname : 'Agent1' ,
email : 'agent-has-changed@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
updated_at : '2015-02-05 16:37:00' ,
2016-07-16 21:43:08 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'owner update - to customer' ,
condition : {
2016-07-16 21:43:08 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'operator' = > 'has changed' ,
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2016-07-16 21:43:08 +00:00
'value_completion' = > '' ,
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-07-16 21:43:08 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > ' < p > The owner of ticket ( Ticket ##{ticket.number}) has changed.<p>
2016-07-16 21:43:08 +00:00
< br / >
< p > To provide additional information , please reply to this email or click on the following link :
< a href = " #{ config . http_type } :// #{ config . fqdn } / # ticket/zoom/ #{ ticket . id } " > #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
< / p>
< br / >
< p > < i > < a href = " http://zammad.com " > Zammad < / a>, your customer support system< /i > < / p>',
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Owner has changed (#{ticket.title})' ,
2016-07-16 21:43:08 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-07-16 21:43:08 +00:00
)
# process mail without Precedence header
2020-02-18 19:51:31 +00:00
content = File . read ( Rails . root . join ( 'test/data/ticket_trigger/mail1.box' ) )
2019-06-28 11:38:49 +00:00
ticket_p , _article_p , _user_p , _mail = Channel :: EmailParser . new . process ( { } , content )
2016-07-16 21:43:08 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title )
assert_equal ( 'Users' , ticket_p . group . name )
assert_equal ( 'new' , ticket_p . state . name )
assert_equal ( 1 , ticket_p . articles . count )
2019-06-28 11:38:49 +00:00
ticket_p . articles . last
2016-07-16 21:43:08 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
ticket_p . owner = agent1
2017-03-03 08:28:45 +00:00
ticket_p . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title , 'ticket_p.title verify' )
assert_equal ( 'Users' , ticket_p . group . name , 'ticket_p.group verify' )
assert_equal ( 'new' , ticket_p . state . name , 'ticket_p.state verify' )
assert_equal ( '2 normal' , ticket_p . priority . name , 'ticket_p.priority verify' )
assert_equal ( 2 , ticket_p . articles . count , 'ticket_p.articles verify' )
2016-08-12 16:39:09 +00:00
#p ticket_p.articles.last.inspect
2016-07-16 21:43:08 +00:00
article_p = ticket_p . articles . last
assert_match ( 'Owner has changed' , article_p . subject )
assert_match ( 'Zammad <zammad@localhost>' , article_p . from )
assert_match ( 'martin@example.com' , article_p . to )
assert_no_match ( 'config\.' , article_p . body )
assert_match ( 'http://zammad.example.com' , article_p . body )
assert_no_match ( 'ticket.' , article_p . body )
assert_match ( ticket_p . number , article_p . body )
assert_equal ( 'text/html' , article_p . content_type )
2019-06-28 11:38:49 +00:00
Trigger . create_or_update (
2018-12-19 17:31:51 +00:00
name : 'owner update - to customer' ,
condition : {
'ticket.owner_id' = > {
'operator' = > 'has changed' ,
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2016-07-16 21:43:08 +00:00
'value_completion' = > '' ,
} ,
'ticket.priority_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Priority . lookup ( name : '3 high' ) . id . to_s ,
2016-07-16 21:43:08 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-07-16 21:43:08 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > ' < p > The owner of ticket ( Ticket ##{ticket.number}) has changed.<p>
2016-07-16 21:43:08 +00:00
< br / >
< p > To provide additional information , please reply to this email or click on the following link :
< a href = " #{ config . http_type } :// #{ config . fqdn } / # ticket/zoom/ #{ ticket . id } " > #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
< / p>
< br / >
< p > < i > < a href = " http://zammad.com " > Zammad < / a>, your customer support system< /i > < / p>',
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Owner has changed (#{ticket.title})' ,
2016-07-16 21:43:08 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-07-16 21:43:08 +00:00
)
# process mail without Precedence header
2020-02-18 19:51:31 +00:00
content = File . read ( Rails . root . join ( 'test/data/ticket_trigger/mail1.box' ) )
2019-06-28 11:38:49 +00:00
ticket_p , _article_p , _user_p , _mail = Channel :: EmailParser . new . process ( { } , content )
2016-07-16 21:43:08 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title )
assert_equal ( 'Users' , ticket_p . group . name )
assert_equal ( 'new' , ticket_p . state . name )
assert_equal ( 1 , ticket_p . articles . count )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
ticket_p . priority = Ticket :: Priority . lookup ( name : '1 low' )
2017-03-03 08:28:45 +00:00
ticket_p . save!
2016-07-16 21:43:08 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
ticket_p . priority = Ticket :: Priority . lookup ( name : '3 high' )
2017-03-03 08:28:45 +00:00
ticket_p . save!
2016-07-16 21:43:08 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
ticket_p . owner = agent1
2017-03-03 08:28:45 +00:00
ticket_p . save!
2016-07-16 21:43:08 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
2016-07-16 21:43:08 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title , 'ticket_p.title verify' )
assert_equal ( 'Users' , ticket_p . group . name , 'ticket_p.group verify' )
assert_equal ( 'new' , ticket_p . state . name , 'ticket_p.state verify' )
assert_equal ( '3 high' , ticket_p . priority . name , 'ticket_p.priority verify' )
assert_equal ( 2 , ticket_p . articles . count , 'ticket_p.articles verify' )
2016-08-12 16:39:09 +00:00
#p ticket_p.articles.last.inspect
2016-07-16 21:43:08 +00:00
article_p = ticket_p . articles . last
assert_match ( 'Owner has changed' , article_p . subject )
assert_match ( 'Zammad <zammad@localhost>' , article_p . from )
assert_match ( 'martin@example.com' , article_p . to )
assert_no_match ( 'config\.' , article_p . body )
assert_match ( 'http://zammad.example.com' , article_p . body )
assert_no_match ( 'ticket.' , article_p . body )
assert_match ( ticket_p . number , article_p . body )
assert_equal ( 'text/html' , article_p . content_type )
# should trigger
2019-06-28 11:38:49 +00:00
Trigger . create_or_update (
2018-12-19 17:31:51 +00:00
name : 'owner update - to customer' ,
condition : {
'ticket.owner_id' = > {
'operator' = > 'has changed' ,
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2016-07-16 21:43:08 +00:00
'value_completion' = > '' ,
} ,
'ticket.priority_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Priority . lookup ( name : '3 high' ) . id . to_s ,
2016-07-16 21:43:08 +00:00
} ,
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2016-07-16 21:43:08 +00:00
'operator' = > 'is not' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2016-07-16 21:43:08 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-07-16 21:43:08 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > ' < p > The owner of ticket ( Ticket ##{ticket.number}) has changed.<p>
2016-07-16 21:43:08 +00:00
< br / >
< p > To provide additional information , please reply to this email or click on the following link :
< a href = " #{ config . http_type } :// #{ config . fqdn } / # ticket/zoom/ #{ ticket . id } " > #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
< / p>
< br / >
< p > < i > < a href = " http://zammad.com " > Zammad < / a>, your customer support system< /i > < / p>',
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Owner has changed (#{ticket.title})' ,
2016-07-16 21:43:08 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-07-16 21:43:08 +00:00
)
# process mail without Precedence header
2020-02-18 19:51:31 +00:00
content = File . read ( Rails . root . join ( 'test/data/ticket_trigger/mail1.box' ) )
2019-06-28 11:38:49 +00:00
ticket_p , _article_p , _user_p , _mail = Channel :: EmailParser . new . process ( { } , content )
2016-07-16 21:43:08 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title )
assert_equal ( 'Users' , ticket_p . group . name )
assert_equal ( 'new' , ticket_p . state . name )
assert_equal ( 1 , ticket_p . articles . count )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
ticket_p . priority = Ticket :: Priority . lookup ( name : '1 low' )
2017-03-03 08:28:45 +00:00
ticket_p . save!
2016-07-16 21:43:08 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
ticket_p . priority = Ticket :: Priority . lookup ( name : '3 high' )
2017-03-03 08:28:45 +00:00
ticket_p . save!
2016-07-16 21:43:08 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
ticket_p . owner = agent1
2017-03-03 08:28:45 +00:00
ticket_p . save!
2016-07-16 21:43:08 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 'aaäöüßad asd' , ticket_p . title , 'ticket_p.title verify' )
assert_equal ( 'Users' , ticket_p . group . name , 'ticket_p.group verify' )
assert_equal ( 'new' , ticket_p . state . name , 'ticket_p.state verify' )
assert_equal ( '3 high' , ticket_p . priority . name , 'ticket_p.priority verify' )
assert_equal ( 2 , ticket_p . articles . count , 'ticket_p.articles verify' )
2016-08-12 16:39:09 +00:00
#p ticket_p.articles.last.inspect
2016-07-16 21:43:08 +00:00
article_p = ticket_p . articles . last
assert_match ( 'Owner has changed' , article_p . subject )
assert_match ( 'Zammad <zammad@localhost>' , article_p . from )
assert_match ( 'martin@example.com' , article_p . to )
assert_no_match ( 'config\.' , article_p . body )
assert_match ( 'http://zammad.example.com' , article_p . body )
assert_no_match ( 'ticket.' , article_p . body )
assert_match ( ticket_p . number , article_p . body )
assert_equal ( 'text/html' , article_p . content_type )
# should not trigger
2019-06-28 11:38:49 +00:00
Trigger . create_or_update (
2018-12-19 17:31:51 +00:00
name : 'owner update - to customer' ,
condition : {
2016-07-16 21:43:08 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'operator' = > 'has changed' ,
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2016-07-16 21:43:08 +00:00
'value_completion' = > '' ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2016-07-16 21:43:08 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2016-07-16 21:43:08 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2016-07-16 21:43:08 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > ' < p > The owner of ticket ( Ticket ##{ticket.number}) has changed.<p>
2016-07-16 21:43:08 +00:00
< br / >
< p > To provide additional information , please reply to this email or click on the following link :
< a href = " #{ config . http_type } :// #{ config . fqdn } / # ticket/zoom/ #{ ticket . id } " > #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
< / p>
< br / >
< p > < i > < a href = " http://zammad.com " > Zammad < / a>, your customer support system< /i > < / p>',
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Owner has changed (#{ticket.title})' ,
2016-07-16 21:43:08 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2016-07-16 21:43:08 +00:00
)
# process mail without Precedence header
2020-02-18 19:51:31 +00:00
content = File . read ( Rails . root . join ( 'test/data/ticket_trigger/mail1.box' ) )
2019-06-28 11:38:49 +00:00
ticket_p , _article_p , _user_p , _mail = Channel :: EmailParser . new . process ( { } , content )
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
ticket_p . owner = agent1
2017-03-03 08:28:45 +00:00
ticket_p . save!
2016-07-16 21:43:08 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2016-07-16 21:43:08 +00:00
assert_equal ( 1 , ticket_p . articles . count )
2017-03-03 08:28:45 +00:00
end
test '5 notify owner' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa notify mail' ,
condition : {
2017-03-03 08:28:45 +00:00
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . all . pluck ( :id ) ,
2017-03-03 08:28:45 +00:00
} ,
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2017-03-03 08:28:45 +00:00
'recipient' = > 'ticket_owner' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'CC NOTE (#{ticket.title})!' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-03-03 08:28:45 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
owner : agent ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
assert_equal ( 1 , ticket1 . articles . count )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
assert_equal ( 3 , ticket1 . articles . count )
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa notify mail 2' ,
condition : {
2017-03-03 08:28:45 +00:00
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . all . pluck ( :id ) ,
2017-03-03 08:28:45 +00:00
} ,
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2017-03-03 08:28:45 +00:00
'recipient' = > 'ticket_owner' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'CC NOTE (#{ticket.title})!' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
assert_equal ( 6 , ticket1 . articles . count )
end
test '6 owner auto assignment' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa auto assignment' ,
condition : {
2017-03-03 08:28:45 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'operator' = > 'is' ,
'pre_condition' = > 'not_set' ,
'value' = > '' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-03-03 08:28:45 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
2017-03-03 08:28:45 +00:00
#owner: agent,
2018-12-19 17:31:51 +00:00
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent . id
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
2017-03-03 08:28:45 +00:00
content_type : 'text/html' ,
2018-12-19 17:31:51 +00:00
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent . id
ticket1 . owner_id = 1
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
end
2017-07-06 13:58:10 +00:00
test '6.1 owner auto assignment based on organization' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa auto assignment' ,
condition : {
2017-07-06 13:58:10 +00:00
'ticket.organization_id' = > {
2018-12-19 17:31:51 +00:00
'operator' = > 'is not' ,
'pre_condition' = > 'not_set' ,
'value' = > '' ,
2017-07-06 13:58:10 +00:00
'value_completion' = > '' ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2017-07-06 13:58:10 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2017-07-06 13:58:10 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-07-06 13:58:10 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2017-07-06 13:58:10 +00:00
'value_completion' = > '' ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-07-06 13:58:10 +00:00
)
roles = Role . where ( name : 'Agent' )
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2019-01-29 14:04:47 +00:00
agent = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-07-06 13:58:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
roles = Role . where ( name : 'Customer' )
2019-01-29 14:04:47 +00:00
customer = User . create! (
2018-12-19 17:31:51 +00:00
login : 'customer@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'customer@example.com' ,
password : 'customerpw' ,
vip : true ,
active : true ,
roles : roles ,
2017-07-06 13:58:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
group : Group . lookup ( name : 'Users' ) ,
customer : customer ,
2017-07-06 13:58:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-07-06 13:58:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-07-06 13:58:10 +00:00
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
2017-09-11 11:16:08 +00:00
ticket1 . update! ( customer : User . lookup ( email : 'nicole.braun@zammad.org' ) )
2017-07-06 13:58:10 +00:00
UserInfo . current_user_id = agent . id
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
2017-07-06 13:58:10 +00:00
content_type : 'text/html' ,
2018-12-19 17:31:51 +00:00
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-07-06 13:58:10 +00:00
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-07-06 13:58:10 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
end
test '6.2 owner auto assignment based on organization' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa auto assignment' ,
condition : {
2017-07-06 13:58:10 +00:00
'ticket.organization_id' = > {
2018-12-19 17:31:51 +00:00
'operator' = > 'is' ,
'pre_condition' = > 'not_set' ,
'value' = > '' ,
2017-07-06 13:58:10 +00:00
'value_completion' = > '' ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2017-07-06 13:58:10 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2017-07-06 13:58:10 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-07-06 13:58:10 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2017-07-06 13:58:10 +00:00
'value_completion' = > '' ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-07-06 13:58:10 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-07-06 13:58:10 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-07-06 13:58:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
roles = Role . where ( name : 'Customer' )
2019-01-29 14:04:47 +00:00
customer = User . create! (
2018-12-19 17:31:51 +00:00
login : 'customer@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'customer@example.com' ,
password : 'customerpw' ,
vip : true ,
active : true ,
roles : roles ,
2017-07-06 13:58:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-07-06 13:58:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-07-06 13:58:10 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-07-06 13:58:10 +00:00
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
2019-01-29 14:04:47 +00:00
ticket1 . update! ( customer : customer )
2017-07-06 13:58:10 +00:00
UserInfo . current_user_id = agent . id
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
2017-07-06 13:58:10 +00:00
content_type : 'text/html' ,
2018-12-19 17:31:51 +00:00
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-07-06 13:58:10 +00:00
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-07-06 13:58:10 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
end
2017-03-03 08:28:45 +00:00
test '7 owner auto assignment' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa auto assignment' ,
condition : {
'ticket.owner_id' = > {
'operator' = > 'is' ,
'pre_condition' = > 'not_set' ,
'value' = > '' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
} ,
2018-12-19 17:31:51 +00:00
'article.type_id' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
} ,
'article.sender_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-03-03 08:28:45 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent1 = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2019-01-29 14:04:47 +00:00
agent2 = User . create! (
login : 'agent2@example.com' ,
2018-12-19 17:31:51 +00:00
firstname : 'Trigger' ,
lastname : 'Agent2' ,
2019-01-29 14:04:47 +00:00
email : 'agent2@example.com' ,
2018-12-19 17:31:51 +00:00
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
2017-03-03 08:28:45 +00:00
#owner: agent,
2018-12-19 17:31:51 +00:00
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent1 . id
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
2017-03-03 08:28:45 +00:00
content_type : 'text/html' ,
2018-12-19 17:31:51 +00:00
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent1 . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent1 . id
ticket1 . owner_id = 1
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent1 . id
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
2017-03-03 08:28:45 +00:00
content_type : 'text/html' ,
2018-12-19 17:31:51 +00:00
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent2 . id
ticket1 . owner_id = agent2 . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent2 . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent1 . id
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
2017-03-03 08:28:45 +00:00
content_type : 'text/html' ,
2018-12-19 17:31:51 +00:00
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
2019-01-29 14:04:47 +00:00
assert_equal ( agent2 . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
2017-03-03 08:28:45 +00:00
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 4 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
end
test '8 owner auto assignment' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa auto assignment' ,
condition : {
'ticket.owner_id' = > {
'operator' = > 'is' ,
'pre_condition' = > 'not_set' ,
'value' = > '' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
} ,
'ticket.priority_id' = > {
2018-12-19 17:31:51 +00:00
'operator' = > 'has changed' ,
'pre_condition' = > '' ,
'value' = > '2' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-03-03 08:28:45 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
2017-03-03 08:28:45 +00:00
#owner: agent,
2018-12-19 17:31:51 +00:00
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent . id
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'update' ,
message_id : 'some@id' ,
2017-03-03 08:28:45 +00:00
content_type : 'text/html' ,
2018-12-19 17:31:51 +00:00
body : 'update' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent . id
ticket1 . priority = Ticket :: Priority . find_by ( name : '1 low' )
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '1 low' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent . id
ticket1 . owner_id = 1
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '1 low' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent . id
ticket1 . owner_id = agent . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '1 low' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
end
test '9 vip priority set' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa vip priority' ,
condition : {
2017-03-03 08:28:45 +00:00
'customer.vip' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > true ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'ticket.priority_id' = > {
'value' = > Ticket :: Priority . find_by ( name : '3 high' ) . id ,
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-03-03 08:28:45 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
roles = Role . where ( name : 'Customer' )
2019-01-29 14:04:47 +00:00
customer = User . create! (
2018-12-19 17:31:51 +00:00
login : 'customer@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'customer@example.com' ,
password : 'customerpw' ,
vip : true ,
active : true ,
roles : roles ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
owner : agent ,
customer : customer ,
group : Group . lookup ( name : 'Users' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
customer . vip = false
customer . save!
2018-01-12 13:59:25 +00:00
ticket2 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
owner : agent ,
customer : customer ,
group : Group . lookup ( name : 'Users' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket2 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'test 123' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( agent . id , ticket2 . owner_id , 'ticket2.owner_id verify' )
assert_equal ( customer . id , ticket2 . customer_id , 'ticket2.customer_id verify' )
assert_equal ( 'new' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 1 , ticket2 . articles . count , 'ticket2.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket2 . tag_list )
2017-03-03 08:28:45 +00:00
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket2 . reload
assert_equal ( 'test 123' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( agent . id , ticket2 . owner_id , 'ticket2.owner_id verify' )
assert_equal ( customer . id , ticket2 . customer_id , 'ticket2.customer_id verify' )
assert_equal ( 'new' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 1 , ticket2 . articles . count , 'ticket2.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket2 . tag_list )
2017-03-03 08:28:45 +00:00
end
test '10 owner auto assignment notify to customer' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa auto assignment' ,
condition : {
2017-03-03 08:28:45 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'operator' = > 'has changed' ,
'pre_condition' = > '' ,
'value' = > '2' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2017-03-03 08:28:45 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'NEW OWNER (#{ticket.title})!' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-03-03 08:28:45 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent1 = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent1@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent1@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2019-01-29 14:04:47 +00:00
agent2 = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent2@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent2' ,
email : 'agent2@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent1 . id
ticket1 . owner_id = agent1 . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent1 . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent1 . id
ticket1 . owner_id = agent1 . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent1 . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent1 . id
ticket1 . owner_id = agent2 . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent2 . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
end
test '11 notify to customer on public note' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa notify to customer on public note' ,
condition : {
'article.internal' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'false' ,
2017-03-03 08:28:45 +00:00
} ,
'article.sender_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Article :: Sender . lookup ( name : 'Agent' ) . id ,
2017-03-03 08:28:45 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.type_id' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > [
2017-03-03 08:28:45 +00:00
Ticket :: Article :: Type . lookup ( name : 'note' ) . id ,
] ,
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2017-03-03 08:28:45 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'UPDATE (#{ticket.title})!' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-03-03 08:28:45 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
roles = Role . where ( name : 'Customer' )
2019-01-29 14:04:47 +00:00
customer = User . create! (
2018-12-19 17:31:51 +00:00
login : 'customer@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'customer@example.com' ,
password : 'customerpw' ,
vip : true ,
active : true ,
roles : roles ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
owner : agent ,
customer : customer ,
group : Group . lookup ( name : 'Users' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : true ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 5 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
ticket1 . priority = Ticket :: Priority . find_by ( name : '3 high' )
ticket1 . save!
2018-01-12 13:59:25 +00:00
article = Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : true ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 6 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
article . internal = false
article . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 6 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : true ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 7 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
end
test '12 notify on owner change' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa notify to customer on public note' ,
condition : {
2017-03-03 08:28:45 +00:00
'ticket.owner_id' = > {
2018-12-19 17:31:51 +00:00
'operator' = > 'has changed' ,
'pre_condition' = > 'current_user.id' ,
'value' = > '' ,
2017-03-03 08:28:45 +00:00
'value_completion' = > '' ,
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2017-03-03 08:28:45 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'UPDATE (#{ticket.title})!' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-03-03 08:28:45 +00:00
)
2019-01-29 14:04:47 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply (on new tickets)' ,
condition : {
'ticket.action' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-03-03 08:28:45 +00:00
} ,
2018-12-19 17:31:51 +00:00
'ticket.state_id' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is not' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'closed' ) . id ,
2017-03-03 08:28:45 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.type_id' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > [
2017-03-03 08:28:45 +00:00
Ticket :: Article :: Type . lookup ( name : 'email' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'phone' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'web' ) . id ,
] ,
} ,
'article.sender_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Article :: Sender . lookup ( name : 'Customer' ) . id ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > ' < div > Your request < b > ( #{config.ticket_hook}#{ticket.number})</b> has been received and will be reviewed by our support staff.</div>
2017-03-03 08:28:45 +00:00
< br / >
< div > To provide additional information , please reply to this email or click on the following link ( for initial login , please request a new password ) :
< a href = " #{ config . http_type } :// #{ config . fqdn } / # ticket/zoom/ #{ ticket . id } " > #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
< / div>
< br / >
< div > Your #{config.product_name} Team</div>
< br / >
< div > < i > < a href = " https://zammad.com " > Zammad < / a>, your customer support system< /i > < / div>',
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
active : true ,
2017-03-03 08:28:45 +00:00
created_by_id : 1 ,
updated_by_id : 1 ,
)
2019-01-29 14:04:47 +00:00
Trigger . create! (
2019-08-16 15:39:31 +00:00
name : 'auto reply (on follow-up of tickets)' ,
2018-12-19 17:31:51 +00:00
condition : {
'ticket.action' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'update' ,
2017-03-03 08:28:45 +00:00
} ,
'article.sender_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Article :: Sender . lookup ( name : 'Customer' ) . id ,
2017-03-03 08:28:45 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.type_id' = > {
2017-03-03 08:28:45 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > [
2017-03-03 08:28:45 +00:00
Ticket :: Article :: Type . lookup ( name : 'email' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'phone' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'web' ) . id ,
] ,
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-03-03 08:28:45 +00:00
'notification.email' = > {
2019-08-16 15:39:31 +00:00
'body' = > ' < div > Your follow - up for < b > ( #{config.ticket_hook}#{ticket.number})</b> has been received and will be reviewed by our support staff.</div>
2017-03-03 08:28:45 +00:00
< br / >
< div > To provide additional information , please reply to this email or click on the following link :
< a href = " #{ config . http_type } :// #{ config . fqdn } / # ticket/zoom/ #{ ticket . id } " > #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
< / div>
< br / >
< div > Your #{config.product_name} Team</div>
< br / >
< div > < i > < a href = " https://zammad.com " > Zammad < / a>, your customer support system< /i > < / div>',
'recipient' = > 'ticket_customer' ,
2019-08-16 15:39:31 +00:00
'subject' = > 'Thanks for your follow-up (#{ticket.title})' ,
2017-03-03 08:28:45 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
active : true ,
2017-03-03 08:28:45 +00:00
created_by_id : 1 ,
updated_by_id : 1 ,
)
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2017-03-03 08:28:45 +00:00
roles = Role . where ( name : 'Agent' )
2019-01-29 14:04:47 +00:00
agent = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent@example.com' ,
firstname : 'Trigger' ,
lastname : 'Agent1' ,
email : 'agent@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
roles = Role . where ( name : 'Customer' )
2019-01-29 14:04:47 +00:00
customer = User . create! (
2018-12-19 17:31:51 +00:00
login : 'customer@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'customer@example.com' ,
password : 'customerpw' ,
vip : true ,
active : true ,
roles : roles ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 123' ,
2017-03-03 08:28:45 +00:00
#owner: agent,
2018-12-19 17:31:51 +00:00
customer : customer ,
group : Group . lookup ( name : 'Users' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'web' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent . id
ticket1 . owner_id = agent . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'web' ) ,
2017-03-03 08:28:45 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( agent . id , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 5 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = agent . id
ticket1 . owner_id = 1
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-03-03 08:28:45 +00:00
UserInfo . current_user_id = nil
ticket1 . reload
assert_equal ( 'test 123' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 1 , ticket1 . owner_id , 'ticket1.owner_id verify' )
assert_equal ( customer . id , ticket1 . customer_id , 'ticket1.customer_id verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 6 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-04-12 07:34:49 +00:00
assert_equal ( [ ] , ticket1 . tag_list )
2016-07-16 21:43:08 +00:00
end
2017-04-27 14:57:19 +00:00
test '1 empty condition should not create errors' do
2017-10-01 12:25:52 +00:00
assert_raises ( Exception ) do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa loop check' ,
condition : {
2017-04-27 14:57:19 +00:00
'ticket.number' = > {
'operator' = > 'contains' ,
'value' = > '' ,
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-04-27 14:57:19 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2017-04-27 14:57:19 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry - loop check (#{ticket.title})!' ,
2017-04-27 14:57:19 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-04-27 14:57:19 +00:00
)
2017-10-01 12:25:52 +00:00
end
2017-04-27 14:57:19 +00:00
end
2017-05-02 11:34:18 +00:00
test 'article_last_sender trigger -> reply_to' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2017-05-02 11:34:18 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-05-02 11:34:18 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2017-05-02 11:34:18 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-05-02 11:34:18 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2017-05-02 11:34:18 +00:00
'recipient' = > 'article_last_sender' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2017-05-02 11:34:18 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-05-02 11:34:18 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient+from@example.com' ,
reply_to : 'some_recipient+reply_to@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-02 11:34:18 +00:00
ticket1 . reload
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state new' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
auto_response = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , auto_response . from )
assert_match ( 'some_recipient+reply_to@example.com' , auto_response . to )
end
test 'article_last_sender trigger -> from' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2017-05-02 11:34:18 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-05-02 11:34:18 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2017-05-02 11:34:18 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-05-02 11:34:18 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2017-05-02 11:34:18 +00:00
'recipient' = > 'article_last_sender' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2017-05-02 11:34:18 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-05-02 11:34:18 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender+from@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-02 11:34:18 +00:00
ticket1 . reload
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state new' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
auto_response = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , auto_response . from )
assert_match ( 'some_sender+from@example.com' , auto_response . to )
end
test 'article_last_sender trigger -> origin_by_id' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2017-05-02 11:34:18 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-05-02 11:34:18 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2017-05-02 11:34:18 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-05-02 11:34:18 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2017-05-02 11:34:18 +00:00
'recipient' = > 'article_last_sender' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2017-05-02 11:34:18 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-05-02 11:34:18 +00:00
)
roles = Role . where ( name : 'Customer' )
2019-01-29 14:04:47 +00:00
customer1 = User . create! (
2018-12-19 17:31:51 +00:00
login : 'customer+origin_by_id@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'customer+origin_by_id@example.com' ,
password : 'customerpw' ,
active : true ,
roles : roles ,
updated_at : '2015-02-05 16:37:00' ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
origin_by_id : customer1 . id ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-02 11:34:18 +00:00
ticket1 . reload
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state new' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
auto_response = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , auto_response . from )
assert_match ( 'customer+origin_by_id@example.com' , auto_response . to )
end
test 'article_last_sender trigger -> created_by_id' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2017-05-02 11:34:18 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-05-02 11:34:18 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2017-05-02 11:34:18 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-05-02 11:34:18 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2017-05-02 11:34:18 +00:00
'recipient' = > 'article_last_sender' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2017-05-02 11:34:18 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-05-02 11:34:18 +00:00
)
roles = Role . where ( name : 'Customer' )
2019-01-29 14:04:47 +00:00
customer1 = User . create! (
2018-12-19 17:31:51 +00:00
login : 'customer+created_by_id@example.com' ,
firstname : 'Trigger' ,
lastname : 'Customer1' ,
email : 'customer+created_by_id@example.com' ,
password : 'customerpw' ,
active : true ,
roles : roles ,
updated_at : '2015-02-05 16:37:00' ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : customer1 . id ,
created_by_id : customer1 . id ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-02 11:34:18 +00:00
ticket1 . reload
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state new' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
auto_response = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , auto_response . from )
assert_match ( 'customer+created_by_id@example.com' , auto_response . to )
end
test 'multiple recipients owner_id, article_last_sender(reply_to) trigger' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2017-05-02 11:34:18 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-05-02 11:34:18 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2017-05-02 11:34:18 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-05-02 11:34:18 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2017-11-23 08:09:44 +00:00
'recipient' = > %w[ ticket_owner article_last_sender ] ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2017-05-02 11:34:18 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-05-02 11:34:18 +00:00
)
2019-01-29 14:04:47 +00:00
admin = User . create! (
2018-12-19 17:31:51 +00:00
login : 'admin+owner_recipient@example.com' ,
firstname : 'Role' ,
lastname : " Admin #{ name } " ,
email : 'admin+owner_recipient@example.com' ,
password : 'adminpw' ,
active : true ,
roles : Role . where ( name : %w[ Admin Agent ] ) ,
groups : Group . where ( name : 'Users' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
owner_id : admin . id ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient+from@example.com' ,
reply_to : 'some_recipient+reply_to@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-02 11:34:18 +00:00
ticket1 . reload
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state new' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
auto_response = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , auto_response . from )
assert_match ( 'some_recipient+reply_to@example.com' , auto_response . to )
assert_match ( 'admin+owner_recipient@example.com' , auto_response . to )
end
test 'article_last_sender trigger -> invalid reply_to' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2017-05-02 11:34:18 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-05-02 11:34:18 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2017-05-02 11:34:18 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-05-02 11:34:18 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2017-05-02 11:34:18 +00:00
'recipient' = > 'article_last_sender' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2017-05-02 11:34:18 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-05-02 11:34:18 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient+from@example.com' ,
reply_to : 'Blub blub blub some_recipient+reply_to@example' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-05-02 11:34:18 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-02 11:34:18 +00:00
ticket1 . reload
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state new' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
end
2017-05-24 10:57:00 +00:00
test '2 loop check' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa loop check' ,
condition : {
'ticket.state_id' = > {
2017-05-24 10:57:00 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . all . pluck ( :id ) ,
2017-05-24 10:57:00 +00:00
} ,
'article.sender_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: Article :: Sender . lookup ( name : 'Customer' ) . id ,
2017-05-24 10:57:00 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.type_id' = > {
2017-05-24 10:57:00 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > [
2017-05-24 10:57:00 +00:00
Ticket :: Article :: Type . lookup ( name : 'email' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'phone' ) . id ,
Ticket :: Article :: Type . lookup ( name : 'web' ) . id ,
] ,
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-05-24 10:57:00 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2017-05-24 10:57:00 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry - loop check (#{ticket.title})!' ,
2017-05-24 10:57:00 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-05-24 10:57:00 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'loop try 1' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket1 . reload
assert_equal ( 1 , ticket1 . articles . count )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 2 , ticket1 . articles . count )
ticket1 . priority = Ticket :: Priority . lookup ( name : '2 normal' )
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 2 , ticket1 . articles . count )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 4 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 2 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 3 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 6 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 4 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 5 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 8 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 6 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 7 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 10 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 8 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 9 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 12 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 10 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 11 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 14 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 12 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 13 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 16 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 14 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 15 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 18 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 16 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 17 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
assert_equal ( 20 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 18 ] . from )
assert_equal ( 'nicole.braun@zammad.org' , ticket1 . articles [ 19 ] . to )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
2017-06-23 22:09:51 +00:00
assert_equal ( 21 , ticket1 . articles . count )
2017-05-24 10:57:00 +00:00
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 20 ] . from )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_loop_sender@example.com' ,
to : 'some_loop_recipient@example.com' ,
subject : 'some subject 1234' ,
message_id : 'some@id' ,
content_type : 'text/html' ,
body : 'some message <b>note</b><br>new line' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2017-05-24 10:57:00 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-05-24 10:57:00 +00:00
ticket1 . reload
2017-06-23 22:09:51 +00:00
assert_equal ( 22 , ticket1 . articles . count )
assert_equal ( 'some_loop_sender@example.com' , ticket1 . articles [ 21 ] . from )
2017-05-24 10:57:00 +00:00
end
2017-08-13 09:54:57 +00:00
test '3 invalid condition' do
2019-01-29 14:04:47 +00:00
trigger1 = Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'aaa loop check' ,
condition : {
2017-08-13 09:54:57 +00:00
'ticket.action' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-08-13 09:54:57 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-08-13 09:54:57 +00:00
'ticket.tags' = > {
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'xxx' ,
2017-08-13 09:54:57 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-08-13 09:54:57 +00:00
)
trigger1 . update_column ( :condition , {
2018-12-19 17:31:51 +00:00
'ticket.action' = > {
2017-08-13 09:54:57 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-08-13 09:54:57 +00:00
} ,
'ticket.first_response_at' = > {
'operator' = > 'before (absolute)' ,
2018-12-19 17:31:51 +00:00
'value' = > 'invalid invalid 4' ,
2017-08-13 09:54:57 +00:00
} ,
} )
assert_equal ( 'invalid invalid 4' , trigger1 . condition [ 'ticket.first_response_at' ] [ 'value' ] )
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2017-08-13 09:54:57 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2017-08-13 09:54:57 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2017-08-13 09:54:57 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
2017-08-13 09:54:57 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2017-08-13 09:54:57 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2017-08-13 09:54:57 +00:00
} ,
'ticket.priority_id' = > {
'value' = > Ticket :: Priority . lookup ( name : '3 high' ) . id . to_s ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.tags' = > {
2017-08-13 09:54:57 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'aa, kk' ,
2017-08-13 09:54:57 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2017-08-13 09:54:57 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2017-08-13 09:54:57 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2017-08-13 09:54:57 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket1 . reload
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2017-08-13 09:54:57 +00:00
ticket1 . reload
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '3 high' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
2017-11-23 08:09:44 +00:00
assert_equal ( %w[ aa kk ] , ticket1 . tag_list )
2017-08-13 09:54:57 +00:00
article1 = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , article1 . from )
assert_match ( 'nicole.braun@zammad.org' , article1 . to )
assert_match ( 'Thanks for your inquiry (some <b>title</b> äöüß)!' , article1 . subject )
assert_match ( 'Braun<br>some <b>title</b>' , article1 . body )
assert_match ( '> some message <b>note</b><br>> new line' , article1 . body )
assert_equal ( 'text/html' , article1 . content_type )
end
2018-01-09 07:39:50 +00:00
test '4 tag based auto response' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : '100 add tag if sender 1' ,
condition : {
2018-01-09 07:39:50 +00:00
'ticket.action' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2018-01-09 07:39:50 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.from' = > {
2018-01-09 07:39:50 +00:00
'operator' = > 'contains' ,
2018-12-19 17:31:51 +00:00
'value' = > 'sender1' ,
2018-01-09 07:39:50 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-01-09 07:39:50 +00:00
'ticket.tags' = > {
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'sender1' ,
2018-01-09 07:39:50 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-09 07:39:50 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : '200 add tag if sender 2' ,
condition : {
2018-01-09 07:39:50 +00:00
'ticket.action' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2018-01-09 07:39:50 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.from' = > {
2018-01-09 07:39:50 +00:00
'operator' = > 'contains' ,
2018-12-19 17:31:51 +00:00
'value' = > 'sender2' ,
2018-01-09 07:39:50 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-01-09 07:39:50 +00:00
'ticket.tags' = > {
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'sender2' ,
2018-01-09 07:39:50 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-09 07:39:50 +00:00
)
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : '300 auto reply' ,
condition : {
'ticket.action' = > {
2018-01-09 07:39:50 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2018-01-09 07:39:50 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2018-01-09 07:39:50 +00:00
} ,
2018-12-19 17:31:51 +00:00
'ticket.tags' = > {
2018-01-09 07:39:50 +00:00
#'operator' => 'contains one not',
'operator' = > 'contains all not' ,
2018-12-19 17:31:51 +00:00
'value' = > 'sender1, sender2' ,
2018-01-09 07:39:50 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-01-09 07:39:50 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2018-01-09 07:39:50 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2018-01-09 07:39:50 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-09 07:39:50 +00:00
)
2018-01-12 13:59:25 +00:00
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 1' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-09 07:39:50 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'sender1@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2018-01-09 07:39:50 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket1 . reload
assert_equal ( 'test 1' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-09 07:39:50 +00:00
ticket1 . reload
assert_equal ( 'test 1' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( %w[ sender1 ] , ticket1 . tag_list )
2018-01-12 13:59:25 +00:00
ticket2 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 2' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-09 07:39:50 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket2 . id ,
from : 'sender2@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2018-01-09 07:39:50 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket2 . reload
assert_equal ( 'test 2' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( 'new' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 1 , ticket2 . articles . count , 'ticket2.articles verify' )
assert_equal ( [ ] , ticket2 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-09 07:39:50 +00:00
ticket2 . reload
assert_equal ( 'test 2' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( 'new' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 1 , ticket2 . articles . count , 'ticket2.articles verify' )
assert_equal ( %w[ sender2 ] , ticket2 . tag_list )
2018-01-12 13:59:25 +00:00
ticket3 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 3' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-09 07:39:50 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert ( ticket3 , 'ticket3 created' )
2018-01-12 13:59:25 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket3 . id ,
from : 'sender0@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2018-01-09 07:39:50 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket3 . reload
assert_equal ( 'test 3' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( '2 normal' , ticket3 . priority . name , 'ticket3.priority verify' )
assert_equal ( 1 , ticket3 . articles . count , 'ticket3.articles verify' )
assert_equal ( [ ] , ticket3 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-09 07:39:50 +00:00
ticket3 . reload
assert_equal ( 'test 3' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( '2 normal' , ticket3 . priority . name , 'ticket3.priority verify' )
assert_equal ( 2 , ticket3 . articles . count , 'ticket3.articles verify' )
assert_equal ( [ ] , ticket3 . tag_list )
2019-06-28 11:38:49 +00:00
ticket3 . articles . last
2018-01-09 07:39:50 +00:00
end
2018-01-12 13:59:25 +00:00
test 'article.body' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2018-01-12 13:59:25 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2018-01-12 13:59:25 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2018-01-12 13:59:25 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.body' = > {
2018-01-12 13:59:25 +00:00
'operator' = > 'contains' ,
2018-12-19 17:31:51 +00:00
'value' = > 'hello' ,
2018-01-12 13:59:25 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-01-12 13:59:25 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2018-01-12 13:59:25 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2018-01-12 13:59:25 +00:00
} ,
2018-12-19 17:31:51 +00:00
'ticket.tags' = > {
2018-01-12 13:59:25 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'aa, kk' ,
2018-01-12 13:59:25 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-12 13:59:25 +00:00
)
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 1' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-12 13:59:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message <b>note</b> hello ' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2018-01-12 13:59:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket1 . reload
assert_equal ( 'test 1' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-12 13:59:25 +00:00
ticket1 . reload
assert_equal ( 'test 1' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( %w[ aa kk ] , ticket1 . tag_list )
article1 = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , article1 . from )
assert_match ( 'nicole.braun@zammad.org' , article1 . to )
assert_match ( 'Thanks for your inquiry (test 1)!' , article1 . subject )
assert_match ( 'some message' , article1 . body )
assert_match ( '> some message <b>note</b> hello' , article1 . body )
assert_equal ( 'text/html' , article1 . content_type )
ticket2 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 1' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-12 13:59:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket2 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message <b>note</b>' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2018-01-12 13:59:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket2 . reload
assert_equal ( 'test 1' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( 'new' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 1 , ticket2 . articles . count , 'ticket2.articles verify' )
assert_equal ( [ ] , ticket2 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-12 13:59:25 +00:00
ticket2 . reload
assert_equal ( 'test 1' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( 'new' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( 1 , ticket2 . articles . count , 'ticket2.articles verify' )
assert_equal ( %w[ ] , ticket2 . tag_list )
2019-06-28 11:38:49 +00:00
Trigger . create_or_update (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2018-01-12 13:59:25 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2018-01-12 13:59:25 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2018-01-12 13:59:25 +00:00
} ,
2018-12-19 17:31:51 +00:00
'article.body' = > {
2018-01-12 13:59:25 +00:00
'operator' = > 'contains not' ,
2018-12-19 17:31:51 +00:00
'value' = > 'hello' ,
2018-01-12 13:59:25 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-01-12 13:59:25 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2018-01-12 13:59:25 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2018-01-12 13:59:25 +00:00
} ,
2018-12-19 17:31:51 +00:00
'ticket.tags' = > {
2018-01-12 13:59:25 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'aa, kk' ,
2018-01-12 13:59:25 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-12 13:59:25 +00:00
)
ticket3 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 1' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-12 13:59:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket3 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message <b>note</b> hello ' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2018-01-12 13:59:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket3 . reload
assert_equal ( 'test 1' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( '2 normal' , ticket3 . priority . name , 'ticket3.priority verify' )
assert_equal ( 1 , ticket3 . articles . count , 'ticket3.articles verify' )
assert_equal ( [ ] , ticket3 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-12 13:59:25 +00:00
ticket3 . reload
assert_equal ( 'test 1' , ticket3 . title , 'ticket3.title verify' )
assert_equal ( 'Users' , ticket3 . group . name , 'ticket3.group verify' )
assert_equal ( 'new' , ticket3 . state . name , 'ticket3.state verify' )
assert_equal ( 1 , ticket3 . articles . count , 'ticket3.articles verify' )
assert_equal ( %w[ ] , ticket3 . tag_list )
ticket4 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 1' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-12 13:59:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket4 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message <b>note</b> 2' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2018-01-12 13:59:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket4 . reload
assert_equal ( 'test 1' , ticket4 . title , 'ticket4.title verify' )
assert_equal ( 'Users' , ticket4 . group . name , 'ticket4.group verify' )
assert_equal ( 'new' , ticket4 . state . name , 'ticket4.state verify' )
assert_equal ( '2 normal' , ticket4 . priority . name , 'ticket4.priority verify' )
assert_equal ( 1 , ticket4 . articles . count , 'ticket4.articles verify' )
assert_equal ( [ ] , ticket4 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-12 13:59:25 +00:00
ticket4 . reload
assert_equal ( 'test 1' , ticket4 . title , 'ticket4.title verify' )
assert_equal ( 'Users' , ticket4 . group . name , 'ticket4.group verify' )
assert_equal ( 'new' , ticket4 . state . name , 'ticket4.state verify' )
assert_equal ( 2 , ticket4 . articles . count , 'ticket4.articles verify' )
assert_equal ( %w[ aa kk ] , ticket4 . tag_list )
article4 = ticket4 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , article4 . from )
assert_match ( 'nicole.braun@zammad.org' , article4 . to )
assert_match ( 'Thanks for your inquiry (test 1)!' , article4 . subject )
assert_match ( 'some message' , article4 . body )
assert_match ( '> some message <b>note</b> 2' , article4 . body )
assert_equal ( 'text/html' , article4 . content_type )
end
2018-01-15 16:49:46 +00:00
test 'change owner' do
roles = Role . where ( name : 'Agent' )
2018-02-10 10:40:57 +00:00
groups = Group . where ( name : 'Users' )
2019-01-29 14:04:47 +00:00
agent1 = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent-has-changed@example.com' ,
firstname : 'Has Changed' ,
lastname : 'Agent1' ,
email : 'agent-has-changed@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
updated_at : '2015-02-05 16:37:00' ,
2018-01-15 16:49:46 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2019-01-29 14:04:47 +00:00
agent2 = User . create! (
2018-12-19 17:31:51 +00:00
login : 'agent-has-changed2@example.com' ,
firstname : 'Has Changed' ,
lastname : 'Agent2' ,
email : 'agent-has-changed2@example.com' ,
password : 'agentpw' ,
active : true ,
roles : roles ,
groups : groups ,
updated_at : '2015-02-05 16:37:00' ,
2018-01-15 16:49:46 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
# multi tag trigger with changed owner
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'change owner' ,
condition : {
2018-01-15 16:49:46 +00:00
'ticket.owner_id' = > {
'operator' = > 'has changed' ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.tags' = > {
2018-01-15 16:49:46 +00:00
'operator' = > 'contains one not' ,
2018-12-19 17:31:51 +00:00
'value' = > 'nosendmail test123'
2018-01-15 16:49:46 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
'ticket.tags' = > {
2018-01-15 16:49:46 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > '123'
2018-01-15 16:49:46 +00:00
} ,
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2018-01-15 16:49:46 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry - 1234 check (#{ticket.title})!' ,
2018-01-15 16:49:46 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-15 16:49:46 +00:00
)
# single tag trigger with changed owner
2019-06-28 11:38:49 +00:00
Trigger . create_or_update (
2018-12-19 17:31:51 +00:00
name : 'change owner' ,
condition : {
2018-01-15 16:49:46 +00:00
'ticket.owner_id' = > {
'operator' = > 'has changed' ,
} ,
2018-12-19 17:31:51 +00:00
'ticket.tags' = > {
2018-01-15 16:49:46 +00:00
'operator' = > 'contains one not' ,
2018-12-19 17:31:51 +00:00
'value' = > 'nosendmail2' ,
2018-01-15 16:49:46 +00:00
}
} ,
2018-12-19 17:31:51 +00:00
perform : {
'ticket.tags' = > {
2018-01-15 16:49:46 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > '123'
2018-01-15 16:49:46 +00:00
} ,
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2018-01-15 16:49:46 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry - 1234 check (#{ticket.title})!' ,
2018-01-15 16:49:46 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-15 16:49:46 +00:00
)
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some title \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-15 16:49:46 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 0 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( 'agent-has-changed@example.com' , agent1 . login , 'verify agent' )
assert_equal ( [ ] , ticket1 . tag_list , 'ticket1.tag_list' )
ticket2 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some title \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-15 16:49:46 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_equal ( 'some title äöüß' , ticket2 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( 'new' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 0 , ticket2 . articles . count , 'ticket2.articles verify' )
assert_equal ( 'agent-has-changed@example.com' , agent1 . login , 'verify agent' )
assert_equal ( [ ] , ticket1 . tag_list , 'ticket2.tag_list' )
# control test - should pass
# create common object tag
2019-06-28 11:38:49 +00:00
Tag :: Object . create_or_update ( name : 'Ticket' )
2018-01-15 16:49:46 +00:00
# add tag
ticket1 . tag_add ( 'thisisthebestjob' , agent1 . id )
# change owner
ticket1 . owner_id = agent1 . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-15 16:49:46 +00:00
# this will add a tag by trigger
ticket1 . reload
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket2.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket2.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket2.articles verify' ) # articles.count must be 1 if the tag is added
assert_equal ( 'agent-has-changed@example.com' , agent1 . login , 'verify agent' )
assert_equal ( %w[ thisisthebestjob 123 ] , ticket1 . tag_list , 'ticket2.tag_list' )
# add tag nosendmail (to test the bug)
ticket1 . tag_add ( 'nosendmail' , agent2 . id )
# change owner
ticket1 . owner_id = agent2 . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-15 16:49:46 +00:00
ticket1 . reload
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' ) # articles.count must be 0 if adding tag is skipped
assert_equal ( 'agent-has-changed2@example.com' , agent2 . login , 'verify agent' )
assert_equal ( %w[ thisisthebestjob 123 nosendmail ] , ticket1 . tag_list , 'ticket1.tag_list' )
# add tag (to test the bug)
ticket1 . tag_add ( 'test123' , agent2 . id )
# change owner
ticket1 . owner_id = agent1 . id
ticket1 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-15 16:49:46 +00:00
ticket1 . reload
assert_equal ( 'some title äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' ) # articles.count must be 0 if adding tag is skipped
assert_equal ( 'agent-has-changed@example.com' , agent1 . login , 'verify agent' )
assert_equal ( %w[ thisisthebestjob 123 nosendmail test123 ] , ticket1 . tag_list , 'ticket1.tag_list' )
# add tag single tag 'nosendmail2' (to test the bug)
ticket2 . tag_add ( 'nosendmail2' , agent1 . id )
# change owner
ticket2 . owner_id = agent1 . id
ticket2 . save!
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-15 16:49:46 +00:00
ticket2 . reload
assert_equal ( 'some title äöüß' , ticket2 . title , 'ticket2.title verify' )
assert_equal ( 'Users' , ticket2 . group . name , 'ticket2.group verify' )
assert_equal ( 'new' , ticket2 . state . name , 'ticket2.state verify' )
assert_equal ( '2 normal' , ticket2 . priority . name , 'ticket2.priority verify' )
assert_equal ( 0 , ticket2 . articles . count , 'ticket2.articles verify' ) # articles.count must be 0 if adding tag is skipped
assert_equal ( 'agent-has-changed@example.com' , agent1 . login , 'verify agent' )
assert_equal ( [ 'nosendmail2' ] , ticket2 . tag_list , 'ticket2.tag_list' )
2018-01-15 17:19:12 +00:00
end
2018-01-15 15:22:52 +00:00
test 'trigger auto reply with umlaut in form' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2018-01-15 15:22:52 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2018-01-15 15:22:52 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2018-01-15 15:22:52 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-01-15 15:22:52 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2018-01-15 15:22:52 +00:00
'recipient' = > 'article_last_sender' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2018-01-15 15:22:52 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-15 15:22:52 +00:00
)
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : 'test 1' ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-01-15 15:22:52 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
2018-01-15 17:19:12 +00:00
2018-01-15 15:22:52 +00:00
Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'Sabine Schütz <some_sender@example.com>' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : 'some message <b>note</b> hello ' ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Customer' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'email' ) ,
2018-01-15 15:22:52 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket1 . reload
assert_equal ( 'test 1' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( 'Sabine Schütz <some_sender@example.com>' , ticket1 . articles . first . from , 'ticket1.articles.first.from verify' )
assert_equal ( [ ] , ticket1 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-01-15 15:22:52 +00:00
ticket1 . reload
assert_equal ( 'test 1' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
article1 = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , article1 . from )
assert_match ( 'some_sender@example.com' , article1 . to )
assert_match ( 'Thanks for your inquiry (test 1)!' , article1 . subject )
assert_match ( 'some message' , article1 . body )
assert_match ( '> some message <b>note</b> hello' , article1 . body )
assert_equal ( 'text/html' , article1 . content_type )
end
test 'trigger auto reply with 2 sender addresses in form' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2018-01-15 15:22:52 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2018-01-15 15:22:52 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2018-01-15 15:22:52 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-01-15 15:22:52 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}' ,
2018-01-15 15:22:52 +00:00
'recipient' = > 'article_last_sender' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2018-01-15 15:22:52 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-01-15 15:22:52 +00:00
)
2020-02-18 19:51:31 +00:00
ticket1 , _article1 , _user , _mail = Channel :: EmailParser . new . process ( { } , File . read ( Rails . root . join ( 'test/data/mail/mail065.box' ) ) )
2018-01-15 15:22:52 +00:00
assert_equal ( 'aaäöüßad asd' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
article1 = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , article1 . from )
assert_match ( 'smith@example.com' , article1 . to )
assert_match ( 'Thanks for your inquiry (aaäöüßad asd)!' , article1 . subject )
assert_match ( 'some text<br><br>aaäöüßad asd' , article1 . body )
assert_equal ( 'text/html' , article1 . content_type )
2018-01-15 16:49:46 +00:00
end
2018-04-07 05:01:57 +00:00
test 'make sure attachments should be attached with content id' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply' ,
condition : {
'ticket.action' = > {
2018-04-07 05:01:57 +00:00
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > 'create' ,
2018-04-07 05:01:57 +00:00
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
2018-12-19 17:31:51 +00:00
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
2018-04-07 05:01:57 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-04-07 05:01:57 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}<br><img tabindex="0" style="width: 192px; height: 192px" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCADAAMADAREAAhEBAxEB/8QAHgABAAICAwEBAQAAAAAAAAAAAAcICQoFBgsDAQT/xAA7EAAABwEAAQMCAgYJAgcAAAAAAQIDBAUGBwgJERITIQoUFRciMXa1FiMyNzg5QVF3JLIYGSc1QkVh/8QAHQEBAAICAwEBAAAAAAAAAAAAAAQFAwYCBwgBCf/EAEURAAICAgEDAgMEBAkLBAMAAAECAAMEEQUGEiETMQciQQgUMlEjYXF2FTM1QnJzgZGzFjY3OFJiobGytLUXGILBJTRD/9oADAMBAAIRAxEAPwDU/G4SPARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARLM+HPi5uvNDyU5T4086cbiaXp+iTU/piTGflwM3TxYsiyv9PZx4xk+5WZ+nhzLSelk/qnGjLJslLNKT++Atjk6Wquy1z/uo">' ,
2018-04-07 05:01:57 +00:00
'recipient' = > 'article_last_sender' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2018-04-07 05:01:57 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-04-07 05:01:57 +00:00
)
2020-02-18 19:51:31 +00:00
ticket1 , _article1 , _user , _mail = Channel :: EmailParser . new . process ( { } , File . read ( Rails . root . join ( 'test/data/mail/mail065.box' ) ) )
2018-04-07 05:01:57 +00:00
assert_equal ( 'aaäöüßad asd' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
article1 = ticket1 . articles . last
assert_match ( 'Zammad <zammad@localhost>' , article1 . from )
assert_match ( 'smith@example.com' , article1 . to )
assert_match ( 'Thanks for your inquiry (aaäöüßad asd)!' , article1 . subject )
2021-05-12 11:37:44 +00:00
assert_match ( %r{ .+cid:.+?@zammad.example.com.+ } , article1 . body )
2018-04-09 06:49:32 +00:00
assert_equal ( 1 , article1 . attachments . count )
assert_equal ( '789' , article1 . attachments [ 0 ] . size )
2018-04-07 05:01:57 +00:00
assert_equal ( 'text/html' , article1 . content_type )
end
2018-07-04 10:07:25 +00:00
# Issue #1316 - 'organization is not X' conditions break triggers
test 'NOT IN predicates handle NULL values' do
customer = User . create! (
2018-12-19 17:31:51 +00:00
email : 'issue_1316_test_user@zammad.org' ,
2018-07-04 10:07:25 +00:00
created_by_id : 1 ,
updated_by_id : 1 ,
)
2019-01-29 14:04:47 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'auto reply (condition: organization-is-not)' ,
condition : {
2018-07-04 10:07:25 +00:00
'ticket.organization_id' = > {
'operator' = > 'is not' ,
2018-12-19 17:31:51 +00:00
'value' = > Organization . first . id . to_s ,
2018-07-04 10:07:25 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
2018-07-04 10:07:25 +00:00
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'Lorem ipsum dolor' ,
2018-07-04 10:07:25 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
2018-07-04 10:07:25 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
active : true ,
2018-07-04 10:07:25 +00:00
created_by_id : 1 ,
updated_by_id : 1 ,
)
ticket = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : customer ,
2018-07-04 10:07:25 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
assert_nil ( customer . organization_id )
assert_equal ( 0 , ticket . reload . articles . count , 'ticket.articles verify' )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-07-04 10:07:25 +00:00
assert_equal ( 1 , ticket . reload . articles . count , 'ticket.articles verify' )
autoreply = ticket . articles . first
assert_equal ( 'Zammad <zammad@localhost>' , autoreply . from )
assert_equal ( customer . email , autoreply . to )
assert_equal ( " Thanks for your inquiry ( #{ ticket . title } )! " , autoreply . subject )
assert_equal ( 'Lorem ipsum dolor' , autoreply . body )
assert_equal ( 'text/html' , autoreply . content_type )
end
2018-05-14 16:01:15 +00:00
2019-01-29 14:04:47 +00:00
test 'trigger tags and auto responder when there is an article body contains matched values' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2018-12-19 17:31:51 +00:00
name : 'detect message body' ,
condition : {
2018-05-14 16:01:15 +00:00
'article.body' = > {
'operator' = > 'contains' ,
2018-12-19 17:31:51 +00:00
'value' = > 'some message' ,
2018-05-14 16:01:15 +00:00
} ,
} ,
2018-12-19 17:31:51 +00:00
perform : {
'ticket.tags' = > {
2018-05-14 16:01:15 +00:00
'operator' = > 'add' ,
2018-12-19 17:31:51 +00:00
'value' = > 'tag1, tag2' ,
2018-05-14 16:01:15 +00:00
} ,
'notification.email' = > {
2018-12-19 17:31:51 +00:00
'body' = > 'some lala' ,
2018-05-14 16:01:15 +00:00
'recipient' = > 'ticket_customer' ,
2018-12-19 17:31:51 +00:00
'subject' = > 'Thanks for your inquiry - loop check (#{ticket.title})!' ,
2018-05-14 16:01:15 +00:00
} ,
} ,
disable_notification : true ,
2018-12-19 17:31:51 +00:00
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
2018-05-14 16:01:15 +00:00
)
ticket1 = Ticket . create! (
2018-12-19 17:31:51 +00:00
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
2018-05-14 16:01:15 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
article1 = Ticket :: Article . create! (
2018-12-19 17:31:51 +00:00
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
2018-05-14 16:01:15 +00:00
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket1 . reload
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2018-05-14 16:01:15 +00:00
ticket1 . reload
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( %w[ tag1 tag2 ] , ticket1 . tag_list )
assert_match ( '- ' , article1 . from )
assert_match ( 'some_recipient@example.com' , article1 . to )
assert_match ( 'some subject' , article1 . subject )
assert_match ( " some message <b>note</b> \n new line " , article1 . body )
assert_equal ( 'text/plain' , article1 . content_type )
end
2019-01-29 14:04:47 +00:00
test 'trigger note and auto responder (correct order) when there is an article body contains matched values' do
2019-06-28 11:38:49 +00:00
Trigger . create! (
2019-01-29 14:04:47 +00:00
name : 'detect message body' ,
condition : {
'article.body' = > {
'operator' = > 'contains' ,
'value' = > 'some message' ,
} ,
} ,
perform : {
'article.note' = > {
2020-10-29 11:18:55 +00:00
'subject' = > 'some subject! #{ticket.id}' ,
'body' = > 'I can integrate with 3rd party services at https://my.saas/foo/#{ticket.id}' ,
2019-01-29 14:04:47 +00:00
'internal' = > 'true' ,
} ,
'notification.email' = > {
'body' = > 'some lala' ,
'recipient' = > 'ticket_customer' ,
'subject' = > 'Thanks for your inquiry - loop check (#{ticket.title})!' ,
} ,
} ,
disable_notification : true ,
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
)
ticket1 = Ticket . create! (
title : " some <b>title</b> \n äöüß " ,
group : Group . lookup ( name : 'Users' ) ,
customer : User . lookup ( email : 'nicole.braun@zammad.org' ) ,
updated_by_id : 1 ,
created_by_id : 1 ,
)
article1 = Ticket :: Article . create! (
ticket_id : ticket1 . id ,
from : 'some_sender@example.com' ,
to : 'some_recipient@example.com' ,
subject : 'some subject' ,
message_id : 'some@id' ,
body : " some message <b>note</b> \n new line " ,
internal : false ,
sender : Ticket :: Article :: Sender . find_by ( name : 'Agent' ) ,
type : Ticket :: Article :: Type . find_by ( name : 'note' ) ,
updated_by_id : 1 ,
created_by_id : 1 ,
)
ticket1 . reload
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 1 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
2021-05-20 06:59:02 +00:00
TransactionDispatcher . commit
2019-01-29 14:04:47 +00:00
ticket1 . reload
assert_equal ( 'some <b>title</b> äöüß' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 'Users' , ticket1 . group . name , 'ticket1.group verify' )
assert_equal ( 'new' , ticket1 . state . name , 'ticket1.state verify' )
assert_equal ( '2 normal' , ticket1 . priority . name , 'ticket1.priority verify' )
assert_equal ( 3 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( [ ] , ticket1 . tag_list )
assert_match ( '- ' , article1 . from )
assert_match ( 'some_recipient@example.com' , article1 . to )
assert_match ( 'some subject' , article1 . subject )
assert_match ( " some message <b>note</b> \n new line " , article1 . body )
assert_equal ( 'text/plain' , article1 . content_type )
article_note1 = ticket1 . articles [ 1 ]
assert_match ( '- ' , article_note1 . from )
assert_nil ( article_note1 . to )
2020-10-29 11:18:55 +00:00
assert_match ( " some subject! #{ ticket1 . id } " , article_note1 . subject )
assert_match ( " I can integrate with 3rd party services at <a href= \" https://my.saas/foo/ #{ ticket1 . id } \" rel= \" nofollow noreferrer noopener \" target= \" _blank \" >https://my.saas/foo/ #{ ticket1 . id } </a> " , article_note1 . body )
2019-01-29 14:04:47 +00:00
assert_equal ( 'text/html' , article_note1 . content_type )
assert_equal ( true , article_note1 . internal )
article_auto_responder1 = ticket1 . articles [ 2 ]
assert_match ( 'Zammad <zammad@localhost>' , article_auto_responder1 . from )
assert_match ( 'nicole.braun@zammad.org' , article_auto_responder1 . to )
assert_match ( 'Thanks for your inquiry - loop check (some <b>title</b> äöüß)!' , article_auto_responder1 . subject )
assert_match ( 'some lala' , article_auto_responder1 . body )
assert_equal ( 'text/html' , article_auto_responder1 . content_type )
end
test 'validates perform with article.note - should fail because of missing body' do
assert_raises ( Exception ) do
Trigger . create! (
name : 'some trigger' ,
condition : {
'article.body' = > {
'operator' = > 'contains' ,
'value' = > 'some message' ,
} ,
} ,
perform : {
'article.note' = > {
'subject' = > 'some subject!' ,
'internal' = > 'true' ,
} ,
} ,
disable_notification : true ,
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
)
end
end
test 'validates perform with notification.email - should fail because of missing recipient' do
assert_raises ( Exception ) do
Trigger . create! (
name : 'some trigger' ,
condition : {
'article.body' = > {
'operator' = > 'contains' ,
'value' = > 'some message' ,
} ,
} ,
perform : {
'notification.email' = > {
'body' = > 'some lala' ,
'recipient' = > '' ,
'subject' = > 'Thanks for your inquiry - loop check (#{ticket.title})!' ,
} ,
} ,
disable_notification : true ,
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
)
end
end
test 'validates perform with notification.sms - should fail because of missing recipient' do
assert_raises ( Exception ) do
Trigger . create! (
name : 'some trigger' ,
condition : {
'article.body' = > {
'operator' = > 'contains' ,
'value' = > 'some message' ,
} ,
} ,
perform : {
'notification.sms' = > {
'body' = > 'some lala' ,
'recipient' = > '' ,
} ,
} ,
disable_notification : true ,
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
)
end
end
2019-02-10 08:40:55 +00:00
#2399 - Attached images are broken on trigger reply with #{article.body_as_html}
test 'make sure auto reply using #{article.body_as_html} copies all articles image attachments as well' do
# make sure that this auto reply trigger only reacts to this particular test in order not to interfer with other auto reply tests
2019-06-28 11:38:49 +00:00
Trigger . create! (
2019-02-10 08:40:55 +00:00
name : 'auto reply with HTML quote' ,
condition : {
'ticket.action' = > {
'operator' = > 'is' ,
'value' = > 'create' ,
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
} ,
'ticket.title' = > {
'operator' = > 'contains' ,
'value' = > 'AW: OTRS / Anfrage OTRS Einführung/Präsentation [Ticket#11545]' ,
} ,
} ,
perform : {
'notification.email' = > {
'body' = > '#{article.body_as_html}' ,
'recipient' = > 'article_last_sender' ,
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
} ,
} ,
disable_notification : true ,
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
)
2020-02-18 19:51:31 +00:00
ticket1 , _article1 , _user , _mail = Channel :: EmailParser . new . process ( { } , File . read ( Rails . root . join ( 'test/data/mail/mail048.box' ) ) )
2019-02-10 08:40:55 +00:00
assert_equal ( 'AW: OTRS / Anfrage OTRS Einführung/Präsentation [Ticket#11545]' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( 2 , ticket1 . articles . first . attachments . count )
article1 = ticket1 . articles . last
assert_match ( 'Thanks for your inquiry (AW: OTRS / Anfrage OTRS Einführung/Präsentation [Ticket#11545])!' , article1 . subject )
assert_equal ( 1 , article1 . attachments . count )
assert_equal ( '50606' , article1 . attachments [ 0 ] . size )
assert_equal ( 'CPG-Reklamationsmitteilung bezügl.01234567895 an Voda-28.03.2017.jpg' , article1 . attachments [ 0 ] . filename )
end
#2399 - Attached images are broken on trigger reply with #{article.body_as_html}
test 'make sure auto reply using #{article.body_as_html} does not copy any non-image attachments' do
# make sure that this auto reply trigger only reacts to this particular test in order not to interfer with other auto reply tests
2019-06-28 11:38:49 +00:00
Trigger . create! (
2019-02-10 08:40:55 +00:00
name : 'auto reply with HTML quote' ,
condition : {
'ticket.action' = > {
'operator' = > 'is' ,
'value' = > 'create' ,
} ,
'ticket.state_id' = > {
'operator' = > 'is' ,
'value' = > Ticket :: State . lookup ( name : 'new' ) . id . to_s ,
} ,
'ticket.title' = > {
'operator' = > 'contains' ,
'value' = > 'Online-apotheke. Günstigster Preis. Ohne Rezepte' ,
} ,
} ,
perform : {
'notification.email' = > {
'body' = > '#{article.body_as_html}' ,
'recipient' = > 'article_last_sender' ,
'subject' = > 'Thanks for your inquiry (#{ticket.title})!' ,
} ,
} ,
disable_notification : true ,
active : true ,
created_by_id : 1 ,
updated_by_id : 1 ,
)
2020-02-18 19:51:31 +00:00
ticket1 , _article1 , _user , _mail = Channel :: EmailParser . new . process ( { } , File . read ( Rails . root . join ( 'test/data/mail/mail069.box' ) ) )
2019-02-10 08:40:55 +00:00
assert_equal ( 'Online-apotheke. Günstigster Preis. Ohne Rezepte' , ticket1 . title , 'ticket1.title verify' )
assert_equal ( 2 , ticket1 . articles . count , 'ticket1.articles verify' )
assert_equal ( 1 , ticket1 . articles . first . attachments . count )
article1 = ticket1 . articles . last
assert_match ( 'Thanks for your inquiry (Online-apotheke. Günstigster Preis. Ohne Rezepte)!' , article1 . subject )
assert_equal ( 0 , article1 . attachments . count )
end
2016-05-03 00:36:44 +00:00
end