ticket_test.rb 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketTest < ActiveSupport::TestCase
  4. test 'ticket create' do
  5. ticket = Ticket.create(
  6. :title => 'some title äöüß',
  7. :group => Group.lookup( :name => 'Users'),
  8. :customer_id => 2,
  9. :state => Ticket::State.lookup( :name => 'new' ),
  10. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  11. :updated_by_id => 1,
  12. :created_by_id => 1,
  13. )
  14. assert( ticket, "ticket created" )
  15. assert_equal( ticket.title, 'some title äöüß', 'ticket.title verify' )
  16. assert_equal( ticket.group.name, 'Users', 'ticket.group verify' )
  17. assert_equal( ticket.state.name, 'new', 'ticket.state verify' )
  18. # create inbound article
  19. article_inbound = Ticket::Article.create(
  20. :ticket_id => ticket.id,
  21. :from => 'some_sender@example.com',
  22. :to => 'some_recipient@example.com',
  23. :subject => 'some subject',
  24. :message_id => 'some@id',
  25. :body => 'some message article_inbound 😍😍😍',
  26. :internal => false,
  27. :sender => Ticket::Article::Sender.where(:name => 'Customer').first,
  28. :type => Ticket::Article::Type.where(:name => 'email').first,
  29. :updated_by_id => 1,
  30. :created_by_id => 1,
  31. )
  32. assert_equal( article_inbound.body, 'some message article_inbound 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound' )
  33. ticket = Ticket.find(ticket.id)
  34. assert_equal( ticket.article_count, 1, 'ticket.article_count verify - inbound' )
  35. assert_equal( ticket.last_contact.to_s, article_inbound.created_at.to_s, 'ticket.last_contact verify - inbound' )
  36. assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - inbound' )
  37. assert_equal( ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - inbound' )
  38. assert_equal( ticket.first_response, nil, 'ticket.first_response verify - inbound' )
  39. assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' )
  40. # create note article
  41. article_note = Ticket::Article.create(
  42. :ticket_id => ticket.id,
  43. :from => 'some persion',
  44. :subject => 'some note',
  45. :body => 'some message',
  46. :internal => true,
  47. :sender => Ticket::Article::Sender.where(:name => 'Agent').first,
  48. :type => Ticket::Article::Type.where(:name => 'note').first,
  49. :updated_by_id => 1,
  50. :created_by_id => 1,
  51. )
  52. ticket = Ticket.find(ticket.id)
  53. assert_equal( ticket.article_count, 2, 'ticket.article_count verify - note' )
  54. assert_equal( ticket.last_contact.to_s, article_inbound.created_at.to_s, 'ticket.last_contact verify - note' )
  55. assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - note' )
  56. assert_equal( ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - note' )
  57. assert_equal( ticket.first_response, nil, 'ticket.first_response verify - note' )
  58. assert_equal( ticket.close_time, nil, 'ticket.close_time verify - note' )
  59. # create outbound article
  60. sleep 10
  61. article_outbound = Ticket::Article.create(
  62. :ticket_id => ticket.id,
  63. :from => 'some_recipient@example.com',
  64. :to => 'some_sender@example.com',
  65. :subject => 'some subject',
  66. :message_id => 'some@id2',
  67. :body => 'some message 2',
  68. :internal => false,
  69. :sender => Ticket::Article::Sender.where(:name => 'Agent').first,
  70. :type => Ticket::Article::Type.where(:name => 'email').first,
  71. :updated_by_id => 1,
  72. :created_by_id => 1,
  73. )
  74. ticket = Ticket.find(ticket.id)
  75. assert_equal( ticket.article_count, 3, 'ticket.article_count verify - outbound' )
  76. assert_equal( ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - outbound' )
  77. assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - outbound' )
  78. assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - outbound' )
  79. assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound' )
  80. assert_equal( ticket.close_time, nil, 'ticket.close_time verify - outbound' )
  81. ticket.state_id = Ticket::State.where(:name => 'closed').first.id
  82. ticket.save
  83. ticket = Ticket.find(ticket.id)
  84. assert_equal( ticket.article_count, 3, 'ticket.article_count verify - state update' )
  85. assert_equal( ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - state update' )
  86. assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - state update' )
  87. assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - state update' )
  88. assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - state update' )
  89. assert( ticket.close_time, 'ticket.close_time verify - state update' )
  90. delete = ticket.destroy
  91. assert( delete, "ticket destroy" )
  92. end
  93. test 'ticket sla' do
  94. # cleanup
  95. delete = Sla.destroy_all
  96. assert( delete, "sla destroy_all" )
  97. delete = Ticket.destroy_all
  98. assert( delete, "ticket destroy_all" )
  99. ticket = Ticket.create(
  100. :title => 'some title äöüß',
  101. :group => Group.lookup( :name => 'Users'),
  102. :customer_id => 2,
  103. :state => Ticket::State.lookup( :name => 'new' ),
  104. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  105. :created_at => '2013-03-21 09:30:00 UTC',
  106. :updated_at => '2013-03-21 09:30:00 UTC',
  107. :updated_by_id => 1,
  108. :created_by_id => 1,
  109. )
  110. assert( ticket, "ticket created" )
  111. assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify' )
  112. sla = Sla.create(
  113. :name => 'test sla 1',
  114. :condition => {},
  115. :data => {
  116. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  117. "beginning_of_workday" => "8:00",
  118. "end_of_workday" => "18:00",
  119. },
  120. :first_response_time => 120,
  121. :update_time => 180,
  122. :close_time => 240,
  123. :active => true,
  124. :updated_by_id => 1,
  125. :created_by_id => 1,
  126. )
  127. ticket = Ticket.find(ticket.id)
  128. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
  129. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
  130. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_time_escal_date verify 1' )
  131. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_time_escal_date verify 1' )
  132. delete = sla.destroy
  133. assert( delete, "sla destroy 1" )
  134. sla = Sla.create(
  135. :name => 'test sla 2',
  136. :condition => { "tickets.priority_id" =>["1", "2", "3"] },
  137. :data => {
  138. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  139. "beginning_of_workday" => "8:00",
  140. "end_of_workday" => "18:00",
  141. },
  142. :first_response_time => 60,
  143. :update_time => 120,
  144. :close_time => 180,
  145. :active => true,
  146. :updated_by_id => 1,
  147. :created_by_id => 1,
  148. )
  149. ticket = Ticket.find(ticket.id)
  150. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_time verify 2' )
  151. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 2' )
  152. assert_equal( ticket.first_response, nil, 'ticket.first_response verify 2' )
  153. assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 2' )
  154. assert_equal( ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 2' )
  155. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_time_escal_date verify 2' )
  156. assert_equal( ticket.update_time_in_min, nil, 'ticket.update_time_in_min verify 2' )
  157. assert_equal( ticket.update_time_diff_in_min, nil, 'ticket.update_time_diff_in_min verify 2' )
  158. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 2' )
  159. assert_equal( ticket.close_time_in_min, nil, 'ticket.close_time_in_min verify 2' )
  160. assert_equal( ticket.close_time_diff_in_min, nil, 'ticket.close_time_diff_in_min verify 2' )
  161. # set first response in time
  162. ticket.update_attributes(
  163. :first_response => '2013-03-21 10:00:00 UTC',
  164. )
  165. puts ticket.inspect
  166. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 3' )
  167. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 3' )
  168. assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 10:00:00 UTC', 'ticket.first_response verify 3' )
  169. assert_equal( ticket.first_response_in_min, 30, 'ticket.first_response_in_min verify 3' )
  170. assert_equal( ticket.first_response_diff_in_min, 30, 'ticket.first_response_diff_in_min verify 3' )
  171. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_time_escal_date verify 3' )
  172. assert_equal( ticket.update_time_in_min, nil, 'ticket.update_time_in_min verify 3' )
  173. assert_equal( ticket.update_time_diff_in_min, nil, 'ticket.update_time_diff_in_min verify 3' )
  174. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 3' )
  175. assert_equal( ticket.close_time_in_min, nil, 'ticket.close_time_in_min verify 3' )
  176. assert_equal( ticket.close_time_diff_in_min, nil, 'ticket.close_time_diff_in_min verify 3' )
  177. # set first reponse over time
  178. ticket.update_attributes(
  179. :first_response => '2013-03-21 14:00:00 UTC',
  180. )
  181. puts ticket.inspect
  182. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 4' )
  183. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 4' )
  184. assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 4' )
  185. assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 4' )
  186. assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 4' )
  187. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_time_escal_date verify 4' )
  188. assert_equal( ticket.update_time_in_min, nil, 'ticket.update_time_in_min verify 4' )
  189. assert_equal( ticket.update_time_diff_in_min, nil, 'ticket.update_time_diff_in_min verify 4' )
  190. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 4' )
  191. assert_equal( ticket.close_time_in_min, nil, 'ticket.close_time_in_min verify 4' )
  192. assert_equal( ticket.close_time_diff_in_min, nil, 'ticket.close_time_diff_in_min verify 4' )
  193. # set update time in time
  194. ticket.update_attributes(
  195. :last_contact_agent => '2013-03-21 11:00:00 UTC',
  196. )
  197. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_time verify 5' )
  198. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 5' )
  199. assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 5' )
  200. assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 5' )
  201. assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 5' )
  202. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 13:00:00 UTC', 'ticket.update_time_escal_date verify 5' )
  203. assert_equal( ticket.update_time_in_min, 90, 'ticket.update_time_in_min verify 5' )
  204. assert_equal( ticket.update_time_diff_in_min, 30, 'ticket.update_time_diff_in_min verify 5' )
  205. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 5' )
  206. assert_equal( ticket.close_time_in_min, nil, 'ticket.close_time_in_min verify 5' )
  207. assert_equal( ticket.close_time_diff_in_min, nil, 'ticket.close_time_diff_in_min verify 5' )
  208. # set update time over time
  209. ticket.update_attributes(
  210. :last_contact_agent => '2013-03-21 12:00:00 UTC',
  211. )
  212. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_time verify 6' )
  213. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 6' )
  214. assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 6' )
  215. assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6' )
  216. assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6' )
  217. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_time_escal_date verify 6' )
  218. assert_equal( ticket.update_time_in_min, 150, 'ticket.update_time_in_min verify 6' )
  219. assert_equal( ticket.update_time_diff_in_min, -30, 'ticket.update_time_diff_in_min verify 6' )
  220. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 6' )
  221. assert_equal( ticket.close_time_in_min, nil, 'ticket.close_time_in_min verify 6' )
  222. assert_equal( ticket.close_time_diff_in_min, nil, 'ticket.close_time_diff_in_min verify 6' )
  223. # set close time in time
  224. ticket.update_attributes(
  225. :close_time => '2013-03-21 11:30:00 UTC',
  226. )
  227. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.escalation_time verify 7' )
  228. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 7' )
  229. assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 7' )
  230. assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 7' )
  231. assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 7' )
  232. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_time_escal_date verify 7' )
  233. assert_equal( ticket.update_time_in_min, 150, 'ticket.update_time_in_min verify 7' )
  234. assert_equal( ticket.update_time_diff_in_min, -30, 'ticket.update_time_diff_in_min verify 7' )
  235. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 7' )
  236. assert_equal( ticket.close_time_in_min, 120, 'ticket.close_time_in_min verify 7' )
  237. assert_equal( ticket.close_time_diff_in_min, 60, 'ticket.close_time_diff_in_min verify 7' )
  238. # set close time over time
  239. ticket.update_attributes(
  240. :close_time => '2013-03-21 13:00:00 UTC',
  241. )
  242. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.escalation_time verify 8' )
  243. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 8' )
  244. assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 8' )
  245. assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 8' )
  246. assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 8' )
  247. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_time_escal_date verify 8' )
  248. assert_equal( ticket.update_time_in_min, 150, 'ticket.update_time_in_min verify 8' )
  249. assert_equal( ticket.update_time_diff_in_min, -30, 'ticket.update_time_diff_in_min verify 8' )
  250. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 8' )
  251. assert_equal( ticket.close_time_in_min, 210, 'ticket.close_time_in_min verify 8' )
  252. assert_equal( ticket.close_time_diff_in_min, -30, 'ticket.close_time_diff_in_min verify 8' )
  253. # set close time over time
  254. ticket.update_attributes(
  255. :state => Ticket::State.lookup( :name => 'closed' )
  256. )
  257. assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 9' )
  258. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 9' )
  259. assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 9' )
  260. assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 9' )
  261. assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 9' )
  262. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_time_escal_date verify 9' )
  263. assert_equal( ticket.update_time_in_min, 150, 'ticket.update_time_in_min verify 9' )
  264. assert_equal( ticket.update_time_diff_in_min, -30, 'ticket.update_time_diff_in_min verify 9' )
  265. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 9' )
  266. assert_equal( ticket.close_time_in_min, 210, 'ticket.close_time_in_min verify 9' )
  267. assert_equal( ticket.close_time_diff_in_min, -30, 'ticket.close_time_diff_in_min verify 9' )
  268. delete = ticket.destroy
  269. assert( delete, "ticket destroy" )
  270. ticket = Ticket.create(
  271. :title => 'some title äöüß',
  272. :group => Group.lookup( :name => 'Users'),
  273. :customer_id => 2,
  274. :state => Ticket::State.lookup( :name => 'new' ),
  275. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  276. :updated_by_id => 1,
  277. :created_by_id => 1,
  278. :created_at => '2013-03-28 23:49:00 UTC',
  279. :updated_at => '2013-03-28 23:49:00 UTC',
  280. )
  281. assert( ticket, "ticket created" )
  282. assert_equal( ticket.title, 'some title äöüß', 'ticket.title verify' )
  283. assert_equal( ticket.group.name, 'Users', 'ticket.group verify' )
  284. assert_equal( ticket.state.name, 'new', 'ticket.state verify' )
  285. # create inbound article
  286. article_inbound = Ticket::Article.create(
  287. :ticket_id => ticket.id,
  288. :from => 'some_sender@example.com',
  289. :to => 'some_recipient@example.com',
  290. :subject => 'some subject',
  291. :message_id => 'some@id',
  292. :body => 'some message',
  293. :internal => false,
  294. :sender => Ticket::Article::Sender.where(:name => 'Customer').first,
  295. :type => Ticket::Article::Type.where(:name => 'email').first,
  296. :updated_by_id => 1,
  297. :created_by_id => 1,
  298. :created_at => '2013-03-28 23:49:00 UTC',
  299. :updated_at => '2013-03-28 23:49:00 UTC',
  300. )
  301. ticket = Ticket.find(ticket.id)
  302. assert_equal( ticket.article_count, 1, 'ticket.article_count verify - inbound' )
  303. assert_equal( ticket.last_contact.to_s, article_inbound.created_at.to_s, 'ticket.last_contact verify - inbound' )
  304. assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - inbound' )
  305. assert_equal( ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - inbound' )
  306. assert_equal( ticket.first_response, nil, 'ticket.first_response verify - inbound' )
  307. assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' )
  308. # create outbound article
  309. article_outbound = Ticket::Article.create(
  310. :ticket_id => ticket.id,
  311. :from => 'some_recipient@example.com',
  312. :to => 'some_sender@example.com',
  313. :subject => 'some subject',
  314. :message_id => 'some@id2',
  315. :body => 'some message 2',
  316. :internal => false,
  317. :sender => Ticket::Article::Sender.where(:name => 'Agent').first,
  318. :type => Ticket::Article::Type.where(:name => 'email').first,
  319. :updated_by_id => 1,
  320. :created_by_id => 1,
  321. :created_at => '2013-03-29 08:00:03 UTC',
  322. :updated_at => '2013-03-29 08:00:03 UTC',
  323. )
  324. ticket = Ticket.find(ticket.id)
  325. assert_equal( ticket.article_count, 2, 'ticket.article_count verify - outbound' )
  326. assert_equal( ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - outbound' )
  327. assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - outbound' )
  328. assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - outbound' )
  329. assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound' )
  330. assert_equal( ticket.first_response_in_min, 0, 'ticket.first_response_in_min verify - outbound' )
  331. assert_equal( ticket.first_response_diff_in_min, 60, 'ticket.first_response_diff_in_min verify - outbound' )
  332. assert_equal( ticket.close_time, nil, 'ticket.close_time verify - outbound' )
  333. delete = ticket.destroy
  334. assert( delete, "ticket destroy" )
  335. ticket = Ticket.create(
  336. :title => 'some title äöüß',
  337. :group => Group.lookup( :name => 'Users'),
  338. :customer_id => 2,
  339. :state => Ticket::State.lookup( :name => 'new' ),
  340. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  341. :updated_by_id => 1,
  342. :created_by_id => 1,
  343. :created_at => '2013-03-28 23:49:00 UTC',
  344. :updated_at => '2013-03-28 23:49:00 UTC',
  345. )
  346. assert( ticket, "ticket created" )
  347. assert_equal( ticket.title, 'some title äöüß', 'ticket.title verify' )
  348. assert_equal( ticket.group.name, 'Users', 'ticket.group verify' )
  349. assert_equal( ticket.state.name, 'new', 'ticket.state verify' )
  350. # create inbound article
  351. article_inbound = Ticket::Article.create(
  352. :ticket_id => ticket.id,
  353. :from => 'some_sender@example.com',
  354. :subject => 'some subject',
  355. :message_id => 'some@id',
  356. :body => 'some message',
  357. :internal => false,
  358. :sender => Ticket::Article::Sender.where(:name => 'Customer').first,
  359. :type => Ticket::Article::Type.where(:name => 'phone').first,
  360. :updated_by_id => 1,
  361. :created_by_id => 1,
  362. :created_at => '2013-03-28 23:49:00 UTC',
  363. :updated_at => '2013-03-28 23:49:00 UTC',
  364. )
  365. ticket = Ticket.find(ticket.id)
  366. assert_equal( ticket.article_count, 1, 'ticket.article_count verify - inbound' )
  367. assert_equal( ticket.last_contact.to_s, article_inbound.created_at.to_s, 'ticket.last_contact verify - inbound' )
  368. assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - inbound' )
  369. assert_equal( ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - inbound' )
  370. assert_equal( ticket.first_response.to_s, article_inbound.created_at.to_s, 'ticket.first_response verify - inbound' )
  371. assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' )
  372. delete = sla.destroy
  373. assert( delete, "sla destroy" )
  374. delete = sla.destroy
  375. assert( delete, "sla destroy" )
  376. end
  377. test 'ticket sla + timezone' do
  378. # cleanup
  379. delete = Sla.destroy_all
  380. assert( delete, "sla destroy_all" )
  381. delete = Ticket.destroy_all
  382. assert( delete, "ticket destroy_all" )
  383. ticket = Ticket.create(
  384. :title => 'some title äöüß',
  385. :group => Group.lookup( :name => 'Users'),
  386. :customer_id => 2,
  387. :state => Ticket::State.lookup( :name => 'new' ),
  388. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  389. :created_at => '2013-03-21 09:30:00 UTC',
  390. :updated_at => '2013-03-21 09:30:00 UTC',
  391. :updated_by_id => 1,
  392. :created_by_id => 1,
  393. )
  394. assert( ticket, "ticket created" )
  395. assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify' )
  396. # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 8:00-17:00
  397. sla = Sla.create(
  398. :name => 'test sla 1',
  399. :condition => {},
  400. :data => {
  401. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  402. "beginning_of_workday" => "9:00",
  403. "end_of_workday" => "18:00",
  404. },
  405. :timezone => 'Europe/Berlin',
  406. :first_response_time => 120,
  407. :update_time => 180,
  408. :close_time => 240,
  409. :active => true,
  410. :updated_by_id => 1,
  411. :created_by_id => 1,
  412. )
  413. ticket = Ticket.find(ticket.id)
  414. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
  415. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
  416. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_time_escal_date verify 1' )
  417. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_time_escal_date verify 1' )
  418. delete = sla.destroy
  419. assert( delete, "sla destroy" )
  420. delete = ticket.destroy
  421. assert( delete, "ticket destroy" )
  422. ticket = Ticket.create(
  423. :title => 'some title äöüß',
  424. :group => Group.lookup( :name => 'Users'),
  425. :customer_id => 2,
  426. :state => Ticket::State.lookup( :name => 'new' ),
  427. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  428. :created_at => '2013-10-21 09:30:00 UTC',
  429. :updated_at => '2013-10-21 09:30:00 UTC',
  430. :updated_by_id => 1,
  431. :created_by_id => 1,
  432. )
  433. assert( ticket, "ticket created" )
  434. assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify' )
  435. # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 7:00-16:00
  436. sla = Sla.create(
  437. :name => 'test sla 1',
  438. :condition => {},
  439. :data => {
  440. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  441. "beginning_of_workday" => "9:00",
  442. "end_of_workday" => "18:00",
  443. },
  444. :timezone => 'Europe/Berlin',
  445. :first_response_time => 120,
  446. :update_time => 180,
  447. :close_time => 240,
  448. :active => true,
  449. :updated_by_id => 1,
  450. :created_by_id => 1,
  451. )
  452. ticket = Ticket.find(ticket.id)
  453. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
  454. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
  455. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-10-21 12:30:00 UTC', 'ticket.update_time_escal_date verify 1' )
  456. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-10-21 13:30:00 UTC', 'ticket.close_time_escal_date verify 1' )
  457. delete = ticket.destroy
  458. assert( delete, "ticket destroy" )
  459. delete = sla.destroy
  460. assert( delete, "sla destroy" )
  461. ticket = Ticket.create(
  462. :title => 'some title äöüß',
  463. :group => Group.lookup( :name => 'Users'),
  464. :customer_id => 2,
  465. :state => Ticket::State.lookup( :name => 'new' ),
  466. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  467. :created_at => '2013-10-21 06:30:00 UTC',
  468. :updated_at => '2013-10-21 06:30:00 UTC',
  469. :updated_by_id => 1,
  470. :created_by_id => 1,
  471. )
  472. assert( ticket, "ticket created" )
  473. assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify' )
  474. # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 7:00-16:00
  475. sla = Sla.create(
  476. :name => 'test sla 1',
  477. :condition => {},
  478. :data => {
  479. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  480. "beginning_of_workday" => "9:00",
  481. "end_of_workday" => "18:00",
  482. },
  483. :timezone => 'Europe/Berlin',
  484. :first_response_time => 120,
  485. :update_time => 180,
  486. :close_time => 240,
  487. :active => true,
  488. :updated_by_id => 1,
  489. :created_by_id => 1,
  490. )
  491. ticket = Ticket.find(ticket.id)
  492. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-10-21 09:00:00 UTC', 'ticket.escalation_time verify 1' )
  493. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 09:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
  494. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-10-21 10:00:00 UTC', 'ticket.update_time_escal_date verify 1' )
  495. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-10-21 11:00:00 UTC', 'ticket.close_time_escal_date verify 1' )
  496. delete = sla.destroy
  497. assert( delete, "sla destroy" )
  498. delete = ticket.destroy
  499. assert( delete, "ticket destroy" )
  500. end
  501. test 'ticket escalation suspend' do
  502. ticket = Ticket.create(
  503. :title => 'some title äöüß3',
  504. :group => Group.lookup( :name => 'Users'),
  505. :customer_id => 2,
  506. :state => Ticket::State.lookup( :name => 'new' ),
  507. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  508. :created_at => '2013-06-04 09:00:00 UTC',
  509. :updated_at => '2013-06-04 09:00:00 UTC',
  510. :updated_by_id => 1,
  511. :created_by_id => 1,
  512. )
  513. assert( ticket, 'ticket created' )
  514. # set ticket at 10:00 to pending
  515. History.add(
  516. :history_type => 'updated',
  517. :history_object => 'Ticket',
  518. :history_attribute => 'state',
  519. :o_id => ticket.id,
  520. :id_to => 3,
  521. :id_from => 2,
  522. :value_from => 'open',
  523. :value_to => 'pending',
  524. :created_by_id => 1,
  525. :created_at => '2013-06-04 10:00:00 UTC',
  526. :updated_at => '2013-06-04 10:00:00 UTC',
  527. )
  528. # set ticket at 10:30 to open
  529. History.add(
  530. :history_type => 'updated',
  531. :history_object => 'Ticket',
  532. :history_attribute => 'state',
  533. :o_id => ticket.id,
  534. :id_to => 2,
  535. :id_from => 3,
  536. :value_from => 'pending',
  537. :value_to => 'open',
  538. :created_by_id => 1,
  539. :created_at => '2013-06-04 10:30:00 UTC',
  540. :updated_at => '2013-06-04 10:30:00 UTC'
  541. )
  542. # set update time
  543. ticket.update_attributes(
  544. :last_contact_agent => '2013-06-04 10:15:00 UTC',
  545. )
  546. # set first response time
  547. ticket.update_attributes(
  548. :first_response => '2013-06-04 10:45:00 UTC',
  549. )
  550. # set ticket from 11:30 to closed
  551. History.add(
  552. :history_type => 'updated',
  553. :history_object => 'Ticket',
  554. :history_attribute => 'state',
  555. :o_id => ticket.id,
  556. :id_to => 3,
  557. :id_from => 2,
  558. :value_from => 'open',
  559. :value_to => 'closed',
  560. :created_by_id => 1,
  561. :created_at => '2013-06-04 12:00:00 UTC',
  562. :updated_at => '2013-06-04 12:00:00 UTC'
  563. )
  564. ticket.update_attributes(
  565. :close_time => '2013-06-04 12:00:00 UTC',
  566. )
  567. # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 7:00-16:00
  568. sla = Sla.create(
  569. :name => 'test sla 1',
  570. :condition => {},
  571. :data => {
  572. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  573. "beginning_of_workday" => "9:00",
  574. "end_of_workday" => "18:00",
  575. },
  576. :timezone => 'Europe/Berlin',
  577. :first_response_time => 120,
  578. :update_time => 180,
  579. :close_time => 250,
  580. :active => true,
  581. :updated_by_id => 1,
  582. :created_by_id => 1,
  583. )
  584. ticket = Ticket.find(ticket.id)
  585. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_time verify 1' )
  586. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
  587. assert_equal( ticket.first_response_in_min, 75, 'ticket.first_response_in_min verify 3' )
  588. assert_equal( ticket.first_response_diff_in_min, 45, 'ticket.first_response_diff_in_min verify 3' )
  589. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.update_time_escal_date verify 1' )
  590. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-06-04 13:40:00 UTC', 'ticket.close_time_escal_date verify 1' )
  591. assert_equal( ticket.close_time_in_min, 150, 'ticket.close_time_in_min verify 3' )
  592. assert_equal( ticket.close_time_diff_in_min, 100, 'ticket.close_time_diff_in_min# verify 3' )
  593. delete = sla.destroy
  594. assert( delete, "sla destroy" )
  595. delete = ticket.destroy
  596. assert( delete, "ticket destroy" )
  597. # test Ticket created in state pending and closed without reopen or state change
  598. ticket = Ticket.create(
  599. :title => 'some title äöüß3',
  600. :group => Group.lookup( :name => 'Users'),
  601. :customer_id => 2,
  602. :state => Ticket::State.lookup( :name => 'pending' ),
  603. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  604. :created_at => '2013-06-04 09:00:00 UTC',
  605. :updated_at => '2013-06-04 09:00:00 UTC',
  606. :updated_by_id => 1,
  607. :created_by_id => 1,
  608. )
  609. assert( ticket, 'ticket created' )
  610. # set ticket from 11:30 to closed
  611. History.add(
  612. :history_type => 'updated',
  613. :history_object => 'Ticket',
  614. :history_attribute => 'state',
  615. :o_id => ticket.id,
  616. :id_to => 4,
  617. :id_from => 3,
  618. :value_from => 'pending',
  619. :value_to => 'closed',
  620. :created_by_id => 1,
  621. :created_at => '2013-06-04 12:00:00 UTC',
  622. :updated_at => '2013-06-04 12:00:00 UTC',
  623. )
  624. ticket.update_attributes(
  625. :close_time => '2013-06-04 12:00:00 UTC',
  626. )
  627. sla = Sla.create(
  628. :name => 'test sla 1',
  629. :condition => {},
  630. :data => {
  631. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  632. "beginning_of_workday" => "9:00",
  633. "end_of_workday" => "18:00",
  634. },
  635. :first_response_time => 120,
  636. :update_time => 180,
  637. :close_time => 240,
  638. :active => true,
  639. :updated_by_id => 1,
  640. :created_by_id => 1,
  641. )
  642. ticket = Ticket.find(ticket.id)
  643. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.escalation_time verify 1' )
  644. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
  645. assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
  646. assert_equal( ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3' )
  647. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-06-04 15:00:00 UTC', 'ticket.update_time_escal_date verify 1' )
  648. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-06-04 16:00:00 UTC', 'ticket.close_time_escal_date verify 1' )
  649. assert_equal( ticket.close_time_in_min, 0, 'ticket.close_time_in_min verify 3' )
  650. assert_equal( ticket.close_time_diff_in_min, 240, 'ticket.close_time_diff_in_min# verify 3' )
  651. delete = sla.destroy
  652. assert( delete, "sla destroy" )
  653. delete = ticket.destroy
  654. assert( delete, "ticket destroy" )
  655. # test Ticket created in state pending, changed state to openen, back to pending and closed
  656. ticket = Ticket.create(
  657. :title => 'some title äöüß3',
  658. :group => Group.lookup( :name => 'Users'),
  659. :customer_id => 2,
  660. :state => Ticket::State.lookup( :name => 'pending' ),
  661. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  662. :created_at => '2013-06-04 09:00:00 UTC',
  663. :updated_at => '2013-06-04 09:00:00 UTC',
  664. :updated_by_id => 1,
  665. :created_by_id => 1,
  666. )
  667. assert( ticket, 'ticket created' )
  668. # state change to open 10:30
  669. History.add(
  670. :history_type => 'updated',
  671. :history_object => 'Ticket',
  672. :history_attribute => 'state',
  673. :o_id => ticket.id,
  674. :id_to => 2,
  675. :id_from => 3,
  676. :value_from => 'pending',
  677. :value_to => 'open',
  678. :created_by_id => 1,
  679. :created_at => '2013-06-04 10:30:00 UTC',
  680. :updated_at => '2013-06-04 10:30:00 UTC',
  681. )
  682. # state change to pending 11:00
  683. History.add(
  684. :history_type => 'updated',
  685. :history_object => 'Ticket',
  686. :history_attribute => 'state',
  687. :o_id => ticket.id,
  688. :id_to => 3,
  689. :id_from => 2,
  690. :value_from => 'open',
  691. :value_to => 'pending',
  692. :created_by_id => 1,
  693. :created_at => '2013-06-04 11:00:00 UTC',
  694. :updated_at => '2013-06-04 11:00:00 UTC',
  695. )
  696. # set ticket from 12:00 to closed
  697. History.add(
  698. :history_type => 'updated',
  699. :history_object => 'Ticket',
  700. :history_attribute => 'state',
  701. :o_id => ticket.id,
  702. :id_to => 4,
  703. :id_from => 3,
  704. :value_from => 'pending',
  705. :value_to => 'closed',
  706. :created_by_id => 1,
  707. :created_at => '2013-06-04 12:00:00 UTC',
  708. :updated_at => '2013-06-04 12:00:00 UTC',
  709. )
  710. ticket.update_attributes(
  711. :close_time => '2013-06-04 12:00:00 UTC',
  712. )
  713. sla = Sla.create(
  714. :name => 'test sla 1',
  715. :condition => {},
  716. :data => {
  717. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  718. "beginning_of_workday" => "9:00",
  719. "end_of_workday" => "18:00",
  720. },
  721. :first_response_time => 120,
  722. :update_time => 180,
  723. :close_time => 240,
  724. :active => true,
  725. :updated_by_id => 1,
  726. :created_by_id => 1,
  727. )
  728. ticket = Ticket.find(ticket.id)
  729. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_time verify 1' )
  730. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
  731. assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
  732. assert_equal( ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3' )
  733. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-06-04 14:30:00 UTC', 'ticket.update_time_escal_date verify 1' )
  734. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-06-04 15:30:00 UTC', 'ticket.close_time_escal_date verify 1' )
  735. assert_equal( ticket.close_time_in_min, 30, 'ticket.close_time_in_min verify 3' )
  736. assert_equal( ticket.close_time_diff_in_min, 210, 'ticket.close_time_diff_in_min# verify 3' )
  737. delete = sla.destroy
  738. assert( delete, "sla destroy" )
  739. delete = ticket.destroy
  740. assert( delete, "ticket destroy" )
  741. ### Test Ticket created in state pending, changed state to openen, back to pending and back to open then
  742. ### close ticket
  743. ticket = Ticket.create(
  744. :title => 'some title äöüß3',
  745. :group => Group.lookup( :name => 'Users'),
  746. :customer_id => 2,
  747. :state => Ticket::State.lookup( :name => 'pending' ),
  748. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  749. :created_at => '2013-06-04 09:00:00 UTC',
  750. :updated_at => '2013-06-04 09:00:00 UTC',
  751. :updated_by_id => 1,
  752. :created_by_id => 1,
  753. )
  754. assert( ticket, 'ticket created' )
  755. # state change to open from pending
  756. History.add(
  757. :history_type => 'updated',
  758. :history_object => 'Ticket',
  759. :history_attribute => 'state',
  760. :o_id => ticket.id,
  761. :id_to => 2,
  762. :id_from => 3,
  763. :value_from => 'pending',
  764. :value_to => 'open',
  765. :created_by_id => 1,
  766. :created_at => '2013-06-04 10:30:00 UTC',
  767. :updated_at => '2013-06-04 10:30:00 UTC',
  768. )
  769. # state change to pending from open 11:00
  770. History.add(
  771. :history_type => 'updated',
  772. :history_object => 'Ticket',
  773. :history_attribute => 'state',
  774. :o_id => ticket.id,
  775. :id_to => 3,
  776. :id_from => 2,
  777. :value_from => 'open',
  778. :value_to => 'pending',
  779. :created_by_id => 1,
  780. :created_at => '2013-06-04 11:00:00 UTC',
  781. :updated_at => '2013-06-04 11:00:00 UTC',
  782. )
  783. # state change to open 11:30
  784. History.add(
  785. :history_type => 'updated',
  786. :history_object => 'Ticket',
  787. :history_attribute => 'state',
  788. :o_id => ticket.id,
  789. :id_to => 2,
  790. :id_from => 3,
  791. :value_from => 'pending',
  792. :value_to => 'open',
  793. :created_by_id => 1,
  794. :created_at => '2013-06-04 11:30:00 UTC',
  795. :updated_at => '2013-06-04 11:30:00 UTC',
  796. )
  797. # set ticket from open to closed 12:00
  798. History.add(
  799. :history_type => 'updated',
  800. :history_object => 'Ticket',
  801. :history_attribute => 'state',
  802. :o_id => ticket.id,
  803. :id_to => 4,
  804. :id_from => 3,
  805. :value_from => 'open',
  806. :value_to => 'closed',
  807. :created_by_id => 1,
  808. :created_at => '2013-06-04 12:00:00 UTC',
  809. :updated_at => '2013-06-04 12:00:00 UTC',
  810. )
  811. ticket.update_attributes(
  812. :close_time => '2013-06-04 12:00:00 UTC',
  813. )
  814. sla = Sla.create(
  815. :name => 'test sla 1',
  816. :condition => {},
  817. :data => {
  818. "Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
  819. "beginning_of_workday" => "9:00",
  820. "end_of_workday" => "18:00",
  821. },
  822. :first_response_time => 120,
  823. :update_time => 180,
  824. :close_time => 240,
  825. :active => true,
  826. :updated_by_id => 1,
  827. :created_by_id => 1,
  828. )
  829. ticket = Ticket.find(ticket.id)
  830. assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.escalation_time verify 1' )
  831. assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
  832. assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
  833. assert_equal( ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3' )
  834. assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.update_time_escal_date verify 1' )
  835. assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-06-04 15:00:00 UTC', 'ticket.close_time_escal_date verify 1' )
  836. assert_equal( ticket.close_time_in_min, 60, 'ticket.close_time_in_min verify 3' )
  837. assert_equal( ticket.close_time_diff_in_min, 180, 'ticket.close_time_diff_in_min# verify 3' )
  838. delete = sla.destroy
  839. assert( delete, "sla destroy" )
  840. delete = ticket.destroy
  841. assert( delete, "ticket destroy" )
  842. end
  843. end