2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2016-07-10 22:47:21 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class KarmaTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
test 'basic' do
|
|
|
|
|
|
|
|
groups = Group.all
|
|
|
|
roles = Role.where(name: 'Agent')
|
2019-04-07 15:23:03 +00:00
|
|
|
agent1 = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'karma-agent1@example.com',
|
|
|
|
firstname: 'Karma',
|
|
|
|
lastname: 'Agent1',
|
|
|
|
email: 'karma-agent1@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2019-04-07 15:23:03 +00:00
|
|
|
agent2 = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'karma-agent2@example.com',
|
|
|
|
firstname: 'Karma',
|
|
|
|
lastname: 'Agent2',
|
|
|
|
email: 'karma-agent2@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2019-04-07 15:23:03 +00:00
|
|
|
customer1 = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'karma-customer1@example.com',
|
|
|
|
firstname: 'Karma',
|
|
|
|
lastname: 'Customer1',
|
|
|
|
email: 'karma-customer1@example.com',
|
|
|
|
password: 'customerpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2019-04-07 15:23:03 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'karma test 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: customer1,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - 10.hours,
|
|
|
|
created_at: Time.zone.now - 10.hours,
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'agent phone 1 / init',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - 10.hours,
|
|
|
|
created_at: Time.zone.now - 10.hours,
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
assert(ticket1)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(0, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
karma_user = Karma::User.by_user(agent1)
|
|
|
|
assert_equal('Beginner', karma_user.level)
|
|
|
|
assert_equal(10, karma_user.score)
|
|
|
|
|
|
|
|
karma_user = Karma::User.by_user(agent2)
|
|
|
|
assert_equal('Beginner', karma_user.level)
|
|
|
|
assert_equal(0, karma_user.score)
|
|
|
|
|
|
|
|
ticket1.state = Ticket::State.lookup(name: 'pending reminder')
|
|
|
|
ticket1.updated_by_id = agent1.id
|
|
|
|
ticket1.updated_at = Time.zone.now - 9.hours
|
|
|
|
ticket1.created_at = Time.zone.now - 9.hours
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket1.save!
|
2016-07-10 22:47:21 +00:00
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(0, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
karma_user = Karma::User.by_user(agent1)
|
|
|
|
assert_equal('Beginner', karma_user.level)
|
|
|
|
assert_equal(12, karma_user.score)
|
|
|
|
|
|
|
|
karma_user = Karma::User.by_user(agent2)
|
|
|
|
assert_equal('Beginner', karma_user.level)
|
|
|
|
assert_equal(0, karma_user.score)
|
|
|
|
|
|
|
|
ticket1.state = Ticket::State.lookup(name: 'pending close')
|
|
|
|
ticket1.updated_by_id = agent1.id
|
|
|
|
ticket1.updated_at = Time.zone.now - 9.hours
|
|
|
|
ticket1.created_at = Time.zone.now - 9.hours
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket1.save!
|
2016-07-10 22:47:21 +00:00
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(0, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
ticket1.state = Ticket::State.lookup(name: 'closed')
|
|
|
|
ticket1.updated_by_id = agent2.id
|
|
|
|
ticket1.updated_at = Time.zone.now - 9.hours
|
|
|
|
ticket1.created_at = Time.zone.now - 9.hours
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket1.save!
|
2016-07-10 22:47:21 +00:00
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(0, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
ticket1.state = Ticket::State.lookup(name: 'open')
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket1.save!
|
2016-07-10 22:47:21 +00:00
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'reply: some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'agent phone 2',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent2.id,
|
|
|
|
created_by_id: agent2.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - (9.hours + 15.minutes),
|
|
|
|
created_at: Time.zone.now - (9.hours + 15.minutes),
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(0, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
ticket1.state = Ticket::State.lookup(name: 'closed')
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket1.save!
|
2016-07-10 22:47:21 +00:00
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'customer phone',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: customer1.id,
|
|
|
|
created_by_id: customer1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - 8.hours,
|
|
|
|
created_at: Time.zone.now - 8.hours,
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'agent phone 3',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - (7.hours + 30.minutes),
|
|
|
|
created_at: Time.zone.now - (7.hours + 30.minutes),
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - (7.hours + 15.minutes),
|
|
|
|
created_at: Time.zone.now - (7.hours + 15.minutes),
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: customer1.id,
|
|
|
|
created_by_id: customer1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - 7.hours,
|
|
|
|
created_at: Time.zone.now - 7.hours,
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent2.id,
|
|
|
|
created_by_id: agent2.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - (2.hours + 30.minutes),
|
|
|
|
created_at: Time.zone.now - (2.hours + 30.minutes),
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - (2.hours + 45.minutes),
|
|
|
|
created_at: Time.zone.now - (2.hours + 45.minutes),
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2017-04-12 07:34:49 +00:00
|
|
|
ticket1.tag_add('Tag1', agent1.id)
|
2016-12-07 07:15:56 +00:00
|
|
|
#travel 5.seconds
|
2017-04-12 07:34:49 +00:00
|
|
|
ticket1.tag_add('Tag2', agent1.id)
|
2016-07-10 22:47:21 +00:00
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25 + 4, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2017-04-12 07:34:49 +00:00
|
|
|
ticket1.tag_add('Tag3', agent1.id)
|
|
|
|
ticket1.tag_add('Tag4', agent2.id)
|
2016-07-10 22:47:21 +00:00
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25 + 4, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
ticket2 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'karma test 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer: customer1,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
owner_id: agent1.id,
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - 10.hours,
|
|
|
|
created_at: Time.zone.now - 10.hours,
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
2019-04-07 15:23:03 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket2.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.lookup(name: 'phone'),
|
2016-07-10 22:47:21 +00:00
|
|
|
updated_by_id: agent1.id,
|
|
|
|
created_by_id: agent1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_at: Time.zone.now - 2.hours,
|
|
|
|
created_at: Time.zone.now - 2.hours,
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
assert(ticket2)
|
|
|
|
|
|
|
|
# execute object transaction
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25 + 4 + 10, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
ticket2.state = Ticket::State.lookup(name: 'pending reminder')
|
|
|
|
ticket2.pending_time = Time.zone.now - 1.day
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket2.save!
|
2016-07-10 22:47:21 +00:00
|
|
|
|
|
|
|
Ticket.process_pending
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25 + 4 + 10, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
ticket2.state = Ticket::State.lookup(name: 'pending reminder')
|
|
|
|
ticket2.pending_time = Time.zone.now - 3.days
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket2.save!
|
2016-07-10 22:47:21 +00:00
|
|
|
|
|
|
|
Ticket.process_pending
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25 + 4 + 10 - 5, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
Ticket.process_pending
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25 + 4 + 10 - 5, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
calendar1 = Calendar.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'EU 1 - karma test',
|
|
|
|
timezone: 'Europe/Berlin',
|
2016-07-10 22:47:21 +00:00
|
|
|
business_hours: {
|
|
|
|
mon: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2016-07-10 22:47:21 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
tue: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2016-07-10 22:47:21 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
wed: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2016-07-10 22:47:21 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
thu: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2016-07-10 22:47:21 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
fri: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2016-07-10 22:47:21 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
sat: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2016-07-10 22:47:21 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
sun: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2016-07-10 22:47:21 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
default: true,
|
|
|
|
ical_url: nil,
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
|
2019-04-07 15:23:03 +00:00
|
|
|
sla1 = Sla.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'test sla 1',
|
|
|
|
condition: {},
|
2016-07-10 22:47:21 +00:00
|
|
|
first_response_time: 20,
|
2018-12-19 17:31:51 +00:00
|
|
|
update_time: 60,
|
|
|
|
solution_time: 120,
|
|
|
|
calendar_id: calendar1.id,
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2016-07-10 22:47:21 +00:00
|
|
|
)
|
|
|
|
ticket2.state = Ticket::State.lookup(name: 'open')
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket2.save!
|
2016-07-10 22:47:21 +00:00
|
|
|
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-07-10 22:47:21 +00:00
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
#Scheduler.worker(true)
|
|
|
|
#Ticket::Escalation.rebuild_all
|
|
|
|
Ticket.process_escalation
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25 + 4 + 10 - 5 - 5, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
|
|
|
Ticket.process_escalation
|
|
|
|
|
|
|
|
assert_equal(10 + 2 + 25 + 4 + 10 - 5 - 5, Karma.score_by_user(agent1))
|
|
|
|
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2016-07-11 15:12:12 +00:00
|
|
|
# check min score
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
|
|
|
assert_equal(0, Karma.score_by_user(agent1), 'block - score, min is 0')
|
|
|
|
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
|
|
|
assert_equal(0, Karma.score_by_user(customer1))
|
|
|
|
|
2016-07-10 22:47:21 +00:00
|
|
|
# test score/level
|
|
|
|
assert_equal('Beginner', Karma::User.level_by_score(0))
|
|
|
|
assert_equal('Beginner', Karma::User.level_by_score(400))
|
|
|
|
assert_equal('Beginner', Karma::User.level_by_score(499))
|
|
|
|
assert_equal('Newbie', Karma::User.level_by_score(500))
|
|
|
|
assert_equal('Newbie', Karma::User.level_by_score(1999))
|
|
|
|
assert_equal('Intermediate', Karma::User.level_by_score(2000))
|
|
|
|
assert_equal('Intermediate', Karma::User.level_by_score(4999))
|
|
|
|
assert_equal('Professional', Karma::User.level_by_score(5000))
|
|
|
|
assert_equal('Professional', Karma::User.level_by_score(6999))
|
|
|
|
assert_equal('Expert', Karma::User.level_by_score(7000))
|
|
|
|
assert_equal('Expert', Karma::User.level_by_score(8999))
|
|
|
|
assert_equal('Master', Karma::User.level_by_score(9000))
|
|
|
|
assert_equal('Master', Karma::User.level_by_score(18_999))
|
|
|
|
assert_equal('Evangelist', Karma::User.level_by_score(19_000))
|
2019-06-27 09:01:11 +00:00
|
|
|
assert_equal('Evangelist', Karma::User.level_by_score(49_999))
|
2016-07-10 22:47:21 +00:00
|
|
|
assert_equal('Hero', Karma::User.level_by_score(50_000))
|
|
|
|
|
2016-07-11 23:30:44 +00:00
|
|
|
# cleanup
|
2017-09-23 06:25:55 +00:00
|
|
|
ticket1.destroy!
|
|
|
|
ticket2.destroy!
|
|
|
|
calendar1.destroy!
|
|
|
|
sla1.destroy!
|
2016-07-11 23:30:44 +00:00
|
|
|
|
2016-07-10 22:47:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|