ticket_sla_test.rb 85 KB

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