ticket_sla_test.rb 77 KB

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