2013-03-22 07:11:20 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'test_helper'
|
2013-06-07 05:57:52 +00:00
|
|
|
|
2013-03-22 07:11:20 +00:00
|
|
|
class TicketTest < ActiveSupport::TestCase
|
|
|
|
test 'ticket create' do
|
|
|
|
ticket = Ticket.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
title: "some title\n äöüß",
|
2016-02-26 12:56:36 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-04-27 13:42:53 +00:00
|
|
|
customer_id: 2,
|
2016-02-26 12:56:36 +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: 1,
|
|
|
|
created_by_id: 1,
|
2013-03-22 07:11:20 +00:00
|
|
|
)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert(ticket, 'ticket created')
|
2013-03-22 07:11:20 +00:00
|
|
|
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.title, 'some title äöüß', 'ticket.title verify')
|
|
|
|
assert_equal(ticket.group.name, 'Users', 'ticket.group verify')
|
|
|
|
assert_equal(ticket.state.name, 'new', 'ticket.state verify')
|
2013-03-22 07:11:20 +00:00
|
|
|
|
2015-10-30 10:05:51 +00:00
|
|
|
# create inbound article #1
|
|
|
|
article_inbound1 = Ticket::Article.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_id: ticket.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
2015-10-30 10:05:51 +00:00
|
|
|
body: 'some message article_inbound1 😍😍😍',
|
2015-04-27 13:42:53 +00:00
|
|
|
internal: false,
|
2016-02-26 12:56:36 +00:00
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2013-03-28 23:13:15 +00:00
|
|
|
)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(article_inbound1.body, 'some message article_inbound1 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound')
|
2014-06-01 08:29:58 +00:00
|
|
|
|
2013-03-28 23:13:15 +00:00
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.article_count, 1, 'ticket.article_count verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_customer.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - inbound')
|
|
|
|
assert_equal(ticket.first_response, nil, 'ticket.first_response verify - inbound')
|
|
|
|
assert_equal(ticket.close_time, nil, 'ticket.close_time verify - inbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
# create inbound article #2
|
|
|
|
sleep 2
|
|
|
|
article_inbound2 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message article_inbound2 😍😍😍',
|
|
|
|
internal: false,
|
2016-02-26 12:56:36 +00:00
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
2015-10-30 10:05:51 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(article_inbound2.body, 'some message article_inbound2 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.article_count, 2, 'ticket.article_count verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_customer.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - inbound')
|
|
|
|
assert_equal(ticket.first_response, nil, 'ticket.first_response verify - inbound')
|
|
|
|
assert_equal(ticket.close_time, nil, 'ticket.close_time verify - inbound')
|
2013-03-28 23:13:15 +00:00
|
|
|
|
|
|
|
# create note article
|
|
|
|
article_note = Ticket::Article.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_id: ticket.id,
|
|
|
|
from: 'some person',
|
|
|
|
subject: "some\nnote",
|
|
|
|
body: "some\n message",
|
|
|
|
internal: true,
|
2016-02-26 12:56:36 +00:00
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'note'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2013-03-28 23:13:15 +00:00
|
|
|
)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(article_note.subject, 'some note', 'article_note.subject verify - inbound')
|
|
|
|
assert_equal(article_note.body, "some\n message", 'article_note.body verify - inbound')
|
2013-03-28 23:13:15 +00:00
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.article_count, 3, 'ticket.article_count verify - note')
|
|
|
|
assert_equal(ticket.last_contact.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact verify - note')
|
|
|
|
assert_equal(ticket.last_contact_customer.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer verify - note')
|
|
|
|
assert_equal(ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - note')
|
|
|
|
assert_equal(ticket.first_response, nil, 'ticket.first_response verify - note')
|
|
|
|
assert_equal(ticket.close_time, nil, 'ticket.close_time verify - note')
|
2013-03-28 23:13:15 +00:00
|
|
|
|
|
|
|
# create outbound article
|
2015-10-30 10:05:51 +00:00
|
|
|
sleep 2
|
2013-03-28 23:13:15 +00:00
|
|
|
article_outbound = Ticket::Article.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_id: ticket.id,
|
|
|
|
from: 'some_recipient@example.com',
|
|
|
|
to: 'some_sender@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id2',
|
|
|
|
body: 'some message 2',
|
|
|
|
internal: false,
|
2016-02-26 12:56:36 +00:00
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2013-03-28 23:13:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.article_count, 4, 'ticket.article_count verify - outbound')
|
|
|
|
assert_equal(ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - outbound')
|
|
|
|
assert_equal(ticket.last_contact_customer.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer verify - outbound')
|
|
|
|
assert_equal(ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - outbound')
|
|
|
|
assert_equal(ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound')
|
|
|
|
assert_equal(ticket.close_time, nil, 'ticket.close_time verify - outbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
# create inbound article #3
|
|
|
|
article_inbound3 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message article_inbound3 😍😍😍',
|
|
|
|
internal: false,
|
2016-02-26 12:56:36 +00:00
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
2015-10-30 10:05:51 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(article_inbound3.body, 'some message article_inbound3 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.article_count, 5, 'ticket.article_count verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_customer.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact_customer verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - outbound')
|
|
|
|
assert_equal(ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound')
|
|
|
|
assert_equal(ticket.close_time, nil, 'ticket.close_time verify - outbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
# create inbound article #4
|
|
|
|
sleep 2
|
|
|
|
article_inbound4 = Ticket::Article.create(
|
|
|
|
ticket_id: ticket.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message article_inbound4 😍😍😍',
|
|
|
|
internal: false,
|
2016-02-26 12:56:36 +00:00
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
2015-10-30 10:05:51 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(article_inbound4.body, 'some message article_inbound4 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.article_count, 6, 'ticket.article_count verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_customer.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact_customer verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - outbound')
|
|
|
|
assert_equal(ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound')
|
|
|
|
assert_equal(ticket.close_time, nil, 'ticket.close_time verify - outbound')
|
2013-03-28 23:13:15 +00:00
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket.state_id = Ticket::State.where(name: 'closed').first.id
|
2013-03-28 23:13:15 +00:00
|
|
|
ticket.save
|
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.article_count, 6, 'ticket.article_count verify - state update')
|
|
|
|
assert_equal(ticket.last_contact.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - state update')
|
|
|
|
assert_equal(ticket.last_contact_customer.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact_customer verify - state update')
|
|
|
|
assert_equal(ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - state update')
|
|
|
|
assert_equal(ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - state update')
|
|
|
|
assert(ticket.close_time, 'ticket.close_time verify - state update')
|
2013-03-28 23:13:15 +00:00
|
|
|
|
2015-02-11 22:05:31 +00:00
|
|
|
# set pending time
|
2016-02-26 12:56:36 +00:00
|
|
|
ticket.state_id = Ticket::State.find_by(name: 'pending reminder').id
|
2015-04-27 17:42:59 +00:00
|
|
|
ticket.pending_time = Time.zone.parse('1977-10-27 22:00:00 +0000')
|
2015-02-11 22:05:31 +00:00
|
|
|
ticket.save
|
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.state.name, 'pending reminder', 'state verify')
|
|
|
|
assert_equal(ticket.pending_time, Time.zone.parse('1977-10-27 22:00:00 +0000'), 'pending_time verify')
|
2015-02-11 22:05:31 +00:00
|
|
|
|
|
|
|
# reset pending state, should also reset pending time
|
2016-02-26 12:56:36 +00:00
|
|
|
ticket.state_id = Ticket::State.find_by(name: 'closed').id
|
2015-02-11 22:05:31 +00:00
|
|
|
ticket.save
|
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(ticket.state.name, 'closed', 'state verify')
|
|
|
|
assert_equal(ticket.pending_time, nil )
|
2015-02-11 22:05:31 +00:00
|
|
|
|
2013-03-22 07:11:20 +00:00
|
|
|
delete = ticket.destroy
|
2016-02-26 12:56:36 +00:00
|
|
|
assert(delete, 'ticket destroy')
|
2013-03-22 07:11:20 +00:00
|
|
|
end
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
test 'ticket latest change' do
|
|
|
|
ticket1 = Ticket.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
title: 'latest change 1',
|
2016-02-26 12:56:36 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-04-27 13:42:53 +00:00
|
|
|
customer_id: 2,
|
2016-02-26 12:56:36 +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: 1,
|
|
|
|
created_by_id: 1,
|
2015-02-25 20:52:14 +00:00
|
|
|
)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
ticket2 = Ticket.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
title: 'latest change 2',
|
2016-02-26 12:56:36 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-04-27 13:42:53 +00:00
|
|
|
customer_id: 2,
|
2016-02-26 12:56:36 +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: 1,
|
|
|
|
created_by_id: 1,
|
2015-02-25 20:52:14 +00:00
|
|
|
)
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(Ticket.latest_change.to_s, ticket2.updated_at.to_s)
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
ticket1.title = 'latest change 1 - 1'
|
|
|
|
ticket1.save
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
ticket1.touch
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
ticket1.destroy
|
2016-02-26 12:56:36 +00:00
|
|
|
assert_equal(Ticket.latest_change.to_s, ticket2.updated_at.to_s)
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
end
|
2015-05-21 14:40:04 +00:00
|
|
|
|
|
|
|
test 'ticket process_pending' do
|
|
|
|
|
2016-02-26 12:56:36 +00:00
|
|
|
# close all other pending close tickets first
|
|
|
|
Ticket.where('pending_time IS NOT NULL').each {|ticket|
|
|
|
|
ticket.state = Ticket::State.lookup(name: 'closed')
|
|
|
|
ticket.save!
|
|
|
|
}
|
|
|
|
|
2015-05-21 14:40:04 +00:00
|
|
|
ticket = Ticket.create(
|
2015-05-21 14:53:44 +00:00
|
|
|
title: 'pending close test',
|
2016-02-26 12:56:36 +00:00
|
|
|
group: Group.lookup(name: 'Users'),
|
2015-05-21 14:40:04 +00:00
|
|
|
customer_id: 2,
|
2016-02-26 12:56:36 +00:00
|
|
|
state: Ticket::State.lookup(name: 'pending close'),
|
2015-05-21 14:40:04 +00:00
|
|
|
pending_time: Time.zone.now - 60,
|
2016-02-26 12:56:36 +00:00
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-05-21 14:40:04 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
2016-02-26 12:56:36 +00:00
|
|
|
lookup_ticket = Ticket.find_by('pending_time <= ?', Time.zone.now)
|
|
|
|
assert_equal(lookup_ticket.id, ticket.id, 'ticket.pending_time verify')
|
2015-05-21 14:40:04 +00:00
|
|
|
|
2015-05-21 14:53:44 +00:00
|
|
|
Ticket.process_pending
|
2015-05-21 14:40:04 +00:00
|
|
|
|
2016-02-26 12:56:36 +00:00
|
|
|
lookup_ticket = Ticket.find_by('pending_time <= ?', Time.zone.now)
|
|
|
|
assert_nil(lookup_ticket, 'ticket.pending_time processed verify')
|
2015-05-21 14:40:04 +00:00
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|