2015-01-02 15:50:31 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class TicketNotificationTest < ActiveSupport::TestCase
|
|
|
|
|
2015-01-02 23:46:11 +00:00
|
|
|
# create agent1 & agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
groups = Group.where(name: 'Users')
|
|
|
|
roles = Role.where(name: 'Agent')
|
2015-01-02 23:46:11 +00:00
|
|
|
agent1 = User.create_or_update(
|
2015-04-27 13:42:53 +00:00
|
|
|
login: 'ticket-notification-agent1@example.com',
|
|
|
|
firstname: 'Notification',
|
|
|
|
lastname: 'Agent1',
|
|
|
|
email: 'ticket-notification-agent1@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
|
|
|
preferences: {
|
|
|
|
locale: 'de-de',
|
2015-01-04 12:52:14 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-01-02 23:46:11 +00:00
|
|
|
)
|
|
|
|
agent2 = User.create_or_update(
|
2015-04-27 13:42:53 +00:00
|
|
|
login: 'ticket-notification-agent2@example.com',
|
|
|
|
firstname: 'Notification',
|
|
|
|
lastname: 'Agent2',
|
|
|
|
email: 'ticket-notification-agent2@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
|
|
|
preferences: {
|
|
|
|
locale: 'en-ca',
|
2015-01-04 12:52:14 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-01-02 23:46:11 +00:00
|
|
|
)
|
|
|
|
Group.create_if_not_exists(
|
2015-04-27 13:42:53 +00:00
|
|
|
name: 'WithoutAccess',
|
|
|
|
note: 'Test for notification check.',
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
2015-01-02 23:46:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# create customer
|
2016-02-03 07:58:51 +00:00
|
|
|
roles = Role.where(name: 'Customer')
|
2015-01-02 23:46:11 +00:00
|
|
|
customer = User.create_or_update(
|
2015-04-27 13:42:53 +00:00
|
|
|
login: 'ticket-notification-customer@example.com',
|
|
|
|
firstname: 'Notification',
|
|
|
|
lastname: 'Customer',
|
|
|
|
email: 'ticket-notification-customer@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-01-02 23:46:11 +00:00
|
|
|
)
|
|
|
|
|
2016-02-03 07:58:51 +00:00
|
|
|
test 'ticket notification - to all agents / to explicit agents' do
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket1 = Ticket.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
title: 'some notification test 1',
|
2016-02-03 07:58:51 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: agent1,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
|
|
|
)
|
|
|
|
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',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
|
|
|
)
|
|
|
|
assert(ticket1)
|
|
|
|
|
|
|
|
# execute ticket events
|
2016-02-04 12:26:04 +00:00
|
|
|
Rails.configuration.webserver_is_active = nil
|
2016-02-03 07:58:51 +00:00
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(1, notification_check(ticket1, agent1), ticket1.id)
|
|
|
|
assert_equal(1, notification_check(ticket1, agent2), ticket1.id)
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket1 = Ticket.create(
|
|
|
|
title: 'some notification test 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: agent1,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
|
|
|
)
|
|
|
|
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',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
|
|
|
)
|
|
|
|
assert(ticket1)
|
|
|
|
|
|
|
|
# execute ticket events
|
2016-02-04 12:26:04 +00:00
|
|
|
Rails.configuration.webserver_is_active = true
|
2016-02-03 07:58:51 +00:00
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(0, notification_check(ticket1, agent1), ticket1.id)
|
|
|
|
assert_equal(1, notification_check(ticket1, agent2), ticket1.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'ticket notification - simple' do
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket1 = Ticket.create(
|
|
|
|
title: 'some notification test 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-04-27 13:42:53 +00:00
|
|
|
customer: customer,
|
2016-02-03 07:58:51 +00:00
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
2015-01-02 15:50:31 +00:00
|
|
|
)
|
2015-04-27 17:42:59 +00:00
|
|
|
Ticket::Article.create(
|
2015-04-27 13:42:53 +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',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
2015-01-02 15:50:31 +00:00
|
|
|
)
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( ticket1, 'ticket created - ticket notification simple' )
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# execute ticket events
|
2016-02-04 12:26:04 +00:00
|
|
|
Rails.configuration.webserver_is_active = true
|
2015-01-02 15:50:31 +00:00
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(1, notification_check(ticket1, agent1), ticket1.id)
|
|
|
|
assert_equal(1, notification_check(ticket1, agent2), ticket1.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket1.title = "#{ticket1.title} - #2"
|
2016-02-03 07:58:51 +00:00
|
|
|
ticket1.priority = Ticket::Priority.lookup(name: '3 high')
|
2015-01-02 15:50:31 +00:00
|
|
|
ticket1.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(2, notification_check(ticket1, agent1), ticket1.id)
|
|
|
|
assert_equal(2, notification_check(ticket1, agent2), ticket1.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# add article to ticket
|
2015-04-27 17:42:59 +00:00
|
|
|
Ticket::Article.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some person',
|
|
|
|
subject: 'some note',
|
|
|
|
body: 'some message',
|
|
|
|
internal: true,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Agent').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'note').first,
|
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2015-01-02 15:50:31 +00:00
|
|
|
)
|
|
|
|
|
2015-01-09 19:44:04 +00:00
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
2015-01-02 15:50:31 +00:00
|
|
|
|
2015-01-09 19:44:04 +00:00
|
|
|
# verify notifications to not to agent1 but to agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(2, notification_check(ticket1, agent1), ticket1.id)
|
|
|
|
assert_equal(3, notification_check(ticket1, agent2), ticket1.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
2015-01-09 19:44:04 +00:00
|
|
|
# update ticket by user
|
|
|
|
ticket1.owner_id = agent1.id
|
|
|
|
ticket1.updated_by_id = agent1.id
|
|
|
|
ticket1.save
|
2015-04-27 17:42:59 +00:00
|
|
|
Ticket::Article.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some person',
|
|
|
|
subject: 'some note',
|
|
|
|
body: 'some message',
|
|
|
|
internal: true,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Agent').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'note').first,
|
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2015-01-09 19:44:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to not to agent1 but to agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(2, notification_check(ticket1, agent1), ticket1.id)
|
|
|
|
assert_equal(3, notification_check(ticket1, agent2), ticket1.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# create ticket with agent1 as owner
|
|
|
|
ticket2 = Ticket.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
title: 'some notification test 2',
|
2016-02-03 07:58:51 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-04-27 13:42:53 +00:00
|
|
|
customer_id: 2,
|
|
|
|
owner_id: agent1.id,
|
2016-02-03 07:58:51 +00:00
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2015-01-02 15:50:31 +00:00
|
|
|
)
|
2015-04-27 17:42:59 +00:00
|
|
|
Ticket::Article.create(
|
2015-04-27 13:42:53 +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',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Agent').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'phone').first,
|
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2015-01-02 15:50:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(ticket2, 'ticket created')
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# verify notifications to no one
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(0, notification_check(ticket2, agent1), ticket2.id)
|
|
|
|
assert_equal(0, notification_check(ticket2, agent2), ticket2.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# update ticket
|
|
|
|
ticket2.title = "#{ticket2.title} - #2"
|
|
|
|
ticket2.updated_by_id = agent1.id
|
2016-02-03 07:58:51 +00:00
|
|
|
ticket2.priority = Ticket::Priority.lookup(name: '3 high')
|
2015-01-02 15:50:31 +00:00
|
|
|
ticket2.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to no one
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(0, notification_check(ticket2, agent1), ticket2.id)
|
|
|
|
assert_equal(0, notification_check(ticket2, agent2), ticket2.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# update ticket
|
|
|
|
ticket2.title = "#{ticket2.title} - #3"
|
|
|
|
ticket2.updated_by_id = agent2.id
|
2016-02-03 07:58:51 +00:00
|
|
|
ticket2.priority = Ticket::Priority.lookup(name: '2 normal')
|
2015-01-02 15:50:31 +00:00
|
|
|
ticket2.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 and not to agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(1, notification_check(ticket2, agent1), ticket2.id)
|
|
|
|
assert_equal(0, notification_check(ticket2, agent2), ticket2.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# create ticket with agent2 and agent1 as owner
|
|
|
|
ticket3 = Ticket.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
title: 'some notification test 3',
|
2016-02-03 07:58:51 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-04-27 13:42:53 +00:00
|
|
|
customer_id: 2,
|
|
|
|
owner_id: agent1.id,
|
2016-02-03 07:58:51 +00:00
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: agent2.id,
|
|
|
|
created_by_id: agent2.id,
|
2015-01-02 15:50:31 +00:00
|
|
|
)
|
|
|
|
article_inbound = Ticket::Article.create(
|
2015-04-27 13:42:53 +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',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Agent').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'phone').first,
|
|
|
|
updated_by_id: agent2.id,
|
|
|
|
created_by_id: agent2.id,
|
2015-01-02 15:50:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(ticket3, 'ticket created')
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# verify notifications to agent1 and not to agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(1, notification_check(ticket3, agent1), ticket3.id)
|
|
|
|
assert_equal(0, notification_check(ticket3, agent2), ticket3.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# update ticket
|
|
|
|
ticket3.title = "#{ticket3.title} - #2"
|
|
|
|
ticket3.updated_by_id = agent1.id
|
2016-02-03 07:58:51 +00:00
|
|
|
ticket3.priority = Ticket::Priority.lookup(name: '3 high')
|
2015-01-02 15:50:31 +00:00
|
|
|
ticket3.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to no one
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(1, notification_check(ticket3, agent1), ticket3.id)
|
|
|
|
assert_equal(0, notification_check(ticket3, agent2), ticket3.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
# update ticket
|
|
|
|
ticket3.title = "#{ticket3.title} - #3"
|
|
|
|
ticket3.updated_by_id = agent2.id
|
2016-02-03 07:58:51 +00:00
|
|
|
ticket3.priority = Ticket::Priority.lookup(name: '2 normal')
|
2015-01-02 15:50:31 +00:00
|
|
|
ticket3.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 and not to agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(2, notification_check(ticket3, agent1), ticket3.id)
|
|
|
|
assert_equal(0, notification_check(ticket3, agent2), ticket3.id)
|
2015-01-02 15:50:31 +00:00
|
|
|
|
2015-02-10 12:37:47 +00:00
|
|
|
# update article / not notification should be sent
|
|
|
|
article_inbound.internal = true
|
|
|
|
article_inbound.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications not to agent1 and not to agent2
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal(2, notification_check(ticket3, agent1), ticket3.id)
|
|
|
|
assert_equal(0, notification_check(ticket3, agent2), ticket3.id)
|
2015-02-10 12:37:47 +00:00
|
|
|
|
2015-01-02 15:50:31 +00:00
|
|
|
delete = ticket1.destroy
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(delete, 'ticket1 destroy')
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
delete = ticket2.destroy
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(delete, 'ticket2 destroy')
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
delete = ticket3.destroy
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(delete, 'ticket3 destroy')
|
2015-01-02 15:50:31 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-02-07 13:00:29 +00:00
|
|
|
test 'ticket notification - z preferences tests' do
|
|
|
|
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = false
|
|
|
|
agent1.save
|
|
|
|
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
|
|
|
agent2.save
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket1 = Ticket.create(
|
|
|
|
title: 'some notification test - z preferences tests 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: customer,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
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',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Rails.configuration.webserver_is_active = false
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(0, notification_check(ticket1, agent1), ticket1.id)
|
|
|
|
assert_equal(1, notification_check(ticket1, agent2), ticket1.id)
|
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket1.title = "#{ticket1.title} - #2"
|
|
|
|
ticket1.priority = Ticket::Priority.lookup(name: '3 high')
|
|
|
|
ticket1.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(0, notification_check(ticket1, agent1), ticket1.id)
|
|
|
|
assert_equal(2, notification_check(ticket1, agent2), ticket1.id)
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket2 = Ticket.create(
|
|
|
|
title: 'some notification test - z preferences tests 2',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: customer,
|
|
|
|
owner: agent1,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
Ticket::Article.create(
|
|
|
|
ticket_id: ticket2.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(1, notification_check(ticket2, agent1), ticket2.id)
|
|
|
|
assert_equal(1, notification_check(ticket2, agent2), ticket2.id)
|
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket2.title = "#{ticket2.title} - #2"
|
|
|
|
ticket2.priority = Ticket::Priority.lookup(name: '3 high')
|
|
|
|
ticket2.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(2, notification_check(ticket2, agent1), ticket2.id)
|
|
|
|
assert_equal(2, notification_check(ticket2, agent2), ticket2.id)
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket3 = Ticket.create(
|
|
|
|
title: 'some notification test - z preferences tests 3',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: customer,
|
|
|
|
owner: agent2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
Ticket::Article.create(
|
|
|
|
ticket_id: ticket3.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(0, notification_check(ticket3, agent1), ticket3.id)
|
|
|
|
assert_equal(1, notification_check(ticket3, agent2), ticket3.id)
|
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket3.title = "#{ticket3.title} - #2"
|
|
|
|
ticket3.priority = Ticket::Priority.lookup(name: '3 high')
|
|
|
|
ticket3.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(0, notification_check(ticket3, agent1), ticket3.id)
|
|
|
|
assert_equal(2, notification_check(ticket3, agent2), ticket3.id)
|
|
|
|
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
|
|
|
agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'Users').id.to_s]
|
|
|
|
agent1.save
|
|
|
|
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
|
|
|
agent1.preferences['notification_config']['group_ids'] = ['-']
|
|
|
|
agent2.save
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket4 = Ticket.create(
|
|
|
|
title: 'some notification test - z preferences tests 4',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: customer,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
Ticket::Article.create(
|
|
|
|
ticket_id: ticket4.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Rails.configuration.webserver_is_active = false
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(1, notification_check(ticket4, agent1), ticket4.id)
|
|
|
|
assert_equal(1, notification_check(ticket4, agent2), ticket4.id)
|
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket4.title = "#{ticket4.title} - #2"
|
|
|
|
ticket4.priority = Ticket::Priority.lookup(name: '3 high')
|
|
|
|
ticket4.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(2, notification_check(ticket4, agent1), ticket4.id)
|
|
|
|
assert_equal(2, notification_check(ticket4, agent2), ticket4.id)
|
|
|
|
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
|
|
|
agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'Users').id.to_s]
|
|
|
|
agent1.save
|
|
|
|
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
|
|
|
agent2.preferences['notification_config']['group_ids'] = [99]
|
|
|
|
agent2.save
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket5 = Ticket.create(
|
|
|
|
title: 'some notification test - z preferences tests 5',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: customer,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
Ticket::Article.create(
|
|
|
|
ticket_id: ticket5.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Rails.configuration.webserver_is_active = false
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(1, notification_check(ticket5, agent1), ticket5.id)
|
|
|
|
assert_equal(0, notification_check(ticket5, agent2), ticket5.id)
|
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket5.title = "#{ticket5.title} - #2"
|
|
|
|
ticket5.priority = Ticket::Priority.lookup(name: '3 high')
|
|
|
|
ticket5.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(2, notification_check(ticket5, agent1), ticket5.id)
|
|
|
|
assert_equal(0, notification_check(ticket5, agent2), ticket5.id)
|
|
|
|
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
|
|
|
agent1.preferences['notification_config']['group_ids'] = [999]
|
|
|
|
agent1.save
|
|
|
|
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
|
|
|
agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
|
|
|
agent2.preferences['notification_config']['group_ids'] = [999]
|
|
|
|
agent2.save
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket6 = Ticket.create(
|
|
|
|
title: 'some notification test - z preferences tests 6',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: customer,
|
|
|
|
owner: agent1,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
Ticket::Article.create(
|
|
|
|
ticket_id: ticket6.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Rails.configuration.webserver_is_active = false
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(1, notification_check(ticket6, agent1), ticket6.id)
|
|
|
|
assert_equal(0, notification_check(ticket6, agent2), ticket6.id)
|
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket6.title = "#{ticket6.title} - #2"
|
|
|
|
ticket6.priority = Ticket::Priority.lookup(name: '3 high')
|
|
|
|
ticket6.save
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# verify notifications to agent1 + agent2
|
|
|
|
assert_equal(2, notification_check(ticket6, agent1), ticket6.id)
|
|
|
|
assert_equal(0, notification_check(ticket6, agent2), ticket6.id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-01-02 23:46:11 +00:00
|
|
|
test 'ticket notification events' do
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket1 = Ticket.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
title: 'some notification event test 1',
|
2016-02-03 07:58:51 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-04-27 13:42:53 +00:00
|
|
|
customer: customer,
|
2016-02-03 07:58:51 +00:00
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
2015-01-02 23:46:11 +00:00
|
|
|
)
|
2015-04-27 17:42:59 +00:00
|
|
|
Ticket::Article.create(
|
2015-04-27 13:42:53 +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',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
2015-01-02 23:46:11 +00:00
|
|
|
)
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(ticket1, 'ticket created')
|
2015-01-02 23:46:11 +00:00
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket1.title = "#{ticket1.title} - #2"
|
2016-02-03 07:58:51 +00:00
|
|
|
ticket1.priority = Ticket::Priority.lookup(name: '3 high')
|
2015-01-02 23:46:11 +00:00
|
|
|
ticket1.save
|
|
|
|
|
2015-04-27 17:42:59 +00:00
|
|
|
list = EventBuffer.list
|
|
|
|
list_objects = Observer::Ticket::Notification.get_uniq_changes(list)
|
2015-01-02 23:46:11 +00:00
|
|
|
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal('some notification event test 1', list_objects[ticket1.id][:changes]['title'][0])
|
|
|
|
assert_equal('some notification event test 1 - #2', list_objects[ticket1.id][:changes]['title'][1])
|
|
|
|
assert_not(list_objects[ticket1.id][:changes]['priority'])
|
|
|
|
assert_equal(2, list_objects[ticket1.id][:changes]['priority_id'][0])
|
|
|
|
assert_equal(3, list_objects[ticket1.id][:changes]['priority_id'][1])
|
2015-01-02 23:46:11 +00:00
|
|
|
|
|
|
|
# update ticket attributes
|
|
|
|
ticket1.title = "#{ticket1.title} - #3"
|
2016-02-03 07:58:51 +00:00
|
|
|
ticket1.priority = Ticket::Priority.lookup(name: '1 low')
|
2015-01-02 23:46:11 +00:00
|
|
|
ticket1.save
|
|
|
|
|
2015-04-27 17:42:59 +00:00
|
|
|
list = EventBuffer.list
|
|
|
|
list_objects = Observer::Ticket::Notification.get_uniq_changes(list)
|
2015-01-02 23:46:11 +00:00
|
|
|
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_equal('some notification event test 1', list_objects[ticket1.id][:changes]['title'][0])
|
|
|
|
assert_equal('some notification event test 1 - #2 - #3', list_objects[ticket1.id][:changes]['title'][1])
|
|
|
|
assert_not(list_objects[ticket1.id][:changes]['priority'])
|
|
|
|
assert_equal(2, list_objects[ticket1.id][:changes]['priority_id'][0])
|
|
|
|
assert_equal(1, list_objects[ticket1.id][:changes]['priority_id'][1])
|
2015-01-04 12:52:14 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'ticket notification template' do
|
|
|
|
|
|
|
|
# create ticket in group
|
|
|
|
ticket1 = Ticket.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
title: 'some notification template test 1 Bobs\'s resumé',
|
2016-02-03 07:58:51 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-04-27 13:42:53 +00:00
|
|
|
customer: customer,
|
2016-02-03 07:58:51 +00:00
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
2015-01-04 12:52:14 +00:00
|
|
|
)
|
|
|
|
article = Ticket::Article.create(
|
2015-04-27 13:42:53 +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\nnewline1 abc\nnewline2",
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
|
|
|
updated_by_id: customer.id,
|
|
|
|
created_by_id: customer.id,
|
2015-01-04 12:52:14 +00:00
|
|
|
)
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(ticket1, 'ticket created - ticket notification template')
|
2015-01-04 12:52:14 +00:00
|
|
|
|
|
|
|
bg = Observer::Ticket::Notification::BackgroundJob.new(
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
article_id: article.id,
|
|
|
|
type: 'update',
|
|
|
|
changes: {
|
2015-02-10 22:32:56 +00:00
|
|
|
'priority_id' => [1, 2],
|
2015-04-27 17:42:59 +00:00
|
|
|
'pending_time' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
|
2015-01-04 12:52:14 +00:00
|
|
|
},
|
|
|
|
)
|
2015-01-04 15:39:57 +00:00
|
|
|
|
|
|
|
# check changed attributes
|
2015-04-27 14:53:29 +00:00
|
|
|
human_changes = bg.human_changes(agent1, ticket1)
|
2015-01-04 15:39:57 +00:00
|
|
|
assert( human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute' )
|
2015-02-10 14:59:21 +00:00
|
|
|
assert( human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute' )
|
2015-01-04 16:03:43 +00:00
|
|
|
assert_equal( 'i18n(1 low)', human_changes['Priority'][0] )
|
|
|
|
assert_equal( 'i18n(2 normal)', human_changes['Priority'][1] )
|
2015-02-10 14:59:21 +00:00
|
|
|
assert_equal( 'i18n()', human_changes['Pending till'][0] )
|
|
|
|
assert_equal( 'i18n(2015-01-11 23:33:47 UTC)', human_changes['Pending till'][1] )
|
2015-01-04 12:52:14 +00:00
|
|
|
assert_not( human_changes['priority_id'] )
|
2015-02-10 22:32:56 +00:00
|
|
|
assert_not( human_changes['pending_time'] )
|
2015-02-10 14:59:21 +00:00
|
|
|
assert_not( human_changes['pending_till'] )
|
2015-01-04 12:52:14 +00:00
|
|
|
|
2015-01-04 15:39:57 +00:00
|
|
|
# en template
|
2015-01-04 16:03:43 +00:00
|
|
|
template = bg.template_update(agent2, ticket1, article, human_changes)
|
2015-01-04 12:52:14 +00:00
|
|
|
assert( template[:subject] )
|
|
|
|
assert( template[:body] )
|
2015-01-04 15:39:57 +00:00
|
|
|
assert_match( /Priority/, template[:body] )
|
|
|
|
assert_match( /1 low/, template[:body] )
|
2015-01-04 16:03:43 +00:00
|
|
|
assert_match( /2 normal/, template[:body] )
|
2015-02-10 14:59:21 +00:00
|
|
|
assert_match( /Pending till/, template[:body] )
|
|
|
|
assert_match( /2015-01-11 23:33:47 UTC/, template[:body] )
|
2015-01-10 08:49:12 +00:00
|
|
|
assert_match( /updated/i, template[:subject] )
|
2015-01-04 12:52:14 +00:00
|
|
|
|
2015-01-04 15:39:57 +00:00
|
|
|
# en notification
|
2015-01-22 07:17:06 +00:00
|
|
|
subject = NotificationFactory.build(
|
2015-04-27 13:42:53 +00:00
|
|
|
locale: agent2.preferences[:locale],
|
|
|
|
string: template[:subject],
|
|
|
|
objects: {
|
|
|
|
ticket: ticket1,
|
|
|
|
article: article,
|
|
|
|
recipient: agent2,
|
2015-01-22 07:17:06 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
assert_match( /Bobs's resumé/, subject )
|
2015-01-04 15:39:57 +00:00
|
|
|
body = NotificationFactory.build(
|
2015-04-27 13:42:53 +00:00
|
|
|
locale: agent2.preferences[:locale],
|
|
|
|
string: template[:body],
|
|
|
|
objects: {
|
|
|
|
ticket: ticket1,
|
|
|
|
article: article,
|
|
|
|
recipient: agent2,
|
2015-01-04 15:39:57 +00:00
|
|
|
}
|
|
|
|
)
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_match(/Priority/, body)
|
|
|
|
assert_match(/1 low/, body)
|
|
|
|
assert_match(/2 normal/, body)
|
|
|
|
assert_match(/Pending till/, body)
|
|
|
|
assert_match(/2015-01-11 23:33:47 UTC/, body)
|
|
|
|
assert_match(/update/, body)
|
|
|
|
assert_no_match(/pending_till/, body)
|
|
|
|
assert_no_match(/i18n/, body)
|
2015-01-04 15:39:57 +00:00
|
|
|
|
|
|
|
# de template
|
2015-01-04 16:03:43 +00:00
|
|
|
template = bg.template_update(agent1, ticket1, article, human_changes)
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(template[:subject])
|
|
|
|
assert(template[:body])
|
|
|
|
assert_match(/Priority/, template[:body])
|
|
|
|
assert_match(/1 low/, template[:body])
|
|
|
|
assert_match(/2 normal/, template[:body])
|
|
|
|
assert_match(/Pending till/, template[:body])
|
|
|
|
assert_match(/2015-01-11 23:33:47 UTC/, template[:body])
|
|
|
|
assert_match(/aktualis/, template[:subject])
|
2015-01-04 15:39:57 +00:00
|
|
|
|
|
|
|
# de notification
|
2015-01-22 07:17:06 +00:00
|
|
|
subject = NotificationFactory.build(
|
2015-04-27 13:42:53 +00:00
|
|
|
locale: agent1.preferences[:locale],
|
|
|
|
string: template[:subject],
|
|
|
|
objects: {
|
|
|
|
ticket: ticket1,
|
|
|
|
article: article,
|
|
|
|
recipient: agent2,
|
2015-01-22 07:17:06 +00:00
|
|
|
}
|
|
|
|
)
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_match(/Bobs's resumé/, subject)
|
2015-01-04 15:39:57 +00:00
|
|
|
body = NotificationFactory.build(
|
2015-04-27 13:42:53 +00:00
|
|
|
locale: agent1.preferences[:locale],
|
|
|
|
string: template[:body],
|
|
|
|
objects: {
|
|
|
|
ticket: ticket1,
|
|
|
|
article: article,
|
|
|
|
recipient: agent1,
|
2015-01-04 15:39:57 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2016-02-03 07:58:51 +00:00
|
|
|
assert_match(/Priorität/, body)
|
|
|
|
assert_match(/1 niedrig/, body)
|
|
|
|
assert_match(/2 normal/, body)
|
|
|
|
assert_match(/Warten/, body)
|
|
|
|
assert_match(/2015-01-11 23:33:47 UTC/, body)
|
|
|
|
assert_match(/aktualis/, body)
|
|
|
|
assert_no_match(/pending_till/, body)
|
|
|
|
assert_no_match(/i18n/, body)
|
2015-01-02 23:46:11 +00:00
|
|
|
|
2015-02-10 12:37:47 +00:00
|
|
|
bg = Observer::Ticket::Notification::BackgroundJob.new(
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
article_id: article.id,
|
|
|
|
type: 'update',
|
|
|
|
changes: {
|
|
|
|
title: ['some notification template test 1', 'some notification template test 1 #2'],
|
|
|
|
priority_id: [2, 3],
|
2015-02-10 12:37:47 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2015-05-05 05:55:06 +00:00
|
|
|
#puts "hc #{human_changes.inspect}"
|
2015-02-10 22:32:56 +00:00
|
|
|
# check changed attributes
|
2015-04-27 14:53:29 +00:00
|
|
|
human_changes = bg.human_changes(agent1, ticket1)
|
2016-02-03 07:58:51 +00:00
|
|
|
assert(human_changes['Title'], 'Check if attributes translated based on ObjectManager::Attribute')
|
|
|
|
assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
|
|
|
|
assert_equal('i18n(2 normal)', human_changes['Priority'][0])
|
|
|
|
assert_equal('i18n(3 high)', human_changes['Priority'][1])
|
|
|
|
assert_equal('some notification template test 1', human_changes['Title'][0])
|
|
|
|
assert_equal('some notification template test 1 #2', human_changes['Title'][1])
|
|
|
|
assert_not(human_changes['priority_id'])
|
|
|
|
assert_not(human_changes['pending_time'])
|
|
|
|
assert_not(human_changes['pending_till'])
|
2015-02-10 12:37:47 +00:00
|
|
|
|
2015-04-27 14:53:29 +00:00
|
|
|
human_changes = bg.human_changes(agent2, ticket1)
|
2015-05-05 05:55:06 +00:00
|
|
|
#puts "hc2 #{human_changes.inspect}"
|
2015-02-10 12:37:47 +00:00
|
|
|
|
|
|
|
template = bg.template_update(agent1, ticket1, article, human_changes)
|
2015-05-05 05:55:06 +00:00
|
|
|
#puts "t1 #{template.inspect}"
|
2015-02-10 12:37:47 +00:00
|
|
|
|
|
|
|
template = bg.template_update(agent2, ticket1, article, human_changes)
|
2015-05-05 05:55:06 +00:00
|
|
|
#puts "t2 #{template.inspect}"
|
2015-02-10 12:37:47 +00:00
|
|
|
|
2015-01-02 23:46:11 +00:00
|
|
|
end
|
|
|
|
|
2015-01-02 15:50:31 +00:00
|
|
|
def notification_check(ticket, recipient)
|
|
|
|
result = ticket.history_get()
|
|
|
|
count = 0
|
|
|
|
result.each {|item|
|
|
|
|
next if item['type'] != 'notification'
|
|
|
|
next if item['object'] != 'Ticket'
|
|
|
|
next if item['value_to'] !~ /#{recipient.email}/i
|
|
|
|
count += 1
|
|
|
|
}
|
|
|
|
count
|
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|