2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2013-03-22 07:11:20 +00:00
|
|
|
require 'test_helper'
|
2013-06-07 05:57:52 +00:00
|
|
|
|
2013-03-22 07:11:20 +00:00
|
|
|
class TicketTest < ActiveSupport::TestCase
|
2018-08-22 10:05:14 +00:00
|
|
|
|
2021-07-09 13:05:05 +00:00
|
|
|
setup do
|
2018-08-22 10:05:14 +00:00
|
|
|
Ticket.destroy_all
|
|
|
|
end
|
|
|
|
|
2013-03-22 07:11:20 +00:00
|
|
|
test 'ticket create' do
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: "some title\n äöüß",
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
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
|
2017-11-16 21:54:31 +00:00
|
|
|
article_inbound1 = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
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_inbound1 😍😍😍',
|
|
|
|
internal: false,
|
|
|
|
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')
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal(ticket.last_contact_at.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_customer_at.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket.last_contact_agent_at, 'ticket.last_contact_agent_at verify - inbound')
|
|
|
|
assert_nil(ticket.first_response_at, 'ticket.first_response_at verify - inbound')
|
|
|
|
assert_nil(ticket.close_at, 'ticket.close_at verify - inbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
# create inbound article #2
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 2.seconds
|
2017-11-16 21:54:31 +00:00
|
|
|
article_inbound2 = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
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,
|
|
|
|
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')
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal(ticket.last_contact_at.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_customer_at.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket.last_contact_agent_at, 'ticket.last_contact_agent_at verify - inbound')
|
|
|
|
assert_nil(ticket.first_response_at, 'ticket.first_response_at verify - inbound')
|
|
|
|
assert_nil(ticket.close_at, 'ticket.close_at verify - inbound')
|
2013-03-28 23:13:15 +00:00
|
|
|
|
|
|
|
# create note article
|
2017-11-16 21:54:31 +00:00
|
|
|
article_note = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket.id,
|
|
|
|
from: 'some person',
|
|
|
|
subject: "some\nnote",
|
|
|
|
body: "some\n message",
|
|
|
|
internal: true,
|
|
|
|
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')
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal(ticket.last_contact_at.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact verify - note')
|
|
|
|
assert_equal(ticket.last_contact_customer_at.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer_at verify - note')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket.last_contact_agent_at, 'ticket.last_contact_agent_at verify - note')
|
|
|
|
assert_nil(ticket.first_response_at, 'ticket.first_response_at verify - note')
|
|
|
|
assert_nil(ticket.close_at, 'ticket.close_at verify - note')
|
2013-03-28 23:13:15 +00:00
|
|
|
|
|
|
|
# create outbound article
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 2.seconds
|
2017-11-16 21:54:31 +00:00
|
|
|
article_outbound = Ticket::Article.create!(
|
2018-12-19 17:31:51 +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,
|
|
|
|
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')
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal(ticket.last_contact_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - outbound')
|
|
|
|
assert_equal(ticket.last_contact_customer_at.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer_at verify - outbound')
|
|
|
|
assert_equal(ticket.last_contact_agent_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent_at verify - outbound')
|
|
|
|
assert_equal(ticket.first_response_at.to_s, article_outbound.created_at.to_s, 'ticket.first_response_at verify - outbound')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket.close_at, 'ticket.close_at verify - outbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
# create inbound article #3
|
2017-11-16 21:54:31 +00:00
|
|
|
article_inbound3 = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
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,
|
|
|
|
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')
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal(ticket.last_contact_at.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_customer_at.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_agent_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent_at verify - outbound')
|
|
|
|
assert_equal(ticket.first_response_at.to_s, article_outbound.created_at.to_s, 'ticket.first_response_at verify - outbound')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket.close_at, 'ticket.close_at verify - outbound')
|
2015-10-30 10:05:51 +00:00
|
|
|
|
|
|
|
# create inbound article #4
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 2.seconds
|
2017-11-16 21:54:31 +00:00
|
|
|
article_inbound4 = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
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,
|
|
|
|
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')
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal(ticket.last_contact_at.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_customer_at.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
|
|
|
|
assert_equal(ticket.last_contact_agent_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent_at verify - outbound')
|
|
|
|
assert_equal(ticket.first_response_at.to_s, article_outbound.created_at.to_s, 'ticket.first_response_at verify - outbound')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket.close_at, 'ticket.close_at 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')
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal(ticket.last_contact_at.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - state update')
|
|
|
|
assert_equal(ticket.last_contact_customer_at.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact_customer_at verify - state update')
|
|
|
|
assert_equal(ticket.last_contact_agent_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent_at verify - state update')
|
|
|
|
assert_equal(ticket.first_response_at.to_s, article_outbound.created_at.to_s, 'ticket.first_response_at verify - state update')
|
|
|
|
assert(ticket.close_at, 'ticket.close_at 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')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket.pending_time)
|
2016-12-15 16:05:54 +00:00
|
|
|
|
|
|
|
# delete article
|
2017-11-16 21:54:31 +00:00
|
|
|
article_note = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket.id,
|
|
|
|
from: 'some person',
|
|
|
|
subject: 'some note',
|
|
|
|
body: 'some message',
|
|
|
|
internal: true,
|
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'note'),
|
2016-12-15 16:05:54 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
|
|
|
assert_equal(ticket.article_count, 7, 'ticket.article_count verify - note')
|
|
|
|
|
|
|
|
article_note.destroy
|
|
|
|
|
|
|
|
ticket = Ticket.find(ticket.id)
|
|
|
|
assert_equal(ticket.article_count, 6, 'ticket.article_count verify - note')
|
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')
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2013-03-22 07:11:20 +00:00
|
|
|
end
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
test 'ticket latest change' do
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'latest change 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
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
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
travel 1.minute
|
2015-02-25 20:52:14 +00:00
|
|
|
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket2 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'latest change 2',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
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
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
travel 1.minute
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
travel 1.minute
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
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)
|
2016-12-08 14:06:54 +00:00
|
|
|
ticket2.destroy
|
|
|
|
travel_back
|
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
|
2020-09-30 09:07:01 +00:00
|
|
|
Ticket.where.not(pending_time: nil).each do |ticket|
|
2016-02-26 12:56:36 +00:00
|
|
|
ticket.state = Ticket::State.lookup(name: 'closed')
|
|
|
|
ticket.save!
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-02-26 12:56:36 +00:00
|
|
|
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'pending close test',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'pending close'),
|
|
|
|
pending_time: Time.zone.now - 60,
|
|
|
|
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
|
2016-05-23 17:56:39 +00:00
|
|
|
|
|
|
|
test 'ticket subject' do
|
|
|
|
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'subject test 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2016-05-23 17:56:39 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-08-25 09:37:56 +00:00
|
|
|
assert_equal('subject test 1', ticket.title)
|
|
|
|
assert_equal("ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1'))
|
2018-05-18 10:59:08 +00:00
|
|
|
assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1', 'reply'))
|
|
|
|
assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build(' ABC subject test 1', 'reply'))
|
|
|
|
assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1 ', 'reply'))
|
|
|
|
assert_equal("FWD: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1 ', 'forward'))
|
2017-08-25 09:37:56 +00:00
|
|
|
ticket.destroy
|
|
|
|
|
|
|
|
Setting.set('ticket_hook_position', 'left')
|
|
|
|
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'subject test 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2017-08-25 09:37:56 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_equal('subject test 1', ticket.title)
|
|
|
|
assert_equal("[Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1'))
|
2018-05-18 10:59:08 +00:00
|
|
|
assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1', 'reply'))
|
|
|
|
assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build(' ABC subject test 1', 'reply'))
|
|
|
|
assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1 ', 'reply'))
|
|
|
|
assert_equal("FWD: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1 ', 'forward'))
|
2017-08-25 09:37:56 +00:00
|
|
|
ticket.destroy
|
|
|
|
|
|
|
|
Setting.set('ticket_hook_position', 'none')
|
|
|
|
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'subject test 1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2017-08-25 09:37:56 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_equal('subject test 1', ticket.title)
|
|
|
|
assert_equal('ABC subject test 1', ticket.subject_build('ABC subject test 1'))
|
2018-05-18 10:59:08 +00:00
|
|
|
assert_equal('RE: ABC subject test 1', ticket.subject_build('ABC subject test 1', 'reply'))
|
|
|
|
assert_equal('RE: ABC subject test 1', ticket.subject_build(' ABC subject test 1', 'reply'))
|
|
|
|
assert_equal('RE: ABC subject test 1', ticket.subject_build('ABC subject test 1 ', 'reply'))
|
|
|
|
assert_equal('FWD: ABC subject test 1', ticket.subject_build('ABC subject test 1 ', 'forward'))
|
2017-08-25 09:37:56 +00:00
|
|
|
ticket.destroy
|
2016-05-23 17:56:39 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-03-27 12:30:26 +00:00
|
|
|
test 'ticket followup number check' do
|
|
|
|
|
|
|
|
origin_backend = Setting.get('ticket_number')
|
|
|
|
Setting.set('ticket_number', 'Ticket::Number::Increment')
|
|
|
|
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'subject test 1234-1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2017-03-27 12:30:26 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_equal('subject test 1234-1', ticket1.title)
|
|
|
|
assert_equal("ABC subject test 1 [Ticket##{ticket1.number}]", ticket1.subject_build('ABC subject test 1'))
|
|
|
|
assert_equal(ticket1.id, Ticket::Number.check("Re: Help [Ticket##{ticket1.number}]").id)
|
|
|
|
|
|
|
|
Setting.set('ticket_number', 'Ticket::Number::Date')
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'subject test 1234-2',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2017-03-27 12:30:26 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_equal('subject test 1234-2', ticket1.title)
|
|
|
|
assert_equal("ABC subject test 1 [Ticket##{ticket1.number}]", ticket1.subject_build('ABC subject test 1'))
|
|
|
|
assert_equal(ticket1.id, Ticket::Number.check("Re: Help [Ticket##{ticket1.number}]").id)
|
|
|
|
|
|
|
|
Setting.set('ticket_number', origin_backend)
|
|
|
|
end
|
|
|
|
|
2017-03-10 05:34:51 +00:00
|
|
|
test 'article attachment helper 1' do
|
2016-07-11 23:32:20 +00:00
|
|
|
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'some article helper test1',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2016-07-11 23:32:20 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert(ticket1, 'ticket created')
|
|
|
|
|
|
|
|
# create inbound article #1
|
2017-11-16 21:54:31 +00:00
|
|
|
article1 = 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',
|
|
|
|
content_type: 'text/html',
|
|
|
|
body: 'some message article helper test1 <div><img style="width: 85.5px; height: 49.5px" src="cid:15.274327094.140938@zammad.example.com">asdasd<img src="cid:15.274327094.140939@zammad.example.com"><br>',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
2016-07-11 23:32:20 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
store1 = Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: 'content_file1_normally_should_be_an_image',
|
|
|
|
filename: 'some_file1.jpg',
|
|
|
|
preferences: {
|
2016-07-11 23:32:20 +00:00
|
|
|
'Content-Type' => 'image/jpeg',
|
|
|
|
'Mime-Type' => 'image/jpeg',
|
|
|
|
'Content-ID' => '15.274327094.140938@zammad.example.com',
|
|
|
|
'Content-Disposition' => 'inline'
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
store2 = Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: 'content_file2_normally_should_be_an_image',
|
|
|
|
filename: 'some_file2.jpg',
|
|
|
|
preferences: {
|
2016-07-11 23:32:20 +00:00
|
|
|
'Content-Type' => 'image/jpeg',
|
|
|
|
'Mime-Type' => 'image/jpeg',
|
|
|
|
'Content-ID' => '15.274327094.140939@zammad.example.com',
|
|
|
|
'Content-Disposition' => 'inline'
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
store3 = Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: 'content_file3',
|
|
|
|
filename: 'some_file3.txt',
|
|
|
|
preferences: {
|
2016-07-11 23:32:20 +00:00
|
|
|
'Content-Type' => 'text/stream',
|
|
|
|
'Mime-Type' => 'text/stream',
|
|
|
|
'Content-ID' => '15.274327094.99999@zammad.example.com',
|
|
|
|
'Content-Disposition' => 'inline'
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
2017-03-10 05:34:51 +00:00
|
|
|
article_attributes = Ticket::Article.insert_urls(article1.attributes_with_association_ids)
|
2016-07-11 23:32:20 +00:00
|
|
|
|
|
|
|
assert_no_match('15.274327094.140938@zammad.example.com', article_attributes['body'])
|
|
|
|
assert_no_match('15.274327094.140939@zammad.example.com', article_attributes['body'])
|
|
|
|
assert_no_match('15.274327094.99999@zammad.example.com', article_attributes['body'])
|
2016-07-11 23:45:46 +00:00
|
|
|
assert_match("api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store1.id}", article_attributes['body'])
|
|
|
|
assert_match("api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store2.id}", article_attributes['body'])
|
|
|
|
assert_no_match("api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store3.id}", article_attributes['body'])
|
2016-07-11 23:32:20 +00:00
|
|
|
|
|
|
|
article1 = Ticket::Article.find(article1.id)
|
|
|
|
attachments = article1.attachments_inline
|
|
|
|
assert_equal(2, attachments.length)
|
|
|
|
assert_equal(store1.id, attachments.first.id)
|
|
|
|
|
|
|
|
ticket1.destroy
|
2017-03-10 05:34:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'article attachment helper 2' do
|
|
|
|
|
2017-11-16 21:54:31 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'some article helper test2',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2017-03-10 05:34:51 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert(ticket1, 'ticket created')
|
|
|
|
|
|
|
|
# create inbound article #1
|
2017-11-16 21:54:31 +00:00
|
|
|
article1 = 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',
|
|
|
|
content_type: 'text/html',
|
|
|
|
body: 'some message article helper test2 <div><img src="cid:15.274327094.140938@zammad.example.com">asdasd<img border="0" width="60" height="19" src="cid:15.274327094.140939@zammad.example.com" alt="Beschreibung: Beschreibung: efqmLogo"><br>',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
|
|
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
2017-03-10 05:34:51 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2016-07-11 23:32:20 +00:00
|
|
|
|
2017-03-10 05:34:51 +00:00
|
|
|
store1 = Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: 'content_file1_normally_should_be_an_image',
|
|
|
|
filename: 'some_file1.jpg',
|
|
|
|
preferences: {
|
2017-03-10 05:34:51 +00:00
|
|
|
'Content-Type' => 'image/jpeg',
|
|
|
|
'Mime-Type' => 'image/jpeg',
|
|
|
|
'Content-ID' => '15.274327094.140938@zammad.example.com',
|
|
|
|
'Content-Disposition' => 'inline'
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
store2 = Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: 'content_file2_normally_should_be_an_image',
|
|
|
|
filename: 'some_file2.jpg',
|
|
|
|
preferences: {
|
2017-03-10 05:34:51 +00:00
|
|
|
'Content-Type' => 'image/jpeg',
|
|
|
|
'Mime-Type' => 'image/jpeg',
|
|
|
|
'Content-ID' => '15.274327094.140939@zammad.example.com',
|
|
|
|
'Content-Disposition' => 'inline'
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
store3 = Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: 'content_file3',
|
|
|
|
filename: 'some_file3.txt',
|
|
|
|
preferences: {
|
2017-03-10 05:34:51 +00:00
|
|
|
'Content-Type' => 'text/stream',
|
|
|
|
'Mime-Type' => 'text/stream',
|
|
|
|
'Content-ID' => '15.274327094.99999@zammad.example.com',
|
|
|
|
'Content-Disposition' => 'inline'
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
article_attributes = Ticket::Article.insert_urls(article1.attributes_with_association_ids)
|
|
|
|
|
|
|
|
assert_no_match('15.274327094.140938@zammad.example.com', article_attributes['body'])
|
|
|
|
assert_no_match('15.274327094.140939@zammad.example.com', article_attributes['body'])
|
|
|
|
assert_no_match('15.274327094.99999@zammad.example.com', article_attributes['body'])
|
|
|
|
assert_match("api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store1.id}", article_attributes['body'])
|
|
|
|
assert_match("api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store2.id}", article_attributes['body'])
|
|
|
|
assert_no_match("api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store3.id}", article_attributes['body'])
|
|
|
|
|
|
|
|
article1 = Ticket::Article.find(article1.id)
|
|
|
|
attachments = article1.attachments_inline
|
|
|
|
assert_equal(2, attachments.length)
|
|
|
|
assert_equal(store1.id, attachments.first.id)
|
|
|
|
|
|
|
|
ticket1.destroy
|
2016-07-11 23:32:20 +00:00
|
|
|
end
|
2017-03-10 05:34:51 +00:00
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|