2015-01-21 20:45:22 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class OnlineNotificationTest < ActiveSupport::TestCase
|
2016-01-19 22:30:23 +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(
|
2015-04-27 13:42:53 +00:00
|
|
|
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
|
2015-01-21 20:45:22 +00:00
|
|
|
)
|
|
|
|
agent_user2 = User.create_or_update(
|
2015-04-27 13:42:53 +00:00
|
|
|
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
|
2015-01-21 20:45:22 +00:00
|
|
|
)
|
2016-01-19 22:30:23 +00:00
|
|
|
customer_user = User.lookup(email: 'nicole.braun@zammad.org')
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2015-09-03 09:14:09 +00:00
|
|
|
test 'ticket notification' do
|
2015-01-21 20:45:22 +00:00
|
|
|
tests = [
|
|
|
|
|
|
|
|
# test 1
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
create: {
|
|
|
|
ticket: {
|
|
|
|
group_id: Group.lookup( name: 'Users' ).id,
|
|
|
|
customer_id: customer_user.id,
|
|
|
|
owner_id: User.lookup( login: '-' ).id,
|
|
|
|
title: 'Unit Test 1 (äöüß)!',
|
|
|
|
state_id: Ticket::State.lookup( name: 'closed' ).id,
|
|
|
|
priority_id: Ticket::Priority.lookup( name: '2 normal' ).id,
|
|
|
|
updated_by_id: agent_user1.id,
|
|
|
|
created_by_id: agent_user1.id,
|
2015-01-21 20:45:22 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
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-01-21 20:45:22 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
online_notification: {
|
|
|
|
seen_only_exists: true,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
2015-01-21 20:45:22 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +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-01-21 20:45:22 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
online_notification: {
|
|
|
|
seen_only_exists: false,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
2015-01-21 20:45:22 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
check: [
|
2015-04-27 15:11:04 +00:00
|
|
|
{
|
2015-04-27 15:21:17 +00:00
|
|
|
type: 'create',
|
2015-04-27 19:24:14 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
created_by_id: agent_user1.id,
|
2015-04-27 15:21:17 +00:00
|
|
|
},
|
2015-04-27 19:24:14 +00:00
|
|
|
{
|
|
|
|
type: 'update',
|
2015-04-27 13:42:53 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
created_by_id: customer_user.id,
|
2015-04-27 19:24:14 +00:00
|
|
|
},
|
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
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
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,
|
2015-04-01 11:47:10 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
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 11:47:10 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
online_notification: {
|
|
|
|
seen_only_exists: false,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
2015-04-01 11:47:10 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
update: {
|
|
|
|
ticket: {
|
|
|
|
title: 'Unit Test 2 (äöüß) - update!',
|
|
|
|
state_id: Ticket::State.lookup( name: 'closed' ).id,
|
|
|
|
priority_id: Ticket::Priority.lookup( name: '1 low' ).id,
|
|
|
|
updated_by_id: customer_user.id,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
online_notification: {
|
|
|
|
seen_only_exists: true,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
check: [
|
2015-04-27 15:11:04 +00:00
|
|
|
{
|
2015-04-27 15:21:17 +00:00
|
|
|
type: 'create',
|
2015-04-27 19:24:14 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
created_by_id: agent_user1.id,
|
2015-04-27 15:21:17 +00:00
|
|
|
},
|
2015-04-27 19:24:14 +00:00
|
|
|
{
|
|
|
|
type: 'update',
|
2015-04-27 13:42:53 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
created_by_id: customer_user.id,
|
2015-04-27 19:24:14 +00:00
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
# test 3
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
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,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
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
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
online_notification: {
|
|
|
|
seen_only_exists: false,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
update: {
|
|
|
|
ticket: {
|
|
|
|
title: 'Unit Test 3 (äöüß) - 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 11:47:10 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
online_notification: {
|
|
|
|
seen_only_exists: false,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
2015-04-01 11:47:10 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
check: [
|
2015-04-27 15:11:04 +00:00
|
|
|
{
|
2015-04-27 15:21:17 +00:00
|
|
|
type: 'create',
|
2015-04-27 19:24:14 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
created_by_id: agent_user1.id,
|
2015-04-27 15:21:17 +00:00
|
|
|
},
|
2015-04-27 19:24:14 +00:00
|
|
|
{
|
|
|
|
type: 'update',
|
2015-04-27 13:42:53 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
created_by_id: customer_user.id,
|
2015-04-27 19:24:14 +00:00
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
# test 4
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
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,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
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
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
online_notification: {
|
|
|
|
seen_only_exists: false,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
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,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
online_notification: {
|
|
|
|
seen_only_exists: false,
|
2015-04-01 14:33:24 +00:00
|
|
|
},
|
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
check: [
|
2015-04-27 15:11:04 +00:00
|
|
|
{
|
2015-04-27 15:21:17 +00:00
|
|
|
type: 'create',
|
2015-04-27 19:24:14 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
created_by_id: agent_user1.id,
|
2015-04-27 15:21:17 +00:00
|
|
|
},
|
2015-04-27 19:24:14 +00:00
|
|
|
{
|
|
|
|
type: 'update',
|
2015-04-27 13:42:53 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
created_by_id: customer_user.id,
|
2015-04-27 19:24:14 +00:00
|
|
|
},
|
2015-04-01 14:33:24 +00:00
|
|
|
],
|
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 )
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( notification_seen_only_exists_exists( notifications ), 'not seen notifications for ticket available')
|
2015-04-01 14:33:24 +00:00
|
|
|
else
|
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id )
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( !notification_seen_only_exists_exists( notifications ), 'seen notifications for ticket available')
|
2015-04-01 14:33:24 +00:00
|
|
|
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
|
2015-07-03 17:40:58 +00:00
|
|
|
next 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')
|
2015-04-01 14:33:24 +00:00
|
|
|
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(
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_id: tickets[3].id,
|
|
|
|
user_id: 1,
|
2015-04-01 11:47:10 +00:00
|
|
|
)
|
2015-05-01 15:06:19 +00:00
|
|
|
Delayed::Worker.new.work_off
|
2015-04-01 14:33:24 +00:00
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', tickets[2].id )
|
2015-04-27 12:51:43 +00:00
|
|
|
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 )
|
2015-04-27 12:51:43 +00:00
|
|
|
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
|
2015-04-27 13:42:53 +00:00
|
|
|
found = Ticket.where( id: ticket_id ).first
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( !found, 'Ticket destroyed')
|
2015-04-01 11:14:46 +00:00
|
|
|
|
|
|
|
# check if notifications for ticket still exist
|
2015-05-01 15:06:19 +00:00
|
|
|
Delayed::Worker.new.work_off
|
2015-04-01 11:47:10 +00:00
|
|
|
notifications = OnlineNotification.list_by_object( 'Ticket', ticket_id )
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( notifications.empty?, 'still notifications for destroyed ticket available')
|
2015-01-21 20:45:22 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-09-03 09:14:09 +00:00
|
|
|
test 'ticket notification item check' do
|
|
|
|
ticket1 = Ticket.create(
|
2015-09-03 09:29:33 +00:00
|
|
|
title: 'some title',
|
2015-09-03 09:14:09 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert( ticket1, 'ticket created' )
|
|
|
|
article_inbound = 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 article_inbound',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'email'),
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2), false)
|
|
|
|
|
|
|
|
# pending reminder, just let new owner to unseed
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: agent_user1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'pending reminder'),
|
|
|
|
updated_by_id: agent_user2.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
|
|
|
|
|
|
|
|
# pending reminder, just let new owner to unseed
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: 1,
|
|
|
|
state: Ticket::State.lookup(name: 'pending reminder'),
|
|
|
|
updated_by_id: agent_user2.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2.id), false)
|
|
|
|
|
|
|
|
# pending reminder, self done, all to unseed
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: agent_user1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'pending reminder'),
|
|
|
|
updated_by_id: agent_user1.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
|
|
|
|
|
|
|
|
# pending close, all to unseen
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: agent_user1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'pending close'),
|
|
|
|
updated_by_id: agent_user2.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2016-02-20 12:36:59 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
|
2015-09-03 09:14:09 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
|
|
|
|
|
|
|
|
# to open, all to seen
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: agent_user1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'open'),
|
|
|
|
updated_by_id: agent_user2.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2.id), false)
|
|
|
|
|
2016-02-20 12:36:59 +00:00
|
|
|
# to closed, all only others to seen
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: agent_user1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'closed'),
|
|
|
|
updated_by_id: agent_user2.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
|
|
|
|
|
|
|
|
# to closed by owner self, all to seen
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: agent_user1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'closed'),
|
|
|
|
updated_by_id: agent_user1.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2016-02-20 13:09:56 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
|
|
|
|
|
|
|
|
# to closed by owner self, all to seen
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: agent_user1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'merged'),
|
|
|
|
updated_by_id: agent_user2.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2016-02-20 12:36:59 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
|
|
|
|
|
2015-09-03 09:14:09 +00:00
|
|
|
end
|
|
|
|
|
2016-01-19 22:30:23 +00:00
|
|
|
def notification_check(online_notifications, checks)
|
2015-01-21 20:45:22 +00:00
|
|
|
checks.each { |check_item|
|
|
|
|
hit = false
|
2015-07-03 17:40:58 +00:00
|
|
|
online_notifications.each {|onine_notification|
|
|
|
|
|
|
|
|
next if onine_notification['o_id'] != check_item[:o_id]
|
|
|
|
next if onine_notification['object'] != check_item[:object]
|
|
|
|
next if onine_notification['type'] != check_item[:type]
|
|
|
|
next if onine_notification['created_by_id'] != check_item[:created_by_id]
|
|
|
|
|
|
|
|
hit = true
|
|
|
|
|
|
|
|
break
|
2015-01-21 20:45:22 +00:00
|
|
|
}
|
2015-07-03 17:40:58 +00:00
|
|
|
#puts "--- #{online_notifications.inspect}"
|
2015-07-03 15:18:01 +00:00
|
|
|
assert( hit, "online notification exists not #{check_item.inspect}" )
|
2015-01-21 20:45:22 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-01-19 22:30:23 +00:00
|
|
|
def notification_seen_only_exists_exists(online_notifications)
|
2015-07-03 17:40:58 +00:00
|
|
|
online_notifications.each {|onine_notification|
|
2015-04-01 14:33:24 +00:00
|
|
|
return false if !onine_notification['seen']
|
|
|
|
}
|
|
|
|
true
|
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|