ticket_sla_test.rb 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketSlaTest < ActiveSupport::TestCase
  4. test 'ticket sla' do
  5. # cleanup
  6. delete = Sla.destroy_all
  7. assert(delete, 'sla destroy_all')
  8. delete = Ticket.destroy_all
  9. assert(delete, 'ticket destroy_all')
  10. ticket = Ticket.create!(
  11. title: 'some title äöüß',
  12. group: Group.lookup(name: 'Users'),
  13. customer_id: 2,
  14. state: Ticket::State.lookup(name: 'new'),
  15. priority: Ticket::Priority.lookup(name: '2 normal'),
  16. created_at: '2013-03-21 09:30:00 UTC',
  17. updated_at: '2013-03-21 09:30:00 UTC',
  18. updated_by_id: 1,
  19. created_by_id: 1,
  20. )
  21. assert(ticket, 'ticket created')
  22. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify')
  23. calendar1 = Calendar.create_or_update(
  24. name: 'EU 1',
  25. timezone: 'Europe/Berlin',
  26. business_hours: {
  27. mon: {
  28. active: true,
  29. timeframes: [ ['09:00', '17:00'] ]
  30. },
  31. tue: {
  32. active: true,
  33. timeframes: [ ['09:00', '17:00'] ]
  34. },
  35. wed: {
  36. active: true,
  37. timeframes: [ ['09:00', '17:00'] ]
  38. },
  39. thu: {
  40. active: true,
  41. timeframes: [ ['09:00', '17:00'] ]
  42. },
  43. fri: {
  44. active: true,
  45. timeframes: [ ['09:00', '17:00'] ]
  46. },
  47. sat: {
  48. active: false,
  49. timeframes: [ ['08:00', '17:00'] ]
  50. },
  51. sun: {
  52. active: false,
  53. timeframes: [ ['08:00', '17:00'] ]
  54. },
  55. },
  56. default: true,
  57. ical_url: nil,
  58. updated_by_id: 1,
  59. created_by_id: 1,
  60. )
  61. sla = Sla.create_or_update(
  62. name: 'test sla 1',
  63. condition: {},
  64. first_response_time: 60,
  65. update_time: 180,
  66. solution_time: 240,
  67. calendar_id: calendar1.id,
  68. updated_by_id: 1,
  69. created_by_id: 1,
  70. )
  71. Scheduler.worker(true)
  72. ticket = Ticket.find(ticket.id)
  73. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_at verify 1')
  74. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  75. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_escalation_at verify 1')
  76. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_escalation_at verify 1')
  77. sla = Sla.create_or_update(
  78. name: 'test sla 1',
  79. condition: {},
  80. first_response_time: 120,
  81. update_time: 180,
  82. solution_time: 240,
  83. calendar_id: calendar1.id,
  84. updated_by_id: 1,
  85. created_by_id: 1,
  86. )
  87. Scheduler.worker(true)
  88. ticket = Ticket.find(ticket.id)
  89. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_at verify 1')
  90. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  91. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_escalation_at verify 1')
  92. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_escalation_at verify 1')
  93. delete = sla.destroy
  94. assert(delete, 'sla destroy 1')
  95. calendar2 = Calendar.create_or_update(
  96. name: 'EU 2',
  97. timezone: 'Europe/Berlin',
  98. business_hours: {
  99. mon: {
  100. active: true,
  101. timeframes: [ ['08:00', '18:00'] ]
  102. },
  103. tue: {
  104. active: true,
  105. timeframes: [ ['08:00', '18:00'] ]
  106. },
  107. wed: {
  108. active: true,
  109. timeframes: [ ['08:00', '18:00'] ]
  110. },
  111. thu: {
  112. active: true,
  113. timeframes: [ ['08:00', '18:00'] ]
  114. },
  115. fri: {
  116. active: true,
  117. timeframes: [ ['08:00', '18:00'] ]
  118. },
  119. sat: {
  120. active: false,
  121. timeframes: [ ['08:00', '17:00'] ]
  122. },
  123. sun: {
  124. active: false,
  125. timeframes: [ ['08:00', '17:00'] ]
  126. },
  127. },
  128. default: true,
  129. ical_url: nil,
  130. updated_by_id: 1,
  131. created_by_id: 1,
  132. )
  133. sla = Sla.create_or_update(
  134. name: 'test sla 2',
  135. condition: {
  136. 'ticket.priority_id' => {
  137. operator: 'is',
  138. value: %w(1 2 3),
  139. },
  140. },
  141. calendar_id: calendar2.id,
  142. first_response_time: 60,
  143. update_time: 120,
  144. solution_time: 180,
  145. updated_by_id: 1,
  146. created_by_id: 1,
  147. )
  148. Scheduler.worker(true)
  149. ticket = Ticket.find(ticket.id)
  150. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_at verify 2')
  151. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 2')
  152. assert_equal(ticket.first_response_at, nil, 'ticket.first_response_at 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_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_escalation_at verify 2')
  156. assert_equal(ticket.update_in_min, nil, 'ticket.update_in_min verify 2')
  157. assert_equal(ticket.update_diff_in_min, nil, 'ticket.update_diff_in_min verify 2')
  158. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 2')
  159. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 2')
  160. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min verify 2')
  161. # set first response in time
  162. ticket.update_attributes(
  163. first_response_at: '2013-03-21 10:00:00 UTC',
  164. )
  165. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_at verify 3')
  166. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 3')
  167. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 10:00:00 UTC', 'ticket.first_response_at verify 3')
  168. assert_equal(ticket.first_response_in_min, 30, 'ticket.first_response_in_min verify 3')
  169. assert_equal(ticket.first_response_diff_in_min, 30, 'ticket.first_response_diff_in_min verify 3')
  170. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_escalation_at verify 3')
  171. assert_equal(ticket.update_in_min, nil, 'ticket.update_in_min verify 3')
  172. assert_equal(ticket.update_diff_in_min, nil, 'ticket.update_diff_in_min verify 3')
  173. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 3')
  174. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 3')
  175. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min verify 3')
  176. # set first reponse over time
  177. ticket.update_attributes(
  178. first_response_at: '2013-03-21 14:00:00 UTC',
  179. )
  180. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_at verify 4')
  181. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 4')
  182. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 4')
  183. assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 4')
  184. assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 4')
  185. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_escalation_at verify 4')
  186. assert_equal(ticket.update_in_min, nil, 'ticket.update_in_min verify 4')
  187. assert_equal(ticket.update_diff_in_min, nil, 'ticket.update_diff_in_min verify 4')
  188. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 4')
  189. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 4')
  190. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min verify 4')
  191. # set update time in time
  192. ticket.update_attributes(
  193. last_contact_agent_at: '2013-03-21 11:00:00 UTC',
  194. )
  195. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 5')
  196. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 5')
  197. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 5')
  198. assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 5')
  199. assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 5')
  200. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 13:00:00 UTC', 'ticket.update_escalation_at verify 5')
  201. assert_equal(ticket.update_in_min, 90, 'ticket.update_in_min verify 5')
  202. assert_equal(ticket.update_diff_in_min, 30, 'ticket.update_diff_in_min verify 5')
  203. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 5')
  204. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 5')
  205. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min verify 5')
  206. # set update time over time
  207. ticket.update_attributes(
  208. last_contact_agent_at: '2013-03-21 12:00:00 UTC',
  209. )
  210. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6')
  211. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 6')
  212. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 6')
  213. assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6')
  214. assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6')
  215. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_escalation_at verify 6')
  216. assert_equal(ticket.update_in_min, 150, 'ticket.update_in_min verify 6')
  217. assert_equal(ticket.update_diff_in_min, -30, 'ticket.update_diff_in_min verify 6')
  218. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 6')
  219. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 6')
  220. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min verify 6')
  221. # set update time over time
  222. ticket.update_attributes(
  223. last_contact_customer_at: '2013-03-21 12:05:00 UTC',
  224. )
  225. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6')
  226. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 6')
  227. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 6')
  228. assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6')
  229. assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6')
  230. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:05:00 UTC', 'ticket.update_escalation_at verify 6')
  231. assert_equal(ticket.update_in_min, 155, 'ticket.update_in_min verify 6')
  232. assert_equal(ticket.update_diff_in_min, -35, 'ticket.update_diff_in_min verify 6')
  233. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 6')
  234. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 6')
  235. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min verify 6')
  236. # set update time over time
  237. ticket.update_attributes(
  238. last_contact_agent_at: '2013-03-21 12:10:00 UTC',
  239. )
  240. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6')
  241. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 6')
  242. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 6')
  243. assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6')
  244. assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6')
  245. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_escalation_at verify 6')
  246. assert_equal(ticket.update_in_min, 160, 'ticket.update_in_min verify 6')
  247. assert_equal(ticket.update_diff_in_min, -40, 'ticket.update_diff_in_min verify 6')
  248. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 6')
  249. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 6')
  250. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min verify 6')
  251. # set close time in time
  252. ticket.update_attributes(
  253. close_at: '2013-03-21 11:30:00 UTC',
  254. )
  255. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.escalation_at verify 7')
  256. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 7')
  257. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 7')
  258. assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 7')
  259. assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 7')
  260. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_escalation_at verify 7')
  261. assert_equal(ticket.update_in_min, 160, 'ticket.update_in_min verify 7')
  262. assert_equal(ticket.update_diff_in_min, -40, 'ticket.update_diff_in_min verify 7')
  263. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 7')
  264. assert_equal(ticket.close_in_min, 120, 'ticket.close_in_min verify 7')
  265. assert_equal(ticket.close_diff_in_min, 60, 'ticket.close_diff_in_min verify 7')
  266. # set close time over time
  267. ticket.update_attributes(
  268. close_at: '2013-03-21 13:00:00 UTC',
  269. )
  270. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.escalation_at verify 8')
  271. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 8')
  272. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 8')
  273. assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 8')
  274. assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 8')
  275. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_escalation_at verify 8')
  276. assert_equal(ticket.update_in_min, 160, 'ticket.update_in_min verify 8')
  277. assert_equal(ticket.update_diff_in_min, -40, 'ticket.update_diff_in_min verify 8')
  278. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 8')
  279. assert_equal(ticket.close_in_min, 210, 'ticket.close_in_min verify 8')
  280. assert_equal(ticket.close_diff_in_min, -30, 'ticket.close_diff_in_min verify 8')
  281. # set close time over time
  282. ticket.update_attributes(
  283. state: Ticket::State.lookup(name: 'closed')
  284. )
  285. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify 9')
  286. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 9')
  287. assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 9')
  288. assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 9')
  289. assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 9')
  290. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_escalation_at verify 9')
  291. assert_equal(ticket.update_in_min, 160, 'ticket.update_in_min verify 9')
  292. assert_equal(ticket.update_diff_in_min, -40, 'ticket.update_diff_in_min verify 9')
  293. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 9')
  294. assert_equal(ticket.close_in_min, 210, 'ticket.close_in_min verify 9')
  295. assert_equal(ticket.close_diff_in_min, -30, 'ticket.close_diff_in_min verify 9')
  296. delete = ticket.destroy
  297. assert(delete, 'ticket destroy')
  298. ticket = Ticket.create!(
  299. title: 'some title äöüß',
  300. group: Group.lookup(name: 'Users'),
  301. customer_id: 2,
  302. state: Ticket::State.lookup(name: 'new'),
  303. priority: Ticket::Priority.lookup(name: '2 normal'),
  304. updated_by_id: 1,
  305. created_by_id: 1,
  306. created_at: '2013-03-28 23:49:00 UTC',
  307. updated_at: '2013-03-28 23:49:00 UTC',
  308. )
  309. assert(ticket, 'ticket created')
  310. assert_equal(ticket.title, 'some title äöüß', 'ticket.title verify')
  311. assert_equal(ticket.group.name, 'Users', 'ticket.group verify')
  312. assert_equal(ticket.state.name, 'new', 'ticket.state verify')
  313. # create inbound article
  314. article_inbound = Ticket::Article.create!(
  315. ticket_id: ticket.id,
  316. from: 'some_sender@example.com',
  317. to: 'some_recipient@example.com',
  318. subject: 'some subject',
  319. message_id: 'some@id',
  320. body: 'some message',
  321. internal: false,
  322. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  323. type: Ticket::Article::Type.where(name: 'email').first,
  324. updated_by_id: 1,
  325. created_by_id: 1,
  326. created_at: '2013-03-28 23:49:00 UTC',
  327. updated_at: '2013-03-28 23:49:00 UTC',
  328. )
  329. ticket = Ticket.find(ticket.id)
  330. assert_equal(ticket.article_count, 1, 'ticket.article_count verify - inbound')
  331. assert_equal(ticket.last_contact_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_at verify - inbound')
  332. assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
  333. assert_equal(ticket.last_contact_agent_at, nil, 'ticket.last_contact_agent_at verify - inbound')
  334. assert_equal(ticket.first_response_at, nil, 'ticket.first_response_at verify - inbound')
  335. assert_equal(ticket.close_at, nil, 'ticket.close_at verify - inbound')
  336. # create outbound article
  337. article_outbound = Ticket::Article.create!(
  338. ticket_id: ticket.id,
  339. from: 'some_recipient@example.com',
  340. to: 'some_sender@example.com',
  341. subject: 'some subject',
  342. message_id: 'some@id2',
  343. body: 'some message 2',
  344. internal: false,
  345. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  346. type: Ticket::Article::Type.where(name: 'email').first,
  347. updated_by_id: 1,
  348. created_by_id: 1,
  349. created_at: '2013-03-29 07:00:03 UTC',
  350. updated_at: '2013-03-29 07:00:03 UTC',
  351. )
  352. ticket = Ticket.find(ticket.id)
  353. assert_equal(ticket.article_count, 2, 'ticket.article_count verify - outbound')
  354. assert_equal(ticket.last_contact_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_at verify - outbound')
  355. assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - outbound')
  356. assert_equal(ticket.last_contact_agent_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent_at verify - outbound')
  357. assert_equal(ticket.first_response_at.to_s, article_outbound.created_at.to_s, 'ticket.first_response_at verify - outbound')
  358. assert_equal(ticket.first_response_in_min, 0, 'ticket.first_response_in_min verify - outbound')
  359. assert_equal(ticket.first_response_diff_in_min, 60, 'ticket.first_response_diff_in_min verify - outbound')
  360. assert_equal(ticket.close_at, nil, 'ticket.close_at verify - outbound')
  361. delete = ticket.destroy
  362. assert(delete, 'ticket destroy')
  363. ticket = Ticket.create!(
  364. title: 'some title äöüß',
  365. group: Group.lookup(name: 'Users'),
  366. customer_id: 2,
  367. state: Ticket::State.lookup(name: 'new'),
  368. priority: Ticket::Priority.lookup(name: '2 normal'),
  369. updated_by_id: 1,
  370. created_by_id: 1,
  371. created_at: '2013-03-28 23:49:00 UTC',
  372. updated_at: '2013-03-28 23:49:00 UTC',
  373. )
  374. assert(ticket, 'ticket created')
  375. assert_equal(ticket.title, 'some title äöüß', 'ticket.title verify')
  376. assert_equal(ticket.group.name, 'Users', 'ticket.group verify')
  377. assert_equal(ticket.state.name, 'new', 'ticket.state verify')
  378. # create inbound article
  379. article_inbound = Ticket::Article.create!(
  380. ticket_id: ticket.id,
  381. from: 'some_sender@example.com',
  382. subject: 'some subject',
  383. message_id: 'some@id',
  384. body: 'some message',
  385. internal: false,
  386. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  387. type: Ticket::Article::Type.where(name: 'phone').first,
  388. updated_by_id: 1,
  389. created_by_id: 1,
  390. created_at: '2013-03-28 23:49:00 UTC',
  391. updated_at: '2013-03-28 23:49:00 UTC',
  392. )
  393. ticket = Ticket.find(ticket.id)
  394. assert_equal(ticket.article_count, 1, 'ticket.article_count verify - inbound')
  395. assert_equal(ticket.last_contact_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_at verify - inbound')
  396. assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
  397. assert_equal(ticket.last_contact_agent_at, nil, 'ticket.last_contact_agent_at verify - inbound')
  398. assert_equal(ticket.first_response_at, nil, 'ticket.first_response_at verify - inbound')
  399. assert_equal(ticket.close_at, nil, 'ticket.close_at verify - inbound')
  400. # create note article
  401. article_note = Ticket::Article.create!(
  402. ticket_id: ticket.id,
  403. from: 'some_sender@example.com',
  404. subject: 'some subject',
  405. message_id: 'some@id',
  406. body: 'some message',
  407. internal: false,
  408. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  409. type: Ticket::Article::Type.where(name: 'note').first,
  410. updated_by_id: 1,
  411. created_by_id: 1,
  412. created_at: '2013-03-28 23:52:00 UTC',
  413. updated_at: '2013-03-28 23:52:00 UTC',
  414. )
  415. ticket = Ticket.find(ticket.id)
  416. assert_equal(ticket.article_count, 2, 'ticket.article_count verify - inbound')
  417. assert_equal(ticket.last_contact_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_at verify - inbound')
  418. assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
  419. assert_equal(ticket.last_contact_agent_at, nil, 'ticket.last_contact_agent_at verify - inbound')
  420. assert_equal(ticket.first_response_at, nil, 'ticket.first_response_at verify - inbound')
  421. assert_equal(ticket.close_at, nil, 'ticket.close_at verify - inbound')
  422. # create outbound article
  423. article_outbound = Ticket::Article.create!(
  424. ticket_id: ticket.id,
  425. from: 'some_sender@example.com',
  426. subject: 'some subject',
  427. message_id: 'some@id',
  428. body: 'some message',
  429. internal: false,
  430. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  431. type: Ticket::Article::Type.where(name: 'phone').first,
  432. updated_by_id: 1,
  433. created_by_id: 1,
  434. created_at: '2013-03-28 23:55:00 UTC',
  435. updated_at: '2013-03-28 23:55:00 UTC',
  436. )
  437. ticket = Ticket.find(ticket.id)
  438. assert_equal(ticket.article_count, 3, 'ticket.article_count verify - inbound')
  439. assert_equal(ticket.last_contact_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_at verify - inbound')
  440. assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
  441. assert_equal(ticket.last_contact_agent_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent_at verify - inbound')
  442. assert_equal(ticket.first_response_at.to_s, article_outbound.created_at.to_s, 'ticket.first_response_at verify - inbound')
  443. assert_equal(ticket.close_at, nil, 'ticket.close_at verify - inbound')
  444. delete = sla.destroy
  445. assert(delete, 'sla destroy')
  446. delete = sla.destroy
  447. assert(delete, 'sla destroy')
  448. end
  449. test 'ticket sla + timezone + holiday' do
  450. # cleanup
  451. delete = Sla.destroy_all
  452. assert(delete, 'sla destroy_all')
  453. delete = Ticket.destroy_all
  454. assert(delete, 'ticket destroy_all')
  455. ticket = Ticket.create!(
  456. title: 'some title äöüß',
  457. group: Group.lookup(name: 'Users'),
  458. customer_id: 2,
  459. state: Ticket::State.lookup(name: 'new'),
  460. priority: Ticket::Priority.lookup(name: '2 normal'),
  461. created_at: '2013-03-21 09:30:00 UTC',
  462. updated_at: '2013-03-21 09:30:00 UTC',
  463. updated_by_id: 1,
  464. created_by_id: 1,
  465. )
  466. assert(ticket, 'ticket created')
  467. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify')
  468. # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 7:00-16:00
  469. calendar = Calendar.create_or_update(
  470. name: 'EU 3',
  471. timezone: 'Europe/Berlin',
  472. business_hours: {
  473. mon: {
  474. active: true,
  475. timeframes: [ ['08:00', '17:00'] ]
  476. },
  477. tue: {
  478. active: true,
  479. timeframes: [ ['08:00', '17:00'] ]
  480. },
  481. wed: {
  482. active: true,
  483. timeframes: [ ['08:00', '17:00'] ]
  484. },
  485. thu: {
  486. active: true,
  487. timeframes: [ ['08:00', '17:00'] ]
  488. },
  489. fri: {
  490. active: true,
  491. timeframes: [ ['08:00', '17:00'] ]
  492. },
  493. sat: {
  494. active: true,
  495. timeframes: [ ['08:00', '17:00'] ]
  496. },
  497. sun: {
  498. active: true,
  499. timeframes: [ ['08:00', '17:00'] ]
  500. },
  501. },
  502. default: true,
  503. ical_url: nil,
  504. updated_by_id: 1,
  505. created_by_id: 1,
  506. )
  507. sla = Sla.create_or_update(
  508. name: 'aaa should not match',
  509. condition: {
  510. 'ticket.priority_id' => {
  511. operator: 'is not',
  512. value: %w(1 2 3),
  513. },
  514. },
  515. calendar_id: calendar.id,
  516. first_response_time: 10,
  517. update_time: 20,
  518. solution_time: 300,
  519. updated_by_id: 1,
  520. created_by_id: 1,
  521. )
  522. sla = Sla.create_or_update(
  523. name: 'test sla 3',
  524. condition: {
  525. 'ticket.priority_id' => {
  526. operator: 'is not',
  527. value: '1',
  528. },
  529. },
  530. calendar_id: calendar.id,
  531. first_response_time: 120,
  532. update_time: 180,
  533. solution_time: 240,
  534. updated_by_id: 1,
  535. created_by_id: 1,
  536. )
  537. Scheduler.worker(true)
  538. ticket = Ticket.find(ticket.id)
  539. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_at verify 1')
  540. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  541. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_escalation_at verify 1')
  542. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_escalation_at verify 1')
  543. delete = sla.destroy
  544. assert(delete, 'sla destroy')
  545. delete = ticket.destroy
  546. assert(delete, 'ticket destroy')
  547. ticket = Ticket.create!(
  548. title: 'some title äöüß',
  549. group: Group.lookup(name: 'Users'),
  550. customer_id: 2,
  551. state: Ticket::State.lookup(name: 'new'),
  552. priority: Ticket::Priority.lookup(name: '2 normal'),
  553. created_at: '2013-10-21 09:30:00 UTC',
  554. updated_at: '2013-10-21 09:30:00 UTC',
  555. updated_by_id: 1,
  556. created_by_id: 1,
  557. )
  558. assert(ticket, 'ticket created')
  559. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify')
  560. # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 6:00-15:00
  561. calendar = Calendar.create_or_update(
  562. name: 'EU 4',
  563. timezone: 'Europe/Berlin',
  564. business_hours: {
  565. mon: {
  566. active: true,
  567. timeframes: [ ['08:00', '17:00'] ]
  568. },
  569. tue: {
  570. active: true,
  571. timeframes: [ ['08:00', '17:00'] ]
  572. },
  573. wed: {
  574. active: true,
  575. timeframes: [ ['08:00', '17:00'] ]
  576. },
  577. thu: {
  578. active: true,
  579. timeframes: [ ['08:00', '17:00'] ]
  580. },
  581. fri: {
  582. active: true,
  583. timeframes: [ ['08:00', '17:00'] ]
  584. },
  585. sat: {
  586. active: true,
  587. timeframes: [ ['08:00', '17:00'] ]
  588. },
  589. sun: {
  590. active: true,
  591. timeframes: [ ['08:00', '17:00'] ]
  592. },
  593. },
  594. public_holidays: {
  595. '2015-09-22' => {
  596. 'active' => true,
  597. 'summary' => 'test 1',
  598. },
  599. '2015-09-23' => {
  600. 'active' => false,
  601. 'summary' => 'test 2',
  602. },
  603. '2015-09-24' => {
  604. 'removed' => false,
  605. 'summary' => 'test 3',
  606. },
  607. },
  608. default: true,
  609. ical_url: nil,
  610. updated_by_id: 1,
  611. created_by_id: 1,
  612. )
  613. sla = Sla.create_or_update(
  614. name: 'test sla 4',
  615. condition: {},
  616. calendar_id: calendar.id,
  617. first_response_time: 120,
  618. update_time: 180,
  619. solution_time: 240,
  620. updated_by_id: 1,
  621. created_by_id: 1,
  622. )
  623. Scheduler.worker(true)
  624. ticket = Ticket.find(ticket.id)
  625. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.escalation_at verify 1')
  626. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  627. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-10-21 12:30:00 UTC', 'ticket.update_escalation_at verify 1')
  628. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-10-21 13:30:00 UTC', 'ticket.close_escalation_at verify 1')
  629. delete = ticket.destroy
  630. assert(delete, 'ticket destroy')
  631. delete = sla.destroy
  632. assert(delete, 'sla destroy')
  633. ticket = Ticket.create!(
  634. title: 'some title äöüß',
  635. group: Group.lookup(name: 'Users'),
  636. customer_id: 2,
  637. state: Ticket::State.lookup(name: 'new'),
  638. priority: Ticket::Priority.lookup(name: '2 normal'),
  639. created_at: '2013-10-21 05:30:00 UTC',
  640. updated_at: '2013-10-21 05:30:00 UTC',
  641. updated_by_id: 1,
  642. created_by_id: 1,
  643. )
  644. assert(ticket, 'ticket created')
  645. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify')
  646. # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 6:00-15:00
  647. sla = Sla.create_or_update(
  648. name: 'test sla 5',
  649. condition: {},
  650. calendar_id: calendar.id,
  651. first_response_time: 120,
  652. update_time: 180,
  653. solution_time: 240,
  654. updated_by_id: 1,
  655. created_by_id: 1,
  656. )
  657. Scheduler.worker(true)
  658. ticket = Ticket.find(ticket.id)
  659. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.escalation_at verify 1')
  660. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  661. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-10-21 09:00:00 UTC', 'ticket.update_escalation_at verify 1')
  662. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-10-21 10:00:00 UTC', 'ticket.close_escalation_at verify 1')
  663. ticket = Ticket.create!(
  664. title: 'some title holiday test',
  665. group: Group.lookup(name: 'Users'),
  666. customer_id: 2,
  667. state: Ticket::State.lookup(name: 'new'),
  668. priority: Ticket::Priority.lookup(name: '2 normal'),
  669. created_at: '2015-09-21 14:30:00 UTC',
  670. updated_at: '2015-09-21 14:30:00 UTC',
  671. updated_by_id: 1,
  672. created_by_id: 1,
  673. )
  674. ticket = Ticket.find(ticket.id)
  675. assert_equal(ticket.escalation_at.gmtime.to_s, '2015-09-23 07:30:00 UTC', 'ticket.escalation_at verify 1')
  676. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2015-09-23 07:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  677. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2015-09-23 08:30:00 UTC', 'ticket.update_escalation_at verify 1')
  678. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2015-09-23 09:30:00 UTC', 'ticket.close_escalation_at verify 1')
  679. delete = sla.destroy
  680. assert(delete, 'sla destroy')
  681. delete = ticket.destroy
  682. assert(delete, 'ticket destroy')
  683. end
  684. test 'ticket escalation suspend close reopen bug' do
  685. # cleanup
  686. delete = Sla.destroy_all
  687. assert(delete, 'sla destroy_all')
  688. delete = Ticket.destroy_all
  689. assert(delete, 'ticket destroy_all')
  690. ticket1 = Ticket.create!(
  691. title: 'some title äöüß3',
  692. group: Group.lookup(name: 'Users'),
  693. customer_id: 2,
  694. state: Ticket::State.lookup(name: 'open'),
  695. priority: Ticket::Priority.lookup(name: '2 normal'),
  696. created_at: '2013-06-04 09:00:00 UTC',
  697. updated_at: '2013-06-04 09:00:00 UTC',
  698. updated_by_id: 1,
  699. created_by_id: 1,
  700. )
  701. assert(ticket1, 'ticket created')
  702. # set ticket at 09:30 to pending
  703. History.add(
  704. history_type: 'updated',
  705. history_object: 'Ticket',
  706. history_attribute: 'state',
  707. o_id: ticket1.id,
  708. id_from: Ticket::State.lookup(name: 'open').id,
  709. id_to: Ticket::State.lookup(name: 'pending reminder').id,
  710. value_from: 'open',
  711. value_to: 'pending reminder',
  712. created_by_id: 1,
  713. created_at: '2013-06-04 09:30:00 UTC',
  714. updated_at: '2013-06-04 09:30:00 UTC',
  715. )
  716. # set ticket at 09:45 to open
  717. History.add(
  718. history_type: 'updated',
  719. history_object: 'Ticket',
  720. history_attribute: 'state',
  721. o_id: ticket1.id,
  722. id_from: Ticket::State.lookup(name: 'pending reminder').id,
  723. id_to: Ticket::State.lookup(name: 'open').id,
  724. value_from: 'pending reminder',
  725. value_to: 'open',
  726. created_by_id: 1,
  727. created_at: '2013-06-04 09:45:00 UTC',
  728. updated_at: '2013-06-04 09:45:00 UTC',
  729. )
  730. # set ticket at 10:00 to closed
  731. History.add(
  732. history_type: 'updated',
  733. history_object: 'Ticket',
  734. history_attribute: 'state',
  735. o_id: ticket1.id,
  736. id_from: Ticket::State.lookup(name: 'open').id,
  737. id_to: Ticket::State.lookup(name: 'closed').id,
  738. value_from: 'open',
  739. value_to: 'closed',
  740. created_by_id: 1,
  741. created_at: '2013-06-04 10:00:00 UTC',
  742. updated_at: '2013-06-04 10:00:00 UTC',
  743. )
  744. # set ticket at 10:30 to open
  745. History.add(
  746. history_type: 'updated',
  747. history_object: 'Ticket',
  748. history_attribute: 'state',
  749. o_id: ticket1.id,
  750. id_from: Ticket::State.lookup(name: 'closed').id,
  751. id_to: Ticket::State.lookup(name: 'open').id,
  752. value_from: 'closed',
  753. value_to: 'open',
  754. created_by_id: 1,
  755. created_at: '2013-06-04 10:30:00 UTC',
  756. updated_at: '2013-06-04 10:30:00 UTC',
  757. )
  758. # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 7:00-16:00
  759. calendar = Calendar.create_or_update(
  760. name: 'EU 5',
  761. timezone: 'Europe/Berlin',
  762. business_hours: {
  763. mon: {
  764. active: true,
  765. timeframes: [ ['09:00', '18:00'] ]
  766. },
  767. tue: {
  768. active: true,
  769. timeframes: [ ['09:00', '18:00'] ]
  770. },
  771. wed: {
  772. active: true,
  773. timeframes: [ ['09:00', '18:00'] ]
  774. },
  775. thu: {
  776. active: true,
  777. timeframes: [ ['09:00', '18:00'] ]
  778. },
  779. fri: {
  780. active: true,
  781. timeframes: [ ['09:00', '18:00'] ]
  782. },
  783. sat: {
  784. active: true,
  785. timeframes: [ ['09:00', '18:00'] ]
  786. },
  787. sun: {
  788. active: true,
  789. timeframes: [ ['09:00', '18:00'] ]
  790. },
  791. },
  792. default: true,
  793. ical_url: nil,
  794. updated_by_id: 1,
  795. created_by_id: 1,
  796. )
  797. sla = Sla.create_or_update(
  798. name: 'test sla suspend bug',
  799. condition: {},
  800. calendar_id: calendar.id,
  801. first_response_time: 120,
  802. update_time: 180,
  803. solution_time: 250,
  804. updated_by_id: 1,
  805. created_by_id: 1,
  806. )
  807. ticket1.escalation_calculation
  808. ticket1 = Ticket.find(ticket1.id)
  809. assert_equal(ticket1.escalation_at.gmtime.to_s, '2013-06-04 11:45:00 UTC', 'ticket1.escalation_at verify 1')
  810. assert_equal(ticket1.first_response_escalation_at.gmtime.to_s, '2013-06-04 11:45:00 UTC', 'ticket1.first_response_escalation_at verify 1')
  811. assert_equal(ticket1.first_response_in_min, nil, 'ticket1.first_response_in_min verify 3')
  812. assert_equal(ticket1.first_response_diff_in_min, nil, 'ticket1.first_response_diff_in_min verify 3')
  813. ticket2 = Ticket.create!(
  814. title: 'some title äöüß4',
  815. group: Group.lookup(name: 'Users'),
  816. customer_id: 2,
  817. state: Ticket::State.lookup(name: 'open'),
  818. priority: Ticket::Priority.lookup(name: '2 normal'),
  819. created_at: '2013-06-04 09:00:00 UTC',
  820. updated_at: '2013-06-04 09:00:00 UTC',
  821. updated_by_id: 1,
  822. created_by_id: 1,
  823. )
  824. assert(ticket2, 'ticket created')
  825. # set ticket at 10:00 to pending
  826. History.add(
  827. history_type: 'updated',
  828. history_object: 'Ticket',
  829. history_attribute: 'state',
  830. o_id: ticket2.id,
  831. id_from: Ticket::State.lookup(name: 'open').id,
  832. id_to: Ticket::State.lookup(name: 'pending reminder').id,
  833. value_from: 'open',
  834. value_to: 'pending reminder',
  835. created_by_id: 1,
  836. created_at: '2013-06-04 10:00:00 UTC',
  837. updated_at: '2013-06-04 10:00:00 UTC',
  838. )
  839. # set ticket at 15:00 to open
  840. History.add(
  841. history_type: 'updated',
  842. history_object: 'Ticket',
  843. history_attribute: 'state',
  844. o_id: ticket2.id,
  845. id_from: Ticket::State.lookup(name: 'pending reminder').id,
  846. id_to: Ticket::State.lookup(name: 'open').id,
  847. value_from: 'pending reminder',
  848. value_to: 'open',
  849. created_by_id: 1,
  850. created_at: '2013-06-04 15:00:00 UTC',
  851. updated_at: '2013-06-04 15:00:00 UTC',
  852. )
  853. ticket2.escalation_calculation(true)
  854. ticket2 = Ticket.find(ticket2.id)
  855. assert_equal(ticket2.escalation_at.gmtime.to_s, '2013-06-04 16:00:00 UTC', 'ticket2.escalation_at verify 1')
  856. assert_equal(ticket2.first_response_escalation_at.gmtime.to_s, '2013-06-04 16:00:00 UTC', 'ticket2.first_response_escalation_at verify 1')
  857. assert_equal(ticket2.first_response_in_min, nil, 'ticket2.first_response_in_min verify 3')
  858. assert_equal(ticket2.first_response_diff_in_min, nil, 'ticket2.first_response_diff_in_min verify 3')
  859. delete = sla.destroy
  860. assert(delete, 'sla destroy')
  861. delete = ticket1.destroy
  862. assert(delete, 'ticket1 destroy')
  863. delete = ticket2.destroy
  864. assert(delete, 'ticket2 destroy')
  865. end
  866. test 'ticket escalation suspend' do
  867. ticket = Ticket.create!(
  868. title: 'some title äöüß3',
  869. group: Group.lookup(name: 'Users'),
  870. customer_id: 2,
  871. state: Ticket::State.lookup(name: 'new'),
  872. priority: Ticket::Priority.lookup(name: '2 normal'),
  873. created_at: '2013-06-04 09:00:00 UTC',
  874. updated_at: '2013-06-04 09:00:00 UTC',
  875. updated_by_id: 1,
  876. created_by_id: 1,
  877. )
  878. assert(ticket, 'ticket created')
  879. # set ticket at 10:00 to pending
  880. History.add(
  881. history_type: 'updated',
  882. history_object: 'Ticket',
  883. history_attribute: 'state',
  884. o_id: ticket.id,
  885. id_to: 3,
  886. id_from: 2,
  887. value_from: 'open',
  888. value_to: 'pending reminder',
  889. created_by_id: 1,
  890. created_at: '2013-06-04 10:00:00 UTC',
  891. updated_at: '2013-06-04 10:00:00 UTC',
  892. )
  893. # set ticket at 10:30 to open
  894. History.add(
  895. history_type: 'updated',
  896. history_object: 'Ticket',
  897. history_attribute: 'state',
  898. o_id: ticket.id,
  899. id_to: 2,
  900. id_from: 3,
  901. value_from: 'pending reminder',
  902. value_to: 'open',
  903. created_by_id: 1,
  904. created_at: '2013-06-04 10:30:00 UTC',
  905. updated_at: '2013-06-04 10:30:00 UTC'
  906. )
  907. # set update time
  908. ticket.update_attributes(
  909. last_contact_agent_at: '2013-06-04 10:15:00 UTC',
  910. )
  911. # set first response time
  912. ticket.update_attributes(
  913. first_response_at: '2013-06-04 10:45:00 UTC',
  914. )
  915. # set ticket from 11:30 to closed
  916. History.add(
  917. history_type: 'updated',
  918. history_object: 'Ticket',
  919. history_attribute: 'state',
  920. o_id: ticket.id,
  921. id_to: 3,
  922. id_from: 2,
  923. value_from: 'open',
  924. value_to: 'closed',
  925. created_by_id: 1,
  926. created_at: '2013-06-04 12:00:00 UTC',
  927. updated_at: '2013-06-04 12:00:00 UTC'
  928. )
  929. ticket.update_attributes(
  930. close_at: '2013-06-04 12:00:00 UTC',
  931. )
  932. # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 7:00-16:00
  933. calendar = Calendar.create_or_update(
  934. name: 'EU 5',
  935. timezone: 'Europe/Berlin',
  936. business_hours: {
  937. mon: {
  938. active: true,
  939. timeframes: [ ['09:00', '18:00'] ]
  940. },
  941. tue: {
  942. active: true,
  943. timeframes: [ ['09:00', '18:00'] ]
  944. },
  945. wed: {
  946. active: true,
  947. timeframes: [ ['09:00', '18:00'] ]
  948. },
  949. thu: {
  950. active: true,
  951. timeframes: [ ['09:00', '18:00'] ]
  952. },
  953. fri: {
  954. active: true,
  955. timeframes: [ ['09:00', '18:00'] ]
  956. },
  957. sat: {
  958. active: true,
  959. timeframes: [ ['09:00', '18:00'] ]
  960. },
  961. sun: {
  962. active: true,
  963. timeframes: [ ['09:00', '18:00'] ]
  964. },
  965. },
  966. default: true,
  967. ical_url: nil,
  968. updated_by_id: 1,
  969. created_by_id: 1,
  970. )
  971. sla = Sla.create_or_update(
  972. name: 'test sla 5',
  973. condition: {},
  974. calendar_id: calendar.id,
  975. first_response_time: 120,
  976. update_time: 180,
  977. solution_time: 250,
  978. updated_by_id: 1,
  979. created_by_id: 1,
  980. )
  981. Scheduler.worker(true)
  982. ticket = Ticket.find(ticket.id)
  983. assert_equal(ticket.escalation_at.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_at verify 1')
  984. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-06-04 11:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  985. assert_equal(ticket.first_response_in_min, 75, 'ticket.first_response_in_min verify 3')
  986. assert_equal(ticket.first_response_diff_in_min, 45, 'ticket.first_response_diff_in_min verify 3')
  987. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.update_escalation_at verify 1')
  988. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-06-04 13:40:00 UTC', 'ticket.close_escalation_at verify 1')
  989. assert_equal(ticket.close_in_min, 150, 'ticket.close_in_min verify 3')
  990. assert_equal(ticket.close_diff_in_min, 100, 'ticket.close_diff_in_min# verify 3')
  991. delete = sla.destroy
  992. assert(delete, 'sla destroy')
  993. delete = ticket.destroy
  994. assert(delete, 'ticket destroy')
  995. # test Ticket created in state pending and closed without reopen or state change
  996. ticket = Ticket.create!(
  997. title: 'some title äöüß3',
  998. group: Group.lookup(name: 'Users'),
  999. customer_id: 2,
  1000. state: Ticket::State.lookup(name: 'pending reminder'),
  1001. priority: Ticket::Priority.lookup(name: '2 normal'),
  1002. created_at: '2013-06-04 09:00:00 UTC',
  1003. updated_at: '2013-06-04 09:00:00 UTC',
  1004. updated_by_id: 1,
  1005. created_by_id: 1,
  1006. )
  1007. assert(ticket, 'ticket created')
  1008. # set ticket from 11:30 to closed
  1009. History.add(
  1010. history_type: 'updated',
  1011. history_object: 'Ticket',
  1012. history_attribute: 'state',
  1013. o_id: ticket.id,
  1014. id_to: 4,
  1015. id_from: 3,
  1016. value_from: 'pending reminder',
  1017. value_to: 'closed',
  1018. created_by_id: 1,
  1019. created_at: '2013-06-04 12:00:00 UTC',
  1020. updated_at: '2013-06-04 12:00:00 UTC',
  1021. )
  1022. ticket.update_attributes(
  1023. close_at: '2013-06-04 12:00:00 UTC',
  1024. )
  1025. ticket.escalation_calculation(true)
  1026. calendar = Calendar.create_or_update(
  1027. name: 'EU 5',
  1028. timezone: 'Europe/Berlin',
  1029. business_hours: {
  1030. mon: {
  1031. active: true,
  1032. timeframes: [ ['09:00', '18:00'] ]
  1033. },
  1034. tue: {
  1035. active: true,
  1036. timeframes: [ ['09:00', '18:00'] ]
  1037. },
  1038. wed: {
  1039. active: true,
  1040. timeframes: [ ['09:00', '18:00'] ]
  1041. },
  1042. thu: {
  1043. active: true,
  1044. timeframes: [ ['09:00', '18:00'] ]
  1045. },
  1046. fri: {
  1047. active: true,
  1048. timeframes: [ ['09:00', '18:00'] ]
  1049. },
  1050. sat: {
  1051. active: true,
  1052. timeframes: [ ['09:00', '18:00'] ]
  1053. },
  1054. sun: {
  1055. active: true,
  1056. timeframes: [ ['09:00', '18:00'] ]
  1057. },
  1058. },
  1059. default: true,
  1060. ical_url: nil,
  1061. updated_by_id: 1,
  1062. created_by_id: 1,
  1063. )
  1064. sla = Sla.create_or_update(
  1065. name: 'test sla 5',
  1066. condition: {},
  1067. calendar_id: calendar.id,
  1068. first_response_time: 120,
  1069. update_time: 180,
  1070. solution_time: 240,
  1071. updated_by_id: 1,
  1072. created_by_id: 1,
  1073. )
  1074. Scheduler.worker(true)
  1075. ticket = Ticket.find(ticket.id)
  1076. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify 1')
  1077. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1078. assert_equal(ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3')
  1079. assert_equal(ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3')
  1080. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-06-04 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
  1081. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-06-04 16:00:00 UTC', 'ticket.close_escalation_at verify 1')
  1082. assert_equal(ticket.close_in_min, 0, 'ticket.close_in_min verify 3')
  1083. assert_equal(ticket.close_diff_in_min, 240, 'ticket.close_diff_in_min# verify 3')
  1084. delete = sla.destroy
  1085. assert(delete, 'sla destroy')
  1086. delete = ticket.destroy
  1087. assert(delete, 'ticket destroy')
  1088. # test Ticket created in state pending, changed state to openen, back to pending and closed
  1089. ticket = Ticket.create!(
  1090. title: 'some title äöüß3',
  1091. group: Group.lookup(name: 'Users'),
  1092. customer_id: 2,
  1093. state: Ticket::State.lookup(name: 'pending reminder'),
  1094. priority: Ticket::Priority.lookup(name: '2 normal'),
  1095. created_at: '2013-06-04 09:00:00 UTC',
  1096. updated_at: '2013-06-04 09:00:00 UTC',
  1097. updated_by_id: 1,
  1098. created_by_id: 1,
  1099. )
  1100. assert(ticket, 'ticket created')
  1101. # state change to open 10:30
  1102. History.add(
  1103. history_type: 'updated',
  1104. history_object: 'Ticket',
  1105. history_attribute: 'state',
  1106. o_id: ticket.id,
  1107. id_to: 2,
  1108. id_from: 3,
  1109. value_from: 'pending reminder',
  1110. value_to: 'open',
  1111. created_by_id: 1,
  1112. created_at: '2013-06-04 10:30:00 UTC',
  1113. updated_at: '2013-06-04 10:30:00 UTC',
  1114. )
  1115. # state change to pending 11:00
  1116. History.add(
  1117. history_type: 'updated',
  1118. history_object: 'Ticket',
  1119. history_attribute: 'state',
  1120. o_id: ticket.id,
  1121. id_to: 3,
  1122. id_from: 2,
  1123. value_from: 'open',
  1124. value_to: 'pending reminder',
  1125. created_by_id: 1,
  1126. created_at: '2013-06-04 11:00:00 UTC',
  1127. updated_at: '2013-06-04 11:00:00 UTC',
  1128. )
  1129. # set ticket from 12:00 to closed
  1130. History.add(
  1131. history_type: 'updated',
  1132. history_object: 'Ticket',
  1133. history_attribute: 'state',
  1134. o_id: ticket.id,
  1135. id_to: 4,
  1136. id_from: 3,
  1137. value_from: 'pending reminder',
  1138. value_to: 'closed',
  1139. created_by_id: 1,
  1140. created_at: '2013-06-04 12:00:00 UTC',
  1141. updated_at: '2013-06-04 12:00:00 UTC',
  1142. )
  1143. ticket.update_attributes(
  1144. close_at: '2013-06-04 12:00:00 UTC',
  1145. )
  1146. calendar = Calendar.create_or_update(
  1147. name: 'EU 5',
  1148. timezone: 'Europe/Berlin',
  1149. business_hours: {
  1150. mon: {
  1151. active: true,
  1152. timeframes: [ ['09:00', '18:00'] ]
  1153. },
  1154. tue: {
  1155. active: true,
  1156. timeframes: [ ['09:00', '18:00'] ]
  1157. },
  1158. wed: {
  1159. active: true,
  1160. timeframes: [ ['09:00', '18:00'] ]
  1161. },
  1162. thu: {
  1163. active: true,
  1164. timeframes: [ ['09:00', '18:00'] ]
  1165. },
  1166. fri: {
  1167. active: true,
  1168. timeframes: [ ['09:00', '18:00'] ]
  1169. },
  1170. sat: {
  1171. active: true,
  1172. timeframes: [ ['09:00', '18:00'] ]
  1173. },
  1174. sun: {
  1175. active: true,
  1176. timeframes: [ ['09:00', '18:00'] ]
  1177. },
  1178. },
  1179. default: true,
  1180. ical_url: nil,
  1181. updated_by_id: 1,
  1182. created_by_id: 1,
  1183. )
  1184. sla = Sla.create_or_update(
  1185. name: 'test sla 5',
  1186. condition: {},
  1187. calendar_id: calendar.id,
  1188. first_response_time: 120,
  1189. update_time: 180,
  1190. solution_time: 240,
  1191. updated_by_id: 1,
  1192. created_by_id: 1,
  1193. )
  1194. Scheduler.worker(true)
  1195. ticket = Ticket.find(ticket.id)
  1196. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify 1')
  1197. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1198. assert_equal(ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3')
  1199. assert_equal(ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3')
  1200. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-06-04 14:30:00 UTC', 'ticket.update_escalation_at verify 1')
  1201. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-06-04 15:30:00 UTC', 'ticket.close_escalation_at verify 1')
  1202. assert_equal(ticket.close_in_min, 30, 'ticket.close_in_min verify 3')
  1203. assert_equal(ticket.close_diff_in_min, 210, 'ticket.close_diff_in_min# verify 3')
  1204. delete = sla.destroy
  1205. assert(delete, 'sla destroy')
  1206. delete = ticket.destroy
  1207. assert(delete, 'ticket destroy')
  1208. ### Test Ticket created in state pending, changed state to openen, back to pending and back to open then
  1209. ### close ticket
  1210. ticket = Ticket.create!(
  1211. title: 'some title äöüß3',
  1212. group: Group.lookup(name: 'Users'),
  1213. customer_id: 2,
  1214. state: Ticket::State.lookup(name: 'pending reminder'),
  1215. priority: Ticket::Priority.lookup(name: '2 normal'),
  1216. created_at: '2013-06-04 09:00:00 UTC',
  1217. updated_at: '2013-06-04 09:00:00 UTC',
  1218. updated_by_id: 1,
  1219. created_by_id: 1,
  1220. )
  1221. assert(ticket, 'ticket created')
  1222. # state change to open from pending
  1223. History.add(
  1224. history_type: 'updated',
  1225. history_object: 'Ticket',
  1226. history_attribute: 'state',
  1227. o_id: ticket.id,
  1228. id_to: 2,
  1229. id_from: 3,
  1230. value_from: 'pending reminder',
  1231. value_to: 'open',
  1232. created_by_id: 1,
  1233. created_at: '2013-06-04 10:30:00 UTC',
  1234. updated_at: '2013-06-04 10:30:00 UTC',
  1235. )
  1236. # state change to pending from open 11:00
  1237. History.add(
  1238. history_type: 'updated',
  1239. history_object: 'Ticket',
  1240. history_attribute: 'state',
  1241. o_id: ticket.id,
  1242. id_to: 3,
  1243. id_from: 2,
  1244. value_from: 'open',
  1245. value_to: 'pending reminder',
  1246. created_by_id: 1,
  1247. created_at: '2013-06-04 11:00:00 UTC',
  1248. updated_at: '2013-06-04 11:00:00 UTC',
  1249. )
  1250. # state change to open 11:30
  1251. History.add(
  1252. history_type: 'updated',
  1253. history_object: 'Ticket',
  1254. history_attribute: 'state',
  1255. o_id: ticket.id,
  1256. id_to: 2,
  1257. id_from: 3,
  1258. value_from: 'pending reminder',
  1259. value_to: 'open',
  1260. created_by_id: 1,
  1261. created_at: '2013-06-04 11:30:00 UTC',
  1262. updated_at: '2013-06-04 11:30:00 UTC',
  1263. )
  1264. # set ticket from open to closed 12:00
  1265. History.add(
  1266. history_type: 'updated',
  1267. history_object: 'Ticket',
  1268. history_attribute: 'state',
  1269. o_id: ticket.id,
  1270. id_to: 4,
  1271. id_from: 3,
  1272. value_from: 'open',
  1273. value_to: 'closed',
  1274. created_by_id: 1,
  1275. created_at: '2013-06-04 12:00:00 UTC',
  1276. updated_at: '2013-06-04 12:00:00 UTC',
  1277. )
  1278. ticket.update_attributes(
  1279. close_at: '2013-06-04 12:00:00 UTC',
  1280. )
  1281. calendar = Calendar.create_or_update(
  1282. name: 'EU 5',
  1283. timezone: 'Europe/Berlin',
  1284. business_hours: {
  1285. mon: {
  1286. active: true,
  1287. timeframes: [ ['09:00', '18:00'] ]
  1288. },
  1289. tue: {
  1290. active: true,
  1291. timeframes: [ ['09:00', '18:00'] ]
  1292. },
  1293. wed: {
  1294. active: true,
  1295. timeframes: [ ['09:00', '18:00'] ]
  1296. },
  1297. thu: {
  1298. active: true,
  1299. timeframes: [ ['09:00', '18:00'] ]
  1300. },
  1301. fri: {
  1302. active: true,
  1303. timeframes: [ ['09:00', '18:00'] ]
  1304. },
  1305. sat: {
  1306. active: true,
  1307. timeframes: [ ['09:00', '18:00'] ]
  1308. },
  1309. sun: {
  1310. active: true,
  1311. timeframes: [ ['09:00', '18:00'] ]
  1312. },
  1313. },
  1314. default: true,
  1315. ical_url: nil,
  1316. updated_by_id: 1,
  1317. created_by_id: 1,
  1318. )
  1319. sla = Sla.create_or_update(
  1320. name: 'test sla 5',
  1321. condition: {},
  1322. calendar_id: calendar.id,
  1323. first_response_time: 120,
  1324. update_time: 180,
  1325. solution_time: 240,
  1326. updated_by_id: 1,
  1327. created_by_id: 1,
  1328. )
  1329. Scheduler.worker(true)
  1330. ticket = Ticket.find(ticket.id)
  1331. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify 1')
  1332. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1333. assert_equal(ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3')
  1334. assert_equal(ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3')
  1335. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.update_escalation_at verify 1')
  1336. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-06-04 15:00:00 UTC', 'ticket.close_escalation_at verify 1')
  1337. assert_equal(ticket.close_in_min, 60, 'ticket.close_in_min verify 3')
  1338. assert_equal(ticket.close_diff_in_min, 180, 'ticket.close_diff_in_min# verify 3')
  1339. delete = sla.destroy
  1340. assert(delete, 'sla destroy')
  1341. delete = ticket.destroy
  1342. assert(delete, 'ticket destroy')
  1343. end
  1344. test 'ticket ticket.title and article.subject' do
  1345. ticket = Ticket.create!(
  1346. title: 'some title SLATEST1 for you',
  1347. group: Group.lookup(name: 'Users'),
  1348. customer_id: 2,
  1349. state: Ticket::State.lookup(name: 'new'),
  1350. priority: Ticket::Priority.lookup(name: '2 normal'),
  1351. created_at: '2016-03-21 12:30:00 UTC',
  1352. updated_at: '2016-03-21 12:30:00 UTC',
  1353. updated_by_id: 1,
  1354. created_by_id: 1,
  1355. )
  1356. article_inbound = Ticket::Article.create!(
  1357. ticket_id: ticket.id,
  1358. from: 'some_sender@example.com',
  1359. to: 'some_recipient@example.com',
  1360. subject: 'some title SLATEST2 for you',
  1361. message_id: 'some@id',
  1362. body: 'some message',
  1363. internal: false,
  1364. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  1365. type: Ticket::Article::Type.where(name: 'email').first,
  1366. updated_by_id: 1,
  1367. created_by_id: 1,
  1368. created_at: '2016-03-21 12:30:00 UTC',
  1369. updated_at: '2016-03-21 12:30:00 UTC',
  1370. )
  1371. calendar = Calendar.create_or_update(
  1372. name: 'EU 5',
  1373. timezone: 'Europe/Berlin',
  1374. business_hours: {
  1375. mon: {
  1376. active: true,
  1377. timeframes: [ ['09:00', '18:00'] ]
  1378. },
  1379. tue: {
  1380. active: true,
  1381. timeframes: [ ['09:00', '18:00'] ]
  1382. },
  1383. wed: {
  1384. active: true,
  1385. timeframes: [ ['09:00', '18:00'] ]
  1386. },
  1387. thu: {
  1388. active: true,
  1389. timeframes: [ ['09:00', '18:00'] ]
  1390. },
  1391. fri: {
  1392. active: true,
  1393. timeframes: [ ['09:00', '18:00'] ]
  1394. },
  1395. sat: {
  1396. active: true,
  1397. timeframes: [ ['09:00', '18:00'] ]
  1398. },
  1399. sun: {
  1400. active: true,
  1401. timeframes: [ ['09:00', '18:00'] ]
  1402. },
  1403. },
  1404. default: true,
  1405. ical_url: nil,
  1406. updated_by_id: 1,
  1407. created_by_id: 1,
  1408. )
  1409. sla = Sla.create_or_update(
  1410. name: 'test sla - ticket.title & article.subject',
  1411. condition: {
  1412. 'ticket.priority_id' => {
  1413. operator: 'is',
  1414. value: %w(1 2 3),
  1415. },
  1416. 'article.subject' => {
  1417. operator: 'contains',
  1418. value: 'SLATEST2',
  1419. },
  1420. },
  1421. calendar_id: calendar.id,
  1422. first_response_time: 60,
  1423. update_time: 120,
  1424. solution_time: 180,
  1425. updated_by_id: 1,
  1426. created_by_id: 1,
  1427. )
  1428. Scheduler.worker(true)
  1429. ticket = Ticket.find(ticket.id)
  1430. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-03-21 13:30:00 UTC', 'ticket.escalation_at verify 1')
  1431. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-03-21 13:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1432. assert_equal(ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3')
  1433. assert_equal(ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3')
  1434. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-03-21 14:30:00 UTC', 'ticket.update_escalation_at verify 1')
  1435. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2016-03-21 15:30:00 UTC', 'ticket.close_escalation_at verify 1')
  1436. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 3')
  1437. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min# verify 3')
  1438. sla = Sla.create_or_update(
  1439. name: 'test sla - ticket.title & article.subject',
  1440. condition: {
  1441. 'ticket.priority_id' => {
  1442. operator: 'is',
  1443. value: %w(1 2 3),
  1444. },
  1445. 'ticket.title' => {
  1446. operator: 'contains',
  1447. value: 'SLATEST1',
  1448. },
  1449. },
  1450. calendar_id: calendar.id,
  1451. first_response_time: 60,
  1452. update_time: 120,
  1453. solution_time: 180,
  1454. updated_by_id: 1,
  1455. created_by_id: 1,
  1456. )
  1457. Scheduler.worker(true)
  1458. ticket = Ticket.find(ticket.id)
  1459. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-03-21 13:30:00 UTC', 'ticket.escalation_at verify 1')
  1460. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-03-21 13:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1461. assert_equal(ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3')
  1462. assert_equal(ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3')
  1463. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-03-21 14:30:00 UTC', 'ticket.update_escalation_at verify 1')
  1464. assert_equal(ticket.close_escalation_at.gmtime.to_s, '2016-03-21 15:30:00 UTC', 'ticket.close_escalation_at verify 1')
  1465. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 3')
  1466. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min# verify 3')
  1467. sla = Sla.create_or_update(
  1468. name: 'test sla - ticket.title & article.subject',
  1469. condition: {
  1470. 'ticket.priority_id' => {
  1471. operator: 'is',
  1472. value: %w(1 2 3),
  1473. },
  1474. 'ticket.title' => {
  1475. operator: 'contains',
  1476. value: 'SLATEST2',
  1477. },
  1478. },
  1479. calendar_id: calendar.id,
  1480. first_response_time: 60,
  1481. update_time: 120,
  1482. solution_time: 180,
  1483. updated_by_id: 1,
  1484. created_by_id: 1,
  1485. )
  1486. Scheduler.worker(true)
  1487. ticket = Ticket.find(ticket.id)
  1488. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify 1')
  1489. assert_equal(ticket.first_response_escalation_at, nil, 'ticket.first_response_escalation_at verify 1')
  1490. assert_equal(ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3')
  1491. assert_equal(ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3')
  1492. assert_equal(ticket.update_escalation_at, nil, 'ticket.update_escalation_at verify 1')
  1493. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1494. assert_equal(ticket.close_in_min, nil, 'ticket.close_in_min verify 3')
  1495. assert_equal(ticket.close_diff_in_min, nil, 'ticket.close_diff_in_min# verify 3')
  1496. delete = sla.destroy
  1497. assert(delete, 'sla destroy')
  1498. delete = ticket.destroy
  1499. assert(delete, 'ticket destroy')
  1500. end
  1501. test 'ticket sla + holiday 222' do
  1502. # cleanup
  1503. delete = Sla.destroy_all
  1504. assert(delete, 'sla destroy_all')
  1505. delete = Ticket.destroy_all
  1506. assert(delete, 'ticket destroy_all')
  1507. ticket = Ticket.create!(
  1508. title: 'some title 222',
  1509. group: Group.lookup(name: 'Users'),
  1510. customer_id: 2,
  1511. state: Ticket::State.lookup(name: 'new'),
  1512. priority: Ticket::Priority.lookup(name: '2 normal'),
  1513. created_at: '2016-11-01 13:56:21 UTC',
  1514. updated_at: '2016-11-01 13:56:21 UTC',
  1515. updated_by_id: 1,
  1516. created_by_id: 1,
  1517. )
  1518. assert(ticket, 'ticket created')
  1519. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify')
  1520. article_customer = Ticket::Article.create!(
  1521. ticket_id: ticket.id,
  1522. from: 'some_sender@example.com',
  1523. to: 'some_recipient@example.com',
  1524. subject: 'some subject',
  1525. message_id: 'some@id',
  1526. body: 'some message',
  1527. internal: false,
  1528. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  1529. type: Ticket::Article::Type.where(name: 'web').first,
  1530. updated_by_id: 1,
  1531. created_by_id: 1,
  1532. created_at: '2016-11-01 13:56:21 UTC',
  1533. updated_at: '2016-11-01 13:56:21 UTC',
  1534. )
  1535. # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 7:00-18:00
  1536. calendar = Calendar.create_or_update(
  1537. name: 'EU',
  1538. timezone: 'Europe/Berlin',
  1539. business_hours: {
  1540. mon: {
  1541. active: true,
  1542. timeframes: [ ['08:00', '20:00'] ]
  1543. },
  1544. tue: {
  1545. active: true,
  1546. timeframes: [ ['08:00', '20:00'] ]
  1547. },
  1548. wed: {
  1549. active: true,
  1550. timeframes: [ ['08:00', '20:00'] ]
  1551. },
  1552. thu: {
  1553. active: true,
  1554. timeframes: [ ['08:00', '20:00'] ]
  1555. },
  1556. fri: {
  1557. active: true,
  1558. timeframes: [ ['08:00', '20:00'] ]
  1559. },
  1560. sat: {
  1561. active: false,
  1562. timeframes: [ ['08:00', '17:00'] ]
  1563. },
  1564. sun: {
  1565. active: false,
  1566. timeframes: [ ['08:00', '17:00'] ]
  1567. },
  1568. },
  1569. public_holidays: {
  1570. '2016-11-01' => {
  1571. 'active' => true,
  1572. 'summary' => 'test 1',
  1573. },
  1574. },
  1575. default: true,
  1576. ical_url: nil,
  1577. updated_by_id: 1,
  1578. created_by_id: 1,
  1579. )
  1580. sla = Sla.create_or_update(
  1581. name: 'test sla 1',
  1582. condition: {},
  1583. calendar_id: calendar.id,
  1584. first_response_time: 120,
  1585. update_time: 1200,
  1586. solution_time: nil,
  1587. updated_by_id: 1,
  1588. created_by_id: 1,
  1589. )
  1590. Scheduler.worker(true)
  1591. ticket = Ticket.find(ticket.id)
  1592. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.escalation_at verify 1')
  1593. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1594. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
  1595. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1596. ticket.state = Ticket::State.lookup(name: 'pending reminder')
  1597. ticket.pending_time = '2016-11-10 07:00:00 UTC'
  1598. ticket.updated_at = '2016-11-01 15:25:40 UTC'
  1599. ticket.save!
  1600. article_agent = Ticket::Article.create!(
  1601. ticket_id: ticket.id,
  1602. from: 'some_sender@example.com',
  1603. to: 'some_recipient@example.com',
  1604. subject: 'some subject',
  1605. message_id: 'some@id',
  1606. body: 'some message',
  1607. internal: false,
  1608. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  1609. type: Ticket::Article::Type.where(name: 'email').first,
  1610. updated_by_id: 1,
  1611. created_by_id: 1,
  1612. created_at: '2016-11-01 15:25:40 UTC',
  1613. updated_at: '2016-11-01 15:25:40 UTC',
  1614. )
  1615. Scheduler.worker(true)
  1616. ticket = Ticket.find(ticket.id)
  1617. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify 1')
  1618. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1619. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
  1620. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1621. ticket.state = Ticket::State.lookup(name: 'open')
  1622. ticket.updated_at = '2016-11-01 15:59:14 UTC'
  1623. ticket.save!
  1624. article_customer = Ticket::Article.create!(
  1625. ticket_id: ticket.id,
  1626. from: 'some_sender@example.com',
  1627. to: 'some_recipient@example.com',
  1628. subject: 'some subject',
  1629. message_id: 'some@id',
  1630. body: 'some message',
  1631. internal: false,
  1632. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  1633. type: Ticket::Article::Type.where(name: 'email').first,
  1634. updated_by_id: 1,
  1635. created_by_id: 1,
  1636. created_at: '2016-11-01 15:59:14 UTC',
  1637. updated_at: '2016-11-01 15:59:14 UTC',
  1638. )
  1639. Scheduler.worker(true)
  1640. ticket = Ticket.find(ticket.id)
  1641. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.escalation_at verify 1')
  1642. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1643. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
  1644. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1645. ticket.state = Ticket::State.lookup(name: 'pending reminder')
  1646. ticket.pending_time = '2016-11-18 07:00:00 UTC'
  1647. ticket.updated_at = '2016-11-01 15:59:58 UTC'
  1648. ticket.save!
  1649. Scheduler.worker(true)
  1650. ticket = Ticket.find(ticket.id)
  1651. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify 1')
  1652. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1653. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
  1654. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1655. ticket.state = Ticket::State.lookup(name: 'open')
  1656. ticket.updated_at = '2016-11-07 13:26:36 UTC'
  1657. ticket.save!
  1658. article_customer = Ticket::Article.create!(
  1659. ticket_id: ticket.id,
  1660. from: 'some_sender@example.com',
  1661. to: 'some_recipient@example.com',
  1662. subject: 'some subject',
  1663. message_id: 'some@id',
  1664. body: 'some message',
  1665. internal: false,
  1666. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  1667. type: Ticket::Article::Type.where(name: 'email').first,
  1668. updated_by_id: 1,
  1669. created_by_id: 1,
  1670. created_at: '2016-11-07 13:26:36 UTC',
  1671. updated_at: '2016-11-07 13:26:36 UTC',
  1672. )
  1673. Scheduler.worker(true)
  1674. ticket = Ticket.find(ticket.id)
  1675. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-09 09:27:00 UTC', 'ticket.escalation_at verify 1')
  1676. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1677. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-09 09:27:00 UTC', 'ticket.update_escalation_at verify 1')
  1678. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1679. article_agent = Ticket::Article.create!(
  1680. ticket_id: ticket.id,
  1681. from: 'some_sender@example.com',
  1682. to: 'some_recipient@example.com',
  1683. subject: 'some subject',
  1684. message_id: 'some@id',
  1685. body: 'some message',
  1686. internal: false,
  1687. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  1688. type: Ticket::Article::Type.where(name: 'email').first,
  1689. updated_by_id: 1,
  1690. created_by_id: 1,
  1691. created_at: '2016-11-07 14:26:36 UTC',
  1692. updated_at: '2016-11-07 14:26:36 UTC',
  1693. )
  1694. Scheduler.worker(true)
  1695. ticket = Ticket.find(ticket.id)
  1696. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-09 10:26:36 UTC', 'ticket.escalation_at verify 1')
  1697. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1698. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-09 10:26:36 UTC', 'ticket.update_escalation_at verify 1')
  1699. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1700. delete = sla.destroy
  1701. assert(delete, 'sla destroy')
  1702. delete = ticket.destroy
  1703. assert(delete, 'ticket destroy')
  1704. end
  1705. test 'ticket sla + observer check' do
  1706. # cleanup
  1707. delete = Sla.destroy_all
  1708. assert(delete, 'sla destroy_all')
  1709. delete = Ticket.destroy_all
  1710. assert(delete, 'ticket destroy_all')
  1711. ticket = Ticket.create!(
  1712. title: 'some title observer#1',
  1713. group: Group.lookup(name: 'Users'),
  1714. customer_id: 2,
  1715. state: Ticket::State.lookup(name: 'new'),
  1716. priority: Ticket::Priority.lookup(name: '2 normal'),
  1717. created_at: '2016-11-01 13:56:21 UTC',
  1718. updated_at: '2016-11-01 13:56:21 UTC',
  1719. updated_by_id: 1,
  1720. created_by_id: 1,
  1721. )
  1722. assert(ticket, 'ticket created')
  1723. assert_equal(ticket.escalation_at, nil, 'ticket.escalation_at verify')
  1724. article_customer = Ticket::Article.create!(
  1725. ticket_id: ticket.id,
  1726. from: 'some_sender@example.com',
  1727. to: 'some_recipient@example.com',
  1728. subject: 'some subject',
  1729. message_id: 'some@id',
  1730. body: 'some message',
  1731. internal: false,
  1732. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  1733. type: Ticket::Article::Type.where(name: 'web').first,
  1734. updated_by_id: 1,
  1735. created_by_id: 1,
  1736. created_at: '2016-11-01 13:56:21 UTC',
  1737. updated_at: '2016-11-01 13:56:21 UTC',
  1738. )
  1739. # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 7:00-18:00
  1740. calendar = Calendar.create_or_update(
  1741. name: 'EU',
  1742. timezone: 'Europe/Berlin',
  1743. business_hours: {
  1744. mon: {
  1745. active: true,
  1746. timeframes: [ ['08:00', '20:00'] ]
  1747. },
  1748. tue: {
  1749. active: true,
  1750. timeframes: [ ['08:00', '20:00'] ]
  1751. },
  1752. wed: {
  1753. active: true,
  1754. timeframes: [ ['08:00', '20:00'] ]
  1755. },
  1756. thu: {
  1757. active: true,
  1758. timeframes: [ ['08:00', '20:00'] ]
  1759. },
  1760. fri: {
  1761. active: true,
  1762. timeframes: [ ['08:00', '20:00'] ]
  1763. },
  1764. sat: {
  1765. active: false,
  1766. timeframes: [ ['08:00', '17:00'] ]
  1767. },
  1768. sun: {
  1769. active: false,
  1770. timeframes: [ ['08:00', '17:00'] ]
  1771. },
  1772. },
  1773. public_holidays: {
  1774. '2016-11-01' => {
  1775. 'active' => true,
  1776. 'summary' => 'test 1',
  1777. },
  1778. },
  1779. default: true,
  1780. ical_url: nil,
  1781. updated_by_id: 1,
  1782. created_by_id: 1,
  1783. )
  1784. sla = Sla.create_or_update(
  1785. name: 'test sla 1',
  1786. condition: {},
  1787. calendar_id: calendar.id,
  1788. first_response_time: 60,
  1789. update_time: 120,
  1790. solution_time: nil,
  1791. updated_by_id: 1,
  1792. created_by_id: 1,
  1793. )
  1794. Scheduler.worker(true)
  1795. ticket = Ticket.find(ticket.id)
  1796. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-02 08:00:00 UTC', 'ticket.escalation_at verify 1')
  1797. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 08:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1798. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.update_escalation_at verify 1')
  1799. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1800. article_agent = Ticket::Article.create!(
  1801. ticket_id: ticket.id,
  1802. from: 'some_sender@example.com',
  1803. to: 'some_recipient@example.com',
  1804. subject: 'some subject',
  1805. message_id: 'some@id',
  1806. body: 'some message',
  1807. internal: false,
  1808. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  1809. type: Ticket::Article::Type.where(name: 'email').first,
  1810. updated_by_id: 1,
  1811. created_by_id: 1,
  1812. created_at: '2016-11-07 13:26:36 UTC',
  1813. updated_at: '2016-11-07 13:26:36 UTC',
  1814. )
  1815. Scheduler.worker(true)
  1816. ticket = Ticket.find(ticket.id)
  1817. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-07 15:26:36 UTC', 'ticket.escalation_at verify 1')
  1818. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 08:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1819. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-07 15:26:36 UTC', 'ticket.update_escalation_at verify 1')
  1820. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1821. # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 3:00-18:00
  1822. calendar.update_attributes(
  1823. business_hours: {
  1824. mon: {
  1825. active: true,
  1826. timeframes: [ ['04:00', '20:00'] ]
  1827. },
  1828. tue: {
  1829. active: true,
  1830. timeframes: [ ['04:00', '20:00'] ]
  1831. },
  1832. wed: {
  1833. active: true,
  1834. timeframes: [ ['04:00', '20:00'] ]
  1835. },
  1836. thu: {
  1837. active: true,
  1838. timeframes: [ ['04:00', '20:00'] ]
  1839. },
  1840. fri: {
  1841. active: true,
  1842. timeframes: [ ['04:00', '20:00'] ]
  1843. },
  1844. sat: {
  1845. active: false,
  1846. timeframes: [ ['04:00', '13:00'] ]
  1847. },
  1848. sun: {
  1849. active: false,
  1850. timeframes: [ ['04:00', '17:00'] ]
  1851. },
  1852. },
  1853. public_holidays: {
  1854. '2016-11-01' => {
  1855. 'active' => true,
  1856. 'summary' => 'test 1',
  1857. },
  1858. },
  1859. default: true,
  1860. ical_url: nil,
  1861. updated_by_id: 1,
  1862. created_by_id: 1,
  1863. )
  1864. Scheduler.worker(true)
  1865. ticket = Ticket.find(ticket.id)
  1866. assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-07 15:26:36 UTC', 'ticket.escalation_at verify 1')
  1867. assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 04:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
  1868. assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-07 15:26:36 UTC', 'ticket.update_escalation_at verify 1')
  1869. assert_equal(ticket.close_escalation_at, nil, 'ticket.close_escalation_at verify 1')
  1870. delete = sla.destroy
  1871. assert(delete, 'sla destroy')
  1872. delete = ticket.destroy
  1873. assert(delete, 'ticket destroy')
  1874. end
  1875. end