2015-01-21 20:45:22 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class OnlineNotificationTest < ActiveSupport::TestCase
|
2015-04-01 11:14:46 +00:00
|
|
|
role = Role.lookup( :name => 'Agent' )
|
|
|
|
group = Group.lookup( :name => 'Users' )
|
2015-01-21 20:45:22 +00:00
|
|
|
agent_user1 = User.create_or_update(
|
|
|
|
:login => 'agent_online_notify1',
|
|
|
|
:firstname => 'Bob',
|
|
|
|
:lastname => 'Smith',
|
|
|
|
:email => 'agent_online_notify1@example.com',
|
|
|
|
:password => 'some_pass',
|
|
|
|
:active => true,
|
|
|
|
:role_ids => [role.id],
|
|
|
|
:group_ids => [group.id],
|
|
|
|
:updated_by_id => 1,
|
|
|
|
:created_by_id => 1
|
|
|
|
)
|
|
|
|
agent_user2 = User.create_or_update(
|
|
|
|
:login => 'agent_online_notify2',
|
|
|
|
:firstname => 'Bob',
|
|
|
|
:lastname => 'Smith',
|
|
|
|
:email => 'agent_online_notify2@example.com',
|
|
|
|
:password => 'some_pass',
|
|
|
|
:active => true,
|
|
|
|
:role_ids => [role.id],
|
|
|
|
:group_ids => [group.id],
|
|
|
|
:updated_by_id => 1,
|
|
|
|
:created_by_id => 1
|
|
|
|
)
|
|
|
|
customer_user = User.lookup( :login => 'nicole.braun@zammad.org' )
|
|
|
|
|
|
|
|
test 'ticket notifiaction' do
|
|
|
|
tests = [
|
|
|
|
|
|
|
|
# test 1
|
|
|
|
{
|
|
|
|
:create => {
|
|
|
|
:ticket => {
|
|
|
|
:group_id => Group.lookup( :name => 'Users' ).id,
|
|
|
|
:customer_id => customer_user.id,
|
|
|
|
:owner_id => User.lookup( :login => '-' ).id,
|
|
|
|
:title => 'Unit Test 1 (äöüß)!',
|
2015-04-01 14:33:24 +00:00
|
|
|
:state_id => Ticket::State.lookup( :name => 'closed' ).id,
|
2015-01-21 20:45:22 +00:00
|
|
|
:priority_id => Ticket::Priority.lookup( :name => '2 normal' ).id,
|
|
|
|
:updated_by_id => agent_user1.id,
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
},
|
|
|
|
:article => {
|
|
|
|
:updated_by_id => agent_user1.id,
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
:type_id => Ticket::Article::Type.lookup( :name => 'phone' ).id,
|
|
|
|
:sender_id => Ticket::Article::Sender.lookup( :name => 'Customer' ).id,
|
|
|
|
:from => 'Unit Test <unittest@example.com>',
|
|
|
|
:body => 'Unit Test 123',
|
|
|
|
:internal => false
|
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
:online_notification => {
|
|
|
|
:seen_only_exists => true,
|
|
|
|
},
|
2015-01-21 20:45:22 +00:00
|
|
|
},
|
|
|
|
:update => {
|
|
|
|
:ticket => {
|
|
|
|
:title => 'Unit Test 1 (äöüß) - update!',
|
|
|
|
:state_id => Ticket::State.lookup( :name => 'open' ).id,
|
|
|
|
:priority_id => Ticket::Priority.lookup( :name => '1 low' ).id,
|
|
|
|
:updated_by_id => customer_user.id,
|
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
:online_notification => {
|
|
|
|
:seen_only_exists => false,
|
|
|
|
},
|
2015-01-21 20:45:22 +00:00
|
|
|
},
|
|
|
|
:check => [
|
|
|
|
{
|
|
|
|
:type => 'create',
|
|
|
|
:object => 'Ticket',
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:type => 'update',
|
|
|
|
:object => 'Ticket',
|
|
|
|
:created_by_id => customer_user.id,
|
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
],
|
2015-01-21 20:45:22 +00:00
|
|
|
},
|
2015-04-01 11:47:10 +00:00
|
|
|
|
|
|
|
# test 2
|
|
|
|
{
|
|
|
|
:create => {
|
|
|
|
:ticket => {
|
|
|
|
:group_id => Group.lookup( :name => 'Users' ).id,
|
|
|
|
:customer_id => customer_user.id,
|
|
|
|
:owner_id => User.lookup( :login => '-' ).id,
|
|
|
|
:title => 'Unit Test 2 (äöüß)!',
|
|
|
|
:state_id => Ticket::State.lookup( :name => 'new' ).id,
|
|
|
|
:priority_id => Ticket::Priority.lookup( :name => '2 normal' ).id,
|
|
|
|
:updated_by_id => agent_user1.id,
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
},
|
|
|
|
:article => {
|
|
|
|
:updated_by_id => agent_user1.id,
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
:type_id => Ticket::Article::Type.lookup( :name => 'phone' ).id,
|
|
|
|
:sender_id => Ticket::Article::Sender.lookup( :name => 'Customer' ).id,
|
|
|
|
:from => 'Unit Test <unittest@example.com>',
|
|
|
|
:body => 'Unit Test 123',
|
|
|
|
:internal => false
|
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
:online_notification => {
|
|
|
|
:seen_only_exists => false,
|
|
|
|
},
|
2015-04-01 11:47:10 +00:00
|
|
|
},
|
|
|
|
:update => {
|
|
|
|
:ticket => {
|
|
|
|
:title => 'Unit Test 2 (äöüß) - update!',
|
2015-04-01 14:33:24 +00:00
|
|
|
:state_id => Ticket::State.lookup( :name => 'closed' ).id,
|
|
|
|
:priority_id => Ticket::Priority.lookup( :name => '1 low' ).id,
|
|
|
|
:updated_by_id => customer_user.id,
|
|
|
|
},
|
|
|
|
:online_notification => {
|
|
|
|
:seen_only_exists => true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
:check => [
|
|
|
|
{
|
|
|
|
:type => 'create',
|
|
|
|
:object => 'Ticket',
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:type => 'update',
|
|
|
|
:object => 'Ticket',
|
|
|
|
:created_by_id => customer_user.id,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
# test 3
|
|
|
|
{
|
|
|
|
:create => {
|
|
|
|
:ticket => {
|
|
|
|
:group_id => Group.lookup( :name => 'Users' ).id,
|
|
|
|
:customer_id => customer_user.id,
|
|
|
|
:owner_id => User.lookup( :login => '-' ).id,
|
|
|
|
:title => 'Unit Test 3 (äöüß)!',
|
|
|
|
:state_id => Ticket::State.lookup( :name => 'new' ).id,
|
|
|
|
:priority_id => Ticket::Priority.lookup( :name => '2 normal' ).id,
|
|
|
|
:updated_by_id => agent_user1.id,
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
},
|
|
|
|
:article => {
|
|
|
|
:updated_by_id => agent_user1.id,
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
:type_id => Ticket::Article::Type.lookup( :name => 'phone' ).id,
|
|
|
|
:sender_id => Ticket::Article::Sender.lookup( :name => 'Customer' ).id,
|
|
|
|
:from => 'Unit Test <unittest@example.com>',
|
|
|
|
:body => 'Unit Test 123',
|
|
|
|
:internal => false
|
|
|
|
},
|
|
|
|
:online_notification => {
|
|
|
|
:seen_only_exists => false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
:update => {
|
|
|
|
:ticket => {
|
|
|
|
:title => 'Unit Test 3 (äöüß) - update!',
|
2015-04-01 11:47:10 +00:00
|
|
|
:state_id => Ticket::State.lookup( :name => 'open' ).id,
|
|
|
|
:priority_id => Ticket::Priority.lookup( :name => '1 low' ).id,
|
|
|
|
:updated_by_id => customer_user.id,
|
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
:online_notification => {
|
|
|
|
:seen_only_exists => false,
|
|
|
|
},
|
2015-04-01 11:47:10 +00:00
|
|
|
},
|
|
|
|
:check => [
|
|
|
|
{
|
|
|
|
:type => 'create',
|
|
|
|
:object => 'Ticket',
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:type => 'update',
|
|
|
|
:object => 'Ticket',
|
|
|
|
:created_by_id => customer_user.id,
|
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
# test 4
|
|
|
|
{
|
|
|
|
:create => {
|
|
|
|
:ticket => {
|
|
|
|
:group_id => Group.lookup( :name => 'Users' ).id,
|
|
|
|
:customer_id => customer_user.id,
|
|
|
|
:owner_id => User.lookup( :login => '-' ).id,
|
|
|
|
:title => 'Unit Test 4 (äöüß)!',
|
|
|
|
:state_id => Ticket::State.lookup( :name => 'new' ).id,
|
|
|
|
:priority_id => Ticket::Priority.lookup( :name => '2 normal' ).id,
|
|
|
|
:updated_by_id => agent_user1.id,
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
},
|
|
|
|
:article => {
|
|
|
|
:updated_by_id => agent_user1.id,
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
:type_id => Ticket::Article::Type.lookup( :name => 'phone' ).id,
|
|
|
|
:sender_id => Ticket::Article::Sender.lookup( :name => 'Customer' ).id,
|
|
|
|
:from => 'Unit Test <unittest@example.com>',
|
|
|
|
:body => 'Unit Test 123',
|
|
|
|
:internal => false
|
|
|
|
},
|
|
|
|
:online_notification => {
|
|
|
|
:seen_only_exists => false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
:update => {
|
|
|
|
:ticket => {
|
|
|
|
:title => 'Unit Test 4 (äöüß) - update!',
|
|
|
|
:state_id => Ticket::State.lookup( :name => 'open' ).id,
|
|
|
|
:priority_id => Ticket::Priority.lookup( :name => '1 low' ).id,
|
|
|
|
:updated_by_id => customer_user.id,
|
|
|
|
},
|
|
|
|
:online_notification => {
|
|
|
|
:seen_only_exists => false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
:check => [
|
|
|
|
{
|
|
|
|
:type => 'create',
|
|
|
|
:object => 'Ticket',
|
|
|
|
:created_by_id => agent_user1.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:type => 'update',
|
|
|
|
:object => 'Ticket',
|
|
|
|
:created_by_id => customer_user.id,
|
|
|
|
},
|
|
|
|
],
|
2015-04-01 11:47:10 +00:00
|
|
|
},
|
2015-01-21 20:45:22 +00:00
|
|
|
]
|
|
|
|
tickets = []
|
|
|
|
tests.each { |test|
|
|
|
|
|
|
|
|
ticket = Ticket.create( test[:create][:ticket] )
|
|
|
|
test[:check][0][:o_id] = ticket.id
|
|
|
|
test[:check][1][:o_id] = ticket.id
|
|
|
|
|
|
|
|
test[:create][:article][:ticket_id] = ticket.id
|
|
|
|
article = Ticket::Article.create( test[:create][:article] )
|
|
|
|
|
|
|
|
assert_equal( ticket.class.to_s, 'Ticket' )
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
2015-04-01 14:33:24 +00:00
|
|
|
# check online notifications
|
|
|
|
if test[:create][:online_notification]
|
|
|
|
if test[:create][:online_notification][:seen_only_exists]
|
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id )
|
|
|
|
assert( notification_seen_only_exists_exists( notifications ), "not seen notifications for ticket available")
|
|
|
|
else
|
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id )
|
|
|
|
assert( !notification_seen_only_exists_exists( notifications ), "seen notifications for ticket available")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-21 20:45:22 +00:00
|
|
|
# update ticket
|
|
|
|
if test[:update][:ticket]
|
|
|
|
ticket.update_attributes( test[:update][:ticket] )
|
|
|
|
end
|
|
|
|
|
|
|
|
# execute ticket events
|
|
|
|
Observer::Ticket::Notification.transaction
|
|
|
|
#puts Delayed::Job.all.inspect
|
|
|
|
Delayed::Worker.new.work_off
|
|
|
|
|
|
|
|
# remember ticket
|
|
|
|
tickets.push ticket
|
|
|
|
|
|
|
|
# check online notifications
|
|
|
|
notification_check( OnlineNotification.list(agent_user2, 10), test[:check] )
|
2015-04-01 14:33:24 +00:00
|
|
|
|
|
|
|
# check online notifications
|
|
|
|
if test[:update][:online_notification]
|
|
|
|
if test[:update][:online_notification][:seen_only_exists]
|
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id )
|
|
|
|
assert( notification_seen_only_exists_exists( notifications ), "not seen notifications for ticket available")
|
|
|
|
else
|
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id )
|
|
|
|
assert( !notification_seen_only_exists_exists( notifications ), "seen notifications for ticket available")
|
|
|
|
end
|
|
|
|
end
|
2015-01-21 20:45:22 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 11:47:10 +00:00
|
|
|
# merge tickets - also remove notifications of merged tickets
|
2015-04-01 14:33:24 +00:00
|
|
|
tickets[2].merge_to(
|
|
|
|
:ticket_id => tickets[3].id,
|
2015-04-01 11:47:10 +00:00
|
|
|
:user_id => 1,
|
|
|
|
)
|
2015-04-01 14:33:24 +00:00
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', tickets[2].id )
|
|
|
|
assert( !notifications.empty?, "should have notifications")
|
|
|
|
assert( notification_seen_only_exists_exists(notifications), "still not seen notifications for merged ticket available")
|
2015-04-01 11:47:10 +00:00
|
|
|
|
2015-04-01 14:33:24 +00:00
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', tickets[3].id )
|
|
|
|
assert( !notifications.empty?, "should have notifications")
|
|
|
|
assert( !notification_seen_only_exists_exists(notifications), "no notifications for master ticket available")
|
2015-04-01 11:47:10 +00:00
|
|
|
|
2015-01-21 20:45:22 +00:00
|
|
|
# delete tickets
|
|
|
|
tickets.each { |ticket|
|
|
|
|
ticket_id = ticket.id
|
|
|
|
ticket.destroy
|
|
|
|
found = Ticket.where( :id => ticket_id ).first
|
|
|
|
assert( !found, "Ticket destroyed")
|
2015-04-01 11:14:46 +00:00
|
|
|
|
|
|
|
# check if notifications for ticket still exist
|
2015-04-01 11:47:10 +00:00
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', ticket_id )
|
2015-04-01 11:14:46 +00:00
|
|
|
assert( notifications.empty?, "still notifications for destroyed ticket available")
|
2015-01-21 20:45:22 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def notification_check( onine_notifications, checks )
|
|
|
|
checks.each { |check_item|
|
|
|
|
hit = false
|
|
|
|
onine_notifications.each {|onine_notification|
|
|
|
|
if onine_notification['o_id'] == check_item[:o_id]
|
|
|
|
if onine_notification['object'] == check_item[:object]
|
|
|
|
if onine_notification['type'] == check_item[:type]
|
|
|
|
if onine_notification['created_by_id'] == check_item[:created_by_id]
|
|
|
|
hit = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
2015-04-01 14:33:24 +00:00
|
|
|
#puts "--- #{onine_notifications.inspect}"
|
|
|
|
assert( hit, "online notification exists not #{ check_item.inspect }" )
|
2015-01-21 20:45:22 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-04-01 14:33:24 +00:00
|
|
|
def notification_seen_only_exists_exists( onine_notifications )
|
|
|
|
onine_notifications.each {|onine_notification|
|
|
|
|
return false if !onine_notification['seen']
|
|
|
|
}
|
|
|
|
true
|
|
|
|
end
|
2015-01-21 20:45:22 +00:00
|
|
|
end
|