2015-01-21 20:45:22 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class OnlineNotificationTest < ActiveSupport::TestCase
|
2017-06-14 15:25:45 +00:00
|
|
|
|
|
|
|
setup do
|
|
|
|
role = Role.lookup(name: 'Agent')
|
|
|
|
@group = Group.create_or_update(
|
2016-06-20 08:55:45 +00:00
|
|
|
name: 'OnlineNotificationTest',
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
@agent_user1 = User.create_or_update(
|
2016-06-20 08:55:45 +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],
|
2017-06-14 15:25:45 +00:00
|
|
|
group_ids: [@group.id],
|
2016-06-20 08:55:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
@agent_user2 = User.create_or_update(
|
2016-06-20 08:55:45 +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],
|
2017-06-14 15:25:45 +00:00
|
|
|
group_ids: [@group.id],
|
2016-06-20 08:55:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
@customer_user = User.lookup(email: 'nicole.braun@zammad.org')
|
2016-06-20 08:55:45 +00:00
|
|
|
end
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2015-09-03 09:14:09 +00:00
|
|
|
test 'ticket notification' do
|
2016-02-22 07:58:33 +00:00
|
|
|
|
2016-08-20 19:29:22 +00:00
|
|
|
ApplicationHandleInfo.current = 'application_server'
|
2016-02-22 08:51:56 +00:00
|
|
|
|
2016-02-22 07:58:33 +00:00
|
|
|
# case #1
|
|
|
|
ticket1 = Ticket.create(
|
2017-06-14 15:25:45 +00:00
|
|
|
group: @group,
|
|
|
|
customer_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user1.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
|
|
|
article1 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket1.id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user1.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
# remember ticket
|
2015-01-21 20:45:22 +00:00
|
|
|
tickets = []
|
2016-02-22 07:58:33 +00:00
|
|
|
tickets.push ticket1
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2016-02-22 07:58:33 +00:00
|
|
|
# because it's already closed
|
|
|
|
assert(OnlineNotification.all_seen?('Ticket', ticket1.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket1.id, 'create', @agent_user1, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket1.id, 'create', @agent_user1, true))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'create', @agent_user1, false))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'create', @agent_user1, true))
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2016-02-22 07:58:33 +00:00
|
|
|
ticket1.update_attributes(
|
|
|
|
title: 'Unit Test 1 (äöüß) - update!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'open').id,
|
|
|
|
priority_id: Ticket::Priority.lookup(name: '1 low').id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2016-02-22 07:58:33 +00:00
|
|
|
# because it's already open
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket1.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket1.id, 'update', @customer_user, true))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket1.id, 'update', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'update', @customer_user, true))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'update', @customer_user, false))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# case #2
|
|
|
|
ticket2 = Ticket.create(
|
2017-06-14 15:25:45 +00:00
|
|
|
group: @group,
|
|
|
|
customer_id: @customer_user.id,
|
|
|
|
owner_id: @agent_user1.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
title: 'Unit Test 1 (äöüß)!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'closed').id,
|
|
|
|
priority_id: Ticket::Priority.lookup(name: '2 normal').id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
|
|
|
created_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
|
|
|
article2 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket2.id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
|
|
|
created_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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
|
|
|
|
2016-02-22 07:58:33 +00:00
|
|
|
# remember ticket
|
|
|
|
tickets = []
|
|
|
|
tickets.push ticket2
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2015-04-01 14:33:24 +00:00
|
|
|
|
2016-02-22 07:58:33 +00:00
|
|
|
# because it's already closed
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket2.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket2.id, 'create', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket2.id, 'create', @customer_user, true))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'create', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'create', @customer_user, true))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
ticket2.update_attributes(
|
|
|
|
title: 'Unit Test 1 (äöüß) - update!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'open').id,
|
|
|
|
priority_id: Ticket::Priority.lookup(name: '1 low').id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
2015-07-03 17:40:58 +00:00
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# because it's already open
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket2.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket2.id, 'update', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket2.id, 'update', @customer_user, true))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'update', @customer_user, true))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'update', @customer_user, false))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# case #3
|
|
|
|
ticket3 = Ticket.create(
|
2017-06-14 15:25:45 +00:00
|
|
|
group: @group,
|
|
|
|
customer_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user1.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
|
|
|
article3 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket3.id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user1.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
|
|
|
# remember ticket
|
|
|
|
tickets.push ticket3
|
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# because it's already new
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket3.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'create', @agent_user1, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'create', @agent_user1, true))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'create', @agent_user1, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'create', @agent_user1, true))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
ticket3.update_attributes(
|
|
|
|
title: 'Unit Test 2 (äöüß) - update!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'closed').id,
|
|
|
|
priority_id: Ticket::Priority.lookup(name: '1 low').id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# because it's already closed
|
|
|
|
assert(OnlineNotification.all_seen?('Ticket', ticket3.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent_user1, 'update'))
|
|
|
|
assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent_user2, 'update'))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'update', @customer_user, false))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'update', @customer_user, true))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'update', @customer_user, false))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'update', @customer_user, true))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
article3 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket3.id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
|
|
|
created_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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 # 2',
|
|
|
|
internal: false
|
|
|
|
)
|
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# because it's already closed but an follow up arrived later
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket3.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'update', @customer_user, false))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'update', @customer_user, true))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'update', @customer_user, false))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'update', @customer_user, true))
|
|
|
|
assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent_user1, 'update'))
|
|
|
|
assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent_user2, 'update'))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# case #4
|
|
|
|
ticket4 = Ticket.create(
|
2017-06-14 15:25:45 +00:00
|
|
|
group: @group,
|
|
|
|
customer_id: @customer_user.id,
|
|
|
|
owner_id: @agent_user1.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
title: 'Unit Test 3 (äöüß)!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'new').id,
|
|
|
|
priority_id: Ticket::Priority.lookup(name: '2 normal').id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
|
|
|
created_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
|
|
|
article4 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket4.id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
|
|
|
created_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
|
|
|
# remember ticket
|
|
|
|
tickets.push ticket4
|
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# because it's already new
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket4.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket4.id, 'create', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket4.id, 'create', @customer_user, true))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'create', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'create', @customer_user, true))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
ticket4.update_attributes(
|
|
|
|
title: 'Unit Test 3 (äöüß) - update!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'open').id,
|
|
|
|
priority_id: Ticket::Priority.lookup(name: '1 low').id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# because it's already open
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket4.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket4.id, 'update', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket4.id, 'update', @customer_user, true))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'update', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'update', @customer_user, true))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# case #5
|
|
|
|
ticket5 = Ticket.create(
|
2017-06-14 15:25:45 +00:00
|
|
|
group: @group,
|
|
|
|
customer_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user1.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
|
|
|
article5 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket5.id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user1.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
|
|
|
# remember ticket
|
|
|
|
tickets.push ticket5
|
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# because it's already new
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket5.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket5.id, 'create', @agent_user1, true))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket5.id, 'create', @agent_user1, false))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'create', @agent_user1, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'create', @agent_user1, true))
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
ticket5.update_attributes(
|
|
|
|
title: 'Unit Test 4 (äöüß) - update!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'open').id,
|
|
|
|
priority_id: Ticket::Priority.lookup(name: '1 low').id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @customer_user.id,
|
2016-02-22 07:58:33 +00:00
|
|
|
)
|
|
|
|
|
2016-04-14 07:17:13 +00:00
|
|
|
# execute object transaction
|
|
|
|
Observer::Transaction.commit
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
|
|
|
|
# because it's already open
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', ticket5.id))
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket5.id, 'update', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket5.id, 'update', @customer_user, true))
|
|
|
|
assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'update', @customer_user, false))
|
|
|
|
assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'update', @customer_user, true))
|
2015-01-21 20:45:22 +00:00
|
|
|
|
2015-04-01 11:47:10 +00:00
|
|
|
# merge tickets - also remove notifications of merged tickets
|
2016-02-22 07:58:33 +00:00
|
|
|
tickets[0].merge_to(
|
|
|
|
ticket_id: tickets[1].id,
|
2015-04-27 13:42:53 +00:00
|
|
|
user_id: 1,
|
2015-04-01 11:47:10 +00:00
|
|
|
)
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2015-04-01 11:47:10 +00:00
|
|
|
|
2016-02-22 07:58:33 +00:00
|
|
|
notifications = OnlineNotification.list_by_object('Ticket', tickets[0].id)
|
|
|
|
assert(!notifications.empty?, 'should have notifications')
|
|
|
|
assert(OnlineNotification.all_seen?('Ticket', tickets[0].id), 'still not seen notifications for merged ticket available')
|
|
|
|
|
|
|
|
notifications = OnlineNotification.list_by_object('Ticket', tickets[1].id)
|
|
|
|
assert(!notifications.empty?, 'should have notifications')
|
|
|
|
assert(!OnlineNotification.all_seen?('Ticket', tickets[1].id), '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
|
2016-02-22 07:58:33 +00:00
|
|
|
found = Ticket.find_by(id: ticket_id)
|
|
|
|
assert(!found, 'Ticket destroyed')
|
2015-04-01 11:14:46 +00:00
|
|
|
|
|
|
|
# check if notifications for ticket still exist
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2016-02-22 07:58:33 +00:00
|
|
|
notifications = OnlineNotification.list_by_object('Ticket', ticket_id)
|
|
|
|
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',
|
2017-06-14 15:25:45 +00:00
|
|
|
group: @group,
|
|
|
|
customer_id: @customer_user.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2016-08-20 19:29:22 +00:00
|
|
|
assert(ticket1, 'ticket created')
|
2015-09-03 09:14:09 +00:00
|
|
|
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)
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user1), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user2), false)
|
2015-09-03 09:14:09 +00:00
|
|
|
|
|
|
|
# pending reminder, just let new owner to unseed
|
|
|
|
ticket1.update_attributes(
|
2017-06-14 15:25:45 +00:00
|
|
|
owner_id: @agent_user1.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
state: Ticket::State.lookup(name: 'pending reminder'),
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user2.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true)
|
2015-09-03 09:14:09 +00:00
|
|
|
|
|
|
|
# pending reminder, just let new owner to unseed
|
|
|
|
ticket1.update_attributes(
|
|
|
|
owner_id: 1,
|
|
|
|
state: Ticket::State.lookup(name: 'pending reminder'),
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user2.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), false)
|
2015-09-03 09:14:09 +00:00
|
|
|
|
|
|
|
# pending reminder, self done, all to unseed
|
|
|
|
ticket1.update_attributes(
|
2017-06-14 15:25:45 +00:00
|
|
|
owner_id: @agent_user1.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
state: Ticket::State.lookup(name: 'pending reminder'),
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user1.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2017-06-14 15:25:45 +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
|
|
|
|
|
|
|
# pending close, all to unseen
|
|
|
|
ticket1.update_attributes(
|
2017-06-14 15:25:45 +00:00
|
|
|
owner_id: @agent_user1.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
state: Ticket::State.lookup(name: 'pending close'),
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user2.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true)
|
2015-09-03 09:14:09 +00:00
|
|
|
|
|
|
|
# to open, all to seen
|
|
|
|
ticket1.update_attributes(
|
2017-06-14 15:25:45 +00:00
|
|
|
owner_id: @agent_user1.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
state: Ticket::State.lookup(name: 'open'),
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user2.id,
|
2015-09-03 09:14:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, false)
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), false)
|
2015-09-03 09:14:09 +00:00
|
|
|
|
2016-02-20 12:36:59 +00:00
|
|
|
# to closed, all only others to seen
|
|
|
|
ticket1.update_attributes(
|
2017-06-14 15:25:45 +00:00
|
|
|
owner_id: @agent_user1.id,
|
2016-02-20 12:36:59 +00:00
|
|
|
state: Ticket::State.lookup(name: 'closed'),
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user2.id,
|
2016-02-20 12:36:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true)
|
2016-02-20 12:36:59 +00:00
|
|
|
|
|
|
|
# to closed by owner self, all to seen
|
|
|
|
ticket1.update_attributes(
|
2017-06-14 15:25:45 +00:00
|
|
|
owner_id: @agent_user1.id,
|
2016-02-20 12:36:59 +00:00
|
|
|
state: Ticket::State.lookup(name: 'closed'),
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user1.id,
|
2016-02-20 12:36:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true)
|
2016-02-20 13:09:56 +00:00
|
|
|
|
|
|
|
# to closed by owner self, all to seen
|
|
|
|
ticket1.update_attributes(
|
2017-06-14 15:25:45 +00:00
|
|
|
owner_id: @agent_user1.id,
|
2016-02-20 13:09:56 +00:00
|
|
|
state: Ticket::State.lookup(name: 'merged'),
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @agent_user2.id,
|
2016-02-20 13:09:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(ticket1.online_notification_seen_state, true)
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), true)
|
|
|
|
assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true)
|
2016-02-20 12:36:59 +00:00
|
|
|
|
2015-09-03 09:14:09 +00:00
|
|
|
end
|
|
|
|
|
2016-02-21 11:43:16 +00:00
|
|
|
test 'cleanup check' do
|
|
|
|
online_notification1 = OnlineNotification.add(
|
|
|
|
type: 'create',
|
|
|
|
object: 'Ticket',
|
|
|
|
o_id: 123,
|
|
|
|
seen: false,
|
2017-06-14 15:25:45 +00:00
|
|
|
user_id: @agent_user1.id,
|
2016-02-21 11:43:16 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
2016-02-24 07:05:03 +00:00
|
|
|
created_at: Time.zone.now - 10.months,
|
|
|
|
updated_at: Time.zone.now - 10.months,
|
2016-02-21 11:43:16 +00:00
|
|
|
)
|
|
|
|
online_notification2 = OnlineNotification.add(
|
|
|
|
type: 'create',
|
|
|
|
object: 'Ticket',
|
|
|
|
o_id: 123,
|
|
|
|
seen: true,
|
2017-06-14 15:25:45 +00:00
|
|
|
user_id: @agent_user1.id,
|
2016-02-21 11:43:16 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
2016-02-24 07:05:03 +00:00
|
|
|
created_at: Time.zone.now - 10.months,
|
|
|
|
updated_at: Time.zone.now - 10.months,
|
2016-02-21 11:43:16 +00:00
|
|
|
)
|
|
|
|
online_notification3 = OnlineNotification.add(
|
|
|
|
type: 'create',
|
|
|
|
object: 'Ticket',
|
|
|
|
o_id: 123,
|
|
|
|
seen: false,
|
2017-06-14 15:25:45 +00:00
|
|
|
user_id: @agent_user1.id,
|
2016-02-21 11:43:16 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_at: Time.zone.now - 2.days,
|
|
|
|
updated_at: Time.zone.now - 2.days,
|
|
|
|
)
|
|
|
|
online_notification4 = OnlineNotification.add(
|
|
|
|
type: 'create',
|
|
|
|
object: 'Ticket',
|
|
|
|
o_id: 123,
|
|
|
|
seen: true,
|
2017-06-14 15:25:45 +00:00
|
|
|
user_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user1.id,
|
|
|
|
updated_by_id: @agent_user1.id,
|
2016-02-21 11:43:16 +00:00
|
|
|
created_at: Time.zone.now - 2.days,
|
|
|
|
updated_at: Time.zone.now - 2.days,
|
|
|
|
)
|
|
|
|
online_notification5 = OnlineNotification.add(
|
|
|
|
type: 'create',
|
|
|
|
object: 'Ticket',
|
|
|
|
o_id: 123,
|
|
|
|
seen: true,
|
2017-06-14 15:25:45 +00:00
|
|
|
user_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user2.id,
|
|
|
|
updated_by_id: @agent_user2.id,
|
2016-02-21 11:43:16 +00:00
|
|
|
created_at: Time.zone.now - 2.days,
|
|
|
|
updated_at: Time.zone.now - 2.days,
|
|
|
|
)
|
|
|
|
online_notification6 = OnlineNotification.add(
|
|
|
|
type: 'create',
|
|
|
|
object: 'Ticket',
|
|
|
|
o_id: 123,
|
|
|
|
seen: true,
|
2017-06-14 15:25:45 +00:00
|
|
|
user_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user1.id,
|
|
|
|
updated_by_id: @agent_user1.id,
|
2016-02-24 05:27:47 +00:00
|
|
|
created_at: Time.zone.now - 5.minutes,
|
|
|
|
updated_at: Time.zone.now - 5.minutes,
|
2016-02-21 11:43:16 +00:00
|
|
|
)
|
|
|
|
online_notification7 = OnlineNotification.add(
|
|
|
|
type: 'create',
|
|
|
|
object: 'Ticket',
|
|
|
|
o_id: 123,
|
|
|
|
seen: true,
|
2017-06-14 15:25:45 +00:00
|
|
|
user_id: @agent_user1.id,
|
|
|
|
created_by_id: @agent_user2.id,
|
|
|
|
updated_by_id: @agent_user2.id,
|
2016-02-24 05:27:47 +00:00
|
|
|
created_at: Time.zone.now - 5.minutes,
|
|
|
|
updated_at: Time.zone.now - 5.minutes,
|
2016-02-21 11:43:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
OnlineNotification.cleanup
|
|
|
|
|
|
|
|
assert(!OnlineNotification.find_by(id: online_notification1.id))
|
|
|
|
assert(!OnlineNotification.find_by(id: online_notification2.id))
|
|
|
|
assert(OnlineNotification.find_by(id: online_notification3.id))
|
|
|
|
assert(!OnlineNotification.find_by(id: online_notification4.id))
|
|
|
|
assert(!OnlineNotification.find_by(id: online_notification5.id))
|
|
|
|
assert(OnlineNotification.find_by(id: online_notification6.id))
|
|
|
|
assert(OnlineNotification.find_by(id: online_notification7.id))
|
2016-02-21 11:54:27 +00:00
|
|
|
OnlineNotification.destroy_all
|
2016-02-21 11:43:16 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|