1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146 |
- require 'test_helper'
- class TicketSlaTest < ActiveSupport::TestCase
- test 'ticket sla' do
- # cleanup
- delete = Ticket.destroy_all
- assert(delete, 'ticket destroy_all')
- ticket = Ticket.create!(
- title: 'some title äöüß',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-03-21 09:30:00 UTC',
- updated_at: '2013-03-21 09:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify')
- calendar1 = Calendar.create_or_update(
- name: 'EU 1',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- sat: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sun: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 1',
- condition: {},
- first_response_time: 60,
- update_time: 180,
- solution_time: 240,
- calendar_id: calendar1.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_escalation_at verify 1')
- sla = Sla.create_or_update(
- name: 'test sla 1',
- condition: {},
- first_response_time: 120,
- update_time: 180,
- solution_time: 240,
- calendar_id: calendar1.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_escalation_at verify 1')
- delete = sla.destroy
- assert(delete, 'sla destroy 1')
- calendar2 = Calendar.create_or_update(
- name: 'EU 2',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['08:00', '18:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['08:00', '18:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['08:00', '18:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['08:00', '18:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['08:00', '18:00'] ]
- },
- sat: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sun: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 2',
- condition: {
- 'ticket.priority_id' => {
- operator: 'is',
- value: %w[1 2 3],
- },
- },
- calendar_id: calendar2.id,
- first_response_time: 60,
- update_time: 120,
- solution_time: 180,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_at verify 2')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 2')
- assert_nil(ticket.first_response_at, 'ticket.first_response_at verify 2')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min verify 2')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min verify 2')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_escalation_at verify 2')
- assert_nil(ticket.update_in_min, 'ticket.update_in_min verify 2')
- assert_nil(ticket.update_diff_in_min, 'ticket.update_diff_in_min verify 2')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 2')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 2')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 2')
- # set first response in time
- ticket.update!(
- first_response_at: '2013-03-21 10:00:00 UTC',
- )
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_at verify 3')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 3')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 10:00:00 UTC', 'ticket.first_response_at verify 3')
- assert_equal(ticket.first_response_in_min, 30, 'ticket.first_response_in_min verify 3')
- assert_equal(ticket.first_response_diff_in_min, 30, 'ticket.first_response_diff_in_min verify 3')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_escalation_at verify 3')
- assert_nil(ticket.update_in_min, 'ticket.update_in_min verify 3')
- assert_nil(ticket.update_diff_in_min, 'ticket.update_diff_in_min verify 3')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 3')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 3')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 3')
- # set first reponse over time
- ticket.update!(
- first_response_at: '2013-03-21 14:00:00 UTC',
- )
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_at verify 4')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 4')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 4')
- assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 4')
- assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 4')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.update_escalation_at verify 4')
- assert_nil(ticket.update_in_min, 'ticket.update_in_min verify 4')
- assert_nil(ticket.update_diff_in_min, 'ticket.update_diff_in_min verify 4')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 4')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 4')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 4')
- # set update time in time
- ticket.update!(
- last_contact_agent_at: '2013-03-21 11:00:00 UTC',
- )
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 5')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 5')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 5')
- assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 5')
- assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 5')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 13:00:00 UTC', 'ticket.update_escalation_at verify 5')
- assert_equal(ticket.update_in_min, 90, 'ticket.update_in_min verify 5')
- assert_equal(ticket.update_diff_in_min, 30, 'ticket.update_diff_in_min verify 5')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 5')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 5')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 5')
- # set update time over time
- ticket.update!(
- last_contact_agent_at: '2013-03-21 12:00:00 UTC',
- )
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 6')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 6')
- assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6')
- assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_escalation_at verify 6')
- assert_equal(ticket.update_in_min, 150, 'ticket.update_in_min verify 6')
- assert_equal(ticket.update_diff_in_min, -30, 'ticket.update_diff_in_min verify 6')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 6')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 6')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 6')
- # set update time over time
- ticket.update!(
- last_contact_customer_at: '2013-03-21 12:05:00 UTC',
- )
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 6')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 6')
- assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6')
- assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:05:00 UTC', 'ticket.update_escalation_at verify 6')
- assert_equal(ticket.update_in_min, 155, 'ticket.update_in_min verify 6')
- assert_equal(ticket.update_diff_in_min, -35, 'ticket.update_diff_in_min verify 6')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 6')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 6')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 6')
- # set update time over time
- ticket.update!(
- last_contact_agent_at: '2013-03-21 12:10:00 UTC',
- )
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 6')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 6')
- assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6')
- assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_escalation_at verify 6')
- assert_equal(ticket.update_in_min, 160, 'ticket.update_in_min verify 6')
- assert_equal(ticket.update_diff_in_min, -40, 'ticket.update_diff_in_min verify 6')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 6')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 6')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 6')
- # set close time in time
- ticket.update!(
- close_at: '2013-03-21 11:30:00 UTC',
- )
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.escalation_at verify 7')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 7')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 7')
- assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 7')
- assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 7')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_escalation_at verify 7')
- assert_equal(ticket.update_in_min, 160, 'ticket.update_in_min verify 7')
- assert_equal(ticket.update_diff_in_min, -40, 'ticket.update_diff_in_min verify 7')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 7')
- assert_equal(ticket.close_in_min, 120, 'ticket.close_in_min verify 7')
- assert_equal(ticket.close_diff_in_min, 60, 'ticket.close_diff_in_min verify 7')
- # set close time over time
- ticket.update!(
- close_at: '2013-03-21 13:00:00 UTC',
- )
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.escalation_at verify 8')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 8')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 8')
- assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 8')
- assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 8')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_escalation_at verify 8')
- assert_equal(ticket.update_in_min, 160, 'ticket.update_in_min verify 8')
- assert_equal(ticket.update_diff_in_min, -40, 'ticket.update_diff_in_min verify 8')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 8')
- assert_equal(ticket.close_in_min, 210, 'ticket.close_in_min verify 8')
- assert_equal(ticket.close_diff_in_min, -30, 'ticket.close_diff_in_min verify 8')
- # set close time over time
- ticket.update!(
- state: Ticket::State.lookup(name: 'closed')
- )
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify 9')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at verify 9')
- assert_equal(ticket.first_response_at.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response_at verify 9')
- assert_equal(ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 9')
- assert_equal(ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 9')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_escalation_at verify 9')
- assert_equal(ticket.update_in_min, 160, 'ticket.update_in_min verify 9')
- assert_equal(ticket.update_diff_in_min, -40, 'ticket.update_diff_in_min verify 9')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_escalation_at verify 9')
- assert_equal(ticket.close_in_min, 210, 'ticket.close_in_min verify 9')
- assert_equal(ticket.close_diff_in_min, -30, 'ticket.close_diff_in_min verify 9')
- delete = ticket.destroy
- assert(delete, 'ticket destroy')
- ticket = Ticket.create!(
- title: 'some title äöüß',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2013-03-28 23:49:00 UTC',
- updated_at: '2013-03-28 23:49:00 UTC',
- )
- assert(ticket, 'ticket created')
- assert_equal(ticket.title, 'some title äöüß', 'ticket.title verify')
- assert_equal(ticket.group.name, 'Users', 'ticket.group verify')
- assert_equal(ticket.state.name, 'new', 'ticket.state verify')
- # create inbound article
- article_inbound = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2013-03-28 23:49:00 UTC',
- updated_at: '2013-03-28 23:49:00 UTC',
- )
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.article_count, 1, 'ticket.article_count verify - inbound')
- assert_equal(ticket.last_contact_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_at verify - inbound')
- assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
- assert_nil(ticket.last_contact_agent_at, 'ticket.last_contact_agent_at verify - inbound')
- assert_nil(ticket.first_response_at, 'ticket.first_response_at verify - inbound')
- assert_nil(ticket.close_at, 'ticket.close_at verify - inbound')
- # create outbound article
- article_outbound = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_recipient@example.com',
- to: 'some_sender@example.com',
- subject: 'some subject',
- message_id: 'some@id2',
- body: 'some message 2',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2013-03-29 07:00:03 UTC',
- updated_at: '2013-03-29 07:00:03 UTC',
- )
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.article_count, 2, 'ticket.article_count verify - outbound')
- assert_equal(ticket.last_contact_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_at verify - outbound')
- assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - outbound')
- assert_equal(ticket.last_contact_agent_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent_at verify - outbound')
- assert_equal(ticket.first_response_at.to_s, article_outbound.created_at.to_s, 'ticket.first_response_at verify - outbound')
- assert_equal(ticket.first_response_in_min, 0, 'ticket.first_response_in_min verify - outbound')
- assert_equal(ticket.first_response_diff_in_min, 60, 'ticket.first_response_diff_in_min verify - outbound')
- assert_nil(ticket.close_at, 'ticket.close_at verify - outbound')
- delete = ticket.destroy
- assert(delete, 'ticket destroy')
- ticket = Ticket.create!(
- title: 'some title äöüß',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2013-03-28 23:49:00 UTC',
- updated_at: '2013-03-28 23:49:00 UTC',
- )
- assert(ticket, 'ticket created')
- assert_equal(ticket.title, 'some title äöüß', 'ticket.title verify')
- assert_equal(ticket.group.name, 'Users', 'ticket.group verify')
- assert_equal(ticket.state.name, 'new', 'ticket.state verify')
- # create inbound article
- article_inbound = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'phone').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2013-03-28 23:49:00 UTC',
- updated_at: '2013-03-28 23:49:00 UTC',
- )
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.article_count, 1, 'ticket.article_count verify - inbound')
- assert_equal(ticket.last_contact_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_at verify - inbound')
- assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
- assert_nil(ticket.last_contact_agent_at, 'ticket.last_contact_agent_at verify - inbound')
- assert_nil(ticket.first_response_at, 'ticket.first_response_at verify - inbound')
- assert_nil(ticket.close_at, 'ticket.close_at verify - inbound')
- # create note article
- article_note = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'note').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2013-03-28 23:52:00 UTC',
- updated_at: '2013-03-28 23:52:00 UTC',
- )
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.article_count, 2, 'ticket.article_count verify - inbound')
- assert_equal(ticket.last_contact_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_at verify - inbound')
- assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
- assert_nil(ticket.last_contact_agent_at, 'ticket.last_contact_agent_at verify - inbound')
- assert_nil(ticket.first_response_at, 'ticket.first_response_at verify - inbound')
- assert_nil(ticket.close_at, 'ticket.close_at verify - inbound')
- # create outbound article
- article_outbound = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'phone').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2013-03-28 23:55:00 UTC',
- updated_at: '2013-03-28 23:55:00 UTC',
- )
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.article_count, 3, 'ticket.article_count verify - inbound')
- assert_equal(ticket.last_contact_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_at verify - inbound')
- assert_equal(ticket.last_contact_customer_at.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer_at verify - inbound')
- assert_equal(ticket.last_contact_agent_at.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent_at verify - inbound')
- assert_equal(ticket.first_response_at.to_s, article_outbound.created_at.to_s, 'ticket.first_response_at verify - inbound')
- assert_nil(ticket.close_at, 'ticket.close_at verify - inbound')
- calendar1.destroy!
- calendar2.destroy!
- end
- test 'ticket sla + selector' do
- # cleanup
- delete = Ticket.destroy_all
- assert(delete, 'ticket destroy_all')
- calendar1 = Calendar.create_or_update(
- name: 'EU 1',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['09:00', '17:00'] ]
- },
- sat: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sun: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 1',
- condition: {
- 'ticket.priority_id' => {
- operator: 'is',
- value: %w[2],
- },
- },
- first_response_time: 60,
- update_time: 180,
- solution_time: 240,
- calendar_id: calendar1.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket = Ticket.create!(
- title: 'some title äöüß',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-03-21 09:30:00 UTC',
- updated_at: '2013-03-21 09:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket.reload
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_at')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escalation_at')
- assert_nil(ticket.first_response_at, 'ticket.first_response_at')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_escalation_at')
- assert_nil(ticket.update_in_min, 'ticket.update_in_min')
- assert_nil(ticket.update_diff_in_min, 'ticket.update_diff_in_min')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_escalation_at')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min')
- ticket.priority = Ticket::Priority.lookup(name: '1 low')
- ticket.save!
- ticket.reload
- assert_nil(ticket.escalation_at, 'ticket.escalation_at')
- assert_nil(ticket.first_response_escalation_at, 'ticket.first_response_escalation_at')
- assert_nil(ticket.first_response_at, 'ticket.first_response_at')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min')
- assert_nil(ticket.update_escalation_at, 'ticket.update_escalation_at')
- assert_nil(ticket.update_in_min, 'ticket.update_in_min')
- assert_nil(ticket.update_diff_in_min, 'ticket.update_diff_in_min')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min')
- calendar1.destroy!
- end
- test 'ticket sla + timezone + holiday' do
- # cleanup
- delete = Sla.destroy_all
- assert(delete, 'sla destroy_all')
- delete = Ticket.destroy_all
- assert(delete, 'ticket destroy_all')
- ticket = Ticket.create!(
- title: 'some title äöüß',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-03-21 09:30:00 UTC',
- updated_at: '2013-03-21 09:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify')
- # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 7:00-16:00
- calendar = Calendar.create_or_update(
- name: 'EU 3',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sat: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sun: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'aaa should not match',
- condition: {
- 'ticket.priority_id' => {
- operator: 'is not',
- value: %w[1 2 3],
- },
- },
- calendar_id: calendar.id,
- first_response_time: 10,
- update_time: 20,
- solution_time: 300,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 3',
- condition: {
- 'ticket.priority_id' => {
- operator: 'is not',
- value: '1',
- },
- },
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 180,
- solution_time: 240,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_escalation_at verify 1')
- delete = sla.destroy
- assert(delete, 'sla destroy')
- delete = ticket.destroy
- assert(delete, 'ticket destroy')
- ticket = Ticket.create!(
- title: 'some title äöüß',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-10-21 09:30:00 UTC',
- updated_at: '2013-10-21 09:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify')
- # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 6:00-15:00
- calendar = Calendar.create_or_update(
- name: 'EU 4',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sat: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sun: {
- active: true,
- timeframes: [ ['08:00', '17:00'] ]
- },
- },
- public_holidays: {
- '2015-09-22' => {
- 'active' => true,
- 'summary' => 'test 1',
- },
- '2015-09-23' => {
- 'active' => false,
- 'summary' => 'test 2',
- },
- '2015-09-24' => {
- 'removed' => false,
- 'summary' => 'test 3',
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 4',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 180,
- solution_time: 240,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-10-21 12:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-10-21 13:30:00 UTC', 'ticket.close_escalation_at verify 1')
- delete = ticket.destroy
- assert(delete, 'ticket destroy')
- delete = sla.destroy
- assert(delete, 'sla destroy')
- ticket = Ticket.create!(
- title: 'some title äöüß',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-10-21 05:30:00 UTC',
- updated_at: '2013-10-21 05:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify')
- # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 6:00-15:00
- sla = Sla.create_or_update(
- name: 'test sla 5',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 180,
- solution_time: 240,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-10-21 09:00:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-10-21 10:00:00 UTC', 'ticket.close_escalation_at verify 1')
- ticket = Ticket.create!(
- title: 'some title holiday test',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2015-09-21 14:30:00 UTC',
- updated_at: '2015-09-21 14:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2015-09-23 07:30:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2015-09-23 07:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2015-09-23 08:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2015-09-23 09:30:00 UTC', 'ticket.close_escalation_at verify 1')
- delete = sla.destroy!
- assert(delete, 'sla destroy')
- delete = ticket.destroy!
- assert(delete, 'ticket destroy')
- calendar.destroy!
- end
- test 'ticket escalation suspend close reopen bug' do
- # cleanup
- delete = Sla.destroy_all
- assert(delete, 'sla destroy_all')
- delete = Ticket.destroy_all
- assert(delete, 'ticket destroy_all')
- ticket1 = Ticket.create!(
- title: 'some title äöüß3',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'open'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-06-04 09:00:00 UTC',
- updated_at: '2013-06-04 09:00:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket1, 'ticket created')
- # set ticket at 09:30 to pending
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket1.id,
- id_from: Ticket::State.lookup(name: 'open').id,
- id_to: Ticket::State.lookup(name: 'pending reminder').id,
- value_from: 'open',
- value_to: 'pending reminder',
- created_by_id: 1,
- created_at: '2013-06-04 09:30:00 UTC',
- updated_at: '2013-06-04 09:30:00 UTC',
- )
- # set ticket at 09:45 to open
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket1.id,
- id_from: Ticket::State.lookup(name: 'pending reminder').id,
- id_to: Ticket::State.lookup(name: 'open').id,
- value_from: 'pending reminder',
- value_to: 'open',
- created_by_id: 1,
- created_at: '2013-06-04 09:45:00 UTC',
- updated_at: '2013-06-04 09:45:00 UTC',
- )
- # set ticket at 10:00 to closed
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket1.id,
- id_from: Ticket::State.lookup(name: 'open').id,
- id_to: Ticket::State.lookup(name: 'closed').id,
- value_from: 'open',
- value_to: 'closed',
- created_by_id: 1,
- created_at: '2013-06-04 10:00:00 UTC',
- updated_at: '2013-06-04 10:00:00 UTC',
- )
- # set ticket at 10:30 to open
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket1.id,
- id_from: Ticket::State.lookup(name: 'closed').id,
- id_to: Ticket::State.lookup(name: 'open').id,
- value_from: 'closed',
- value_to: 'open',
- created_by_id: 1,
- created_at: '2013-06-04 10:30:00 UTC',
- updated_at: '2013-06-04 10:30:00 UTC',
- )
- # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 7:00-16:00
- calendar = Calendar.create_or_update(
- name: 'EU 5',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sat: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sun: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla suspend bug',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 180,
- solution_time: 250,
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket1.escalation_calculation
- ticket1 = Ticket.find(ticket1.id)
- assert_equal(ticket1.escalation_at.gmtime.to_s, '2013-06-04 11:45:00 UTC', 'ticket1.escalation_at verify 1')
- assert_equal(ticket1.first_response_escalation_at.gmtime.to_s, '2013-06-04 11:45:00 UTC', 'ticket1.first_response_escalation_at verify 1')
- assert_nil(ticket1.first_response_in_min, 'ticket1.first_response_in_min verify 3')
- assert_nil(ticket1.first_response_diff_in_min, 'ticket1.first_response_diff_in_min verify 3')
- ticket2 = Ticket.create!(
- title: 'some title äöüß4',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'open'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-06-04 09:00:00 UTC',
- updated_at: '2013-06-04 09:00:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket2, 'ticket created')
- # set ticket at 10:00 to pending
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket2.id,
- id_from: Ticket::State.lookup(name: 'open').id,
- id_to: Ticket::State.lookup(name: 'pending reminder').id,
- value_from: 'open',
- value_to: 'pending reminder',
- created_by_id: 1,
- created_at: '2013-06-04 10:00:00 UTC',
- updated_at: '2013-06-04 10:00:00 UTC',
- )
- # set ticket at 15:00 to open
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket2.id,
- id_from: Ticket::State.lookup(name: 'pending reminder').id,
- id_to: Ticket::State.lookup(name: 'open').id,
- value_from: 'pending reminder',
- value_to: 'open',
- created_by_id: 1,
- created_at: '2013-06-04 15:00:00 UTC',
- updated_at: '2013-06-04 15:00:00 UTC',
- )
- ticket2.escalation_calculation(true)
- ticket2 = Ticket.find(ticket2.id)
- assert_equal(ticket2.escalation_at.gmtime.to_s, '2013-06-04 16:00:00 UTC', 'ticket2.escalation_at verify 1')
- assert_equal(ticket2.first_response_escalation_at.gmtime.to_s, '2013-06-04 16:00:00 UTC', 'ticket2.first_response_escalation_at verify 1')
- assert_nil(ticket2.first_response_in_min, 'ticket2.first_response_in_min verify 3')
- assert_nil(ticket2.first_response_diff_in_min, 'ticket2.first_response_diff_in_min verify 3')
- delete = sla.destroy!
- assert(delete, 'sla destroy')
- delete = ticket1.destroy!
- assert(delete, 'ticket1 destroy')
- delete = ticket2.destroy!
- assert(delete, 'ticket2 destroy')
- calendar.destroy!
- end
- test 'ticket escalation suspend' do
- ticket = Ticket.create!(
- title: 'some title äöüß3',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-06-04 09:00:00 UTC',
- updated_at: '2013-06-04 09:00:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- # set ticket at 10:00 to pending
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 3,
- id_from: 2,
- value_from: 'open',
- value_to: 'pending reminder',
- created_by_id: 1,
- created_at: '2013-06-04 10:00:00 UTC',
- updated_at: '2013-06-04 10:00:00 UTC',
- )
- # set ticket at 10:30 to open
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 2,
- id_from: 3,
- value_from: 'pending reminder',
- value_to: 'open',
- created_by_id: 1,
- created_at: '2013-06-04 10:30:00 UTC',
- updated_at: '2013-06-04 10:30:00 UTC'
- )
- # set update time
- ticket.update!(
- last_contact_agent_at: '2013-06-04 10:15:00 UTC',
- )
- # set first response time
- ticket.update!(
- first_response_at: '2013-06-04 10:45:00 UTC',
- )
- # set ticket from 11:30 to closed
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 3,
- id_from: 2,
- value_from: 'open',
- value_to: 'closed',
- created_by_id: 1,
- created_at: '2013-06-04 12:00:00 UTC',
- updated_at: '2013-06-04 12:00:00 UTC'
- )
- ticket.update!(
- close_at: '2013-06-04 12:00:00 UTC',
- )
- # set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 7:00-16:00
- calendar = Calendar.create_or_update(
- name: 'EU 5',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sat: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sun: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 5',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 180,
- solution_time: 250,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-06-04 11:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.first_response_in_min, 75, 'ticket.first_response_in_min verify 3')
- assert_equal(ticket.first_response_diff_in_min, 45, 'ticket.first_response_diff_in_min verify 3')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-06-04 13:40:00 UTC', 'ticket.close_escalation_at verify 1')
- assert_equal(ticket.close_in_min, 150, 'ticket.close_in_min verify 3')
- assert_equal(ticket.close_diff_in_min, 100, 'ticket.close_diff_in_min# verify 3')
- delete = sla.destroy
- assert(delete, 'sla destroy')
- delete = ticket.destroy
- assert(delete, 'ticket destroy')
- # test Ticket created in state pending and closed without reopen or state change
- ticket = Ticket.create!(
- title: 'some title äöüß3',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'pending reminder'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-06-04 09:00:00 UTC',
- updated_at: '2013-06-04 09:00:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- # set ticket from 11:30 to closed
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 4,
- id_from: 3,
- value_from: 'pending reminder',
- value_to: 'closed',
- created_by_id: 1,
- created_at: '2013-06-04 12:00:00 UTC',
- updated_at: '2013-06-04 12:00:00 UTC',
- )
- ticket.update!(
- close_at: '2013-06-04 12:00:00 UTC',
- )
- ticket.escalation_calculation(true)
- calendar = Calendar.create_or_update(
- name: 'EU 5',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sat: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sun: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 5',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 180,
- solution_time: 240,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min verify 3')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min verify 3')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-06-04 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-06-04 16:00:00 UTC', 'ticket.close_escalation_at verify 1')
- assert_equal(ticket.close_in_min, 0, 'ticket.close_in_min verify 3')
- assert_equal(ticket.close_diff_in_min, 240, 'ticket.close_diff_in_min# verify 3')
- delete = sla.destroy
- assert(delete, 'sla destroy')
- delete = ticket.destroy
- assert(delete, 'ticket destroy')
- # test Ticket created in state pending, changed state to openen, back to pending and closed
- ticket = Ticket.create!(
- title: 'some title äöüß3',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'pending reminder'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-06-04 09:00:00 UTC',
- updated_at: '2013-06-04 09:00:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- # state change to open 10:30
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 2,
- id_from: 3,
- value_from: 'pending reminder',
- value_to: 'open',
- created_by_id: 1,
- created_at: '2013-06-04 10:30:00 UTC',
- updated_at: '2013-06-04 10:30:00 UTC',
- )
- # state change to pending 11:00
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 3,
- id_from: 2,
- value_from: 'open',
- value_to: 'pending reminder',
- created_by_id: 1,
- created_at: '2013-06-04 11:00:00 UTC',
- updated_at: '2013-06-04 11:00:00 UTC',
- )
- # set ticket from 12:00 to closed
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 4,
- id_from: 3,
- value_from: 'pending reminder',
- value_to: 'closed',
- created_by_id: 1,
- created_at: '2013-06-04 12:00:00 UTC',
- updated_at: '2013-06-04 12:00:00 UTC',
- )
- ticket.update!(
- close_at: '2013-06-04 12:00:00 UTC',
- )
- calendar = Calendar.create_or_update(
- name: 'EU 5',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sat: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sun: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 5',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 180,
- solution_time: 240,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min verify 3')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min verify 3')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-06-04 14:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-06-04 15:30:00 UTC', 'ticket.close_escalation_at verify 1')
- assert_equal(ticket.close_in_min, 30, 'ticket.close_in_min verify 3')
- assert_equal(ticket.close_diff_in_min, 210, 'ticket.close_diff_in_min# verify 3')
- delete = sla.destroy
- assert(delete, 'sla destroy')
- delete = ticket.destroy
- assert(delete, 'ticket destroy')
- ### Test Ticket created in state pending, changed state to openen, back to pending and back to open then
- ### close ticket
- ticket = Ticket.create!(
- title: 'some title äöüß3',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'pending reminder'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2013-06-04 09:00:00 UTC',
- updated_at: '2013-06-04 09:00:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- # state change to open from pending
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 2,
- id_from: 3,
- value_from: 'pending reminder',
- value_to: 'open',
- created_by_id: 1,
- created_at: '2013-06-04 10:30:00 UTC',
- updated_at: '2013-06-04 10:30:00 UTC',
- )
- # state change to pending from open 11:00
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 3,
- id_from: 2,
- value_from: 'open',
- value_to: 'pending reminder',
- created_by_id: 1,
- created_at: '2013-06-04 11:00:00 UTC',
- updated_at: '2013-06-04 11:00:00 UTC',
- )
- # state change to open 11:30
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 2,
- id_from: 3,
- value_from: 'pending reminder',
- value_to: 'open',
- created_by_id: 1,
- created_at: '2013-06-04 11:30:00 UTC',
- updated_at: '2013-06-04 11:30:00 UTC',
- )
- # set ticket from open to closed 12:00
- History.add(
- history_type: 'updated',
- history_object: 'Ticket',
- history_attribute: 'state',
- o_id: ticket.id,
- id_to: 4,
- id_from: 3,
- value_from: 'open',
- value_to: 'closed',
- created_by_id: 1,
- created_at: '2013-06-04 12:00:00 UTC',
- updated_at: '2013-06-04 12:00:00 UTC',
- )
- ticket.update!(
- close_at: '2013-06-04 12:00:00 UTC',
- )
- calendar = Calendar.create_or_update(
- name: 'EU 5',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sat: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sun: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 5',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 180,
- solution_time: 240,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min verify 3')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min verify 3')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2013-06-04 15:00:00 UTC', 'ticket.close_escalation_at verify 1')
- assert_equal(ticket.close_in_min, 60, 'ticket.close_in_min verify 3')
- assert_equal(ticket.close_diff_in_min, 180, 'ticket.close_diff_in_min# verify 3')
- delete = sla.destroy!
- assert(delete, 'sla destroy')
- delete = ticket.destroy!
- assert(delete, 'ticket destroy')
- calendar.destroy!
- end
- test 'ticket ticket.title and article.subject' do
- ticket = Ticket.create!(
- title: 'some title SLATEST1 for you',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2016-03-21 12:30:00 UTC',
- updated_at: '2016-03-21 12:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- article_inbound = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some title SLATEST2 for you',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2016-03-21 12:30:00 UTC',
- updated_at: '2016-03-21 12:30:00 UTC',
- )
- calendar = Calendar.create_or_update(
- name: 'EU 5',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sat: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- sun: {
- active: true,
- timeframes: [ ['09:00', '18:00'] ]
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla - ticket.title & article.subject',
- condition: {
- 'ticket.priority_id' => {
- operator: 'is',
- value: %w[1 2 3],
- },
- 'article.subject' => {
- operator: 'contains',
- value: 'SLATEST2',
- },
- },
- calendar_id: calendar.id,
- first_response_time: 60,
- update_time: 120,
- solution_time: 180,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-03-21 13:30:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-03-21 13:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min verify 3')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min verify 3')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-03-21 14:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2016-03-21 15:30:00 UTC', 'ticket.close_escalation_at verify 1')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 3')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min# verify 3')
- sla = Sla.create_or_update(
- name: 'test sla - ticket.title & article.subject',
- condition: {
- 'ticket.priority_id' => {
- operator: 'is',
- value: %w[1 2 3],
- },
- 'ticket.title' => {
- operator: 'contains',
- value: 'SLATEST1',
- },
- },
- calendar_id: calendar.id,
- first_response_time: 60,
- update_time: 120,
- solution_time: 180,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-03-21 13:30:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-03-21 13:30:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min verify 3')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min verify 3')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-03-21 14:30:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_equal(ticket.close_escalation_at.gmtime.to_s, '2016-03-21 15:30:00 UTC', 'ticket.close_escalation_at verify 1')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 3')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min# verify 3')
- sla = Sla.create_or_update(
- name: 'test sla - ticket.title & article.subject',
- condition: {
- 'ticket.priority_id' => {
- operator: 'is',
- value: %w[1 2 3],
- },
- 'ticket.title' => {
- operator: 'contains',
- value: 'SLATEST2',
- },
- },
- calendar_id: calendar.id,
- first_response_time: 60,
- update_time: 120,
- solution_time: 180,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify 1')
- assert_nil(ticket.first_response_escalation_at, 'ticket.first_response_escalation_at verify 1')
- assert_nil(ticket.first_response_in_min, 'ticket.first_response_in_min verify 3')
- assert_nil(ticket.first_response_diff_in_min, 'ticket.first_response_diff_in_min verify 3')
- assert_nil(ticket.update_escalation_at, 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- assert_nil(ticket.close_in_min, 'ticket.close_in_min verify 3')
- assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min# verify 3')
- delete = sla.destroy!
- assert(delete, 'sla destroy')
- delete = ticket.destroy!
- assert(delete, 'ticket destroy')
- calendar.destroy!
- end
- test 'ticket sla + holiday 222' do
- # cleanup
- delete = Sla.destroy_all
- assert(delete, 'sla destroy_all')
- delete = Ticket.destroy_all
- assert(delete, 'ticket destroy_all')
- ticket = Ticket.create!(
- title: 'some title 222',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2016-11-01 13:56:21 UTC',
- updated_at: '2016-11-01 13:56:21 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify')
- article_customer = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'web').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2016-11-01 13:56:21 UTC',
- updated_at: '2016-11-01 13:56:21 UTC',
- )
- # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 7:00-18:00
- calendar = Calendar.create_or_update(
- name: 'EU',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- sat: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sun: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- },
- public_holidays: {
- '2016-11-01' => {
- 'active' => true,
- 'summary' => 'test 1',
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 1',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 120,
- update_time: 1200,
- solution_time: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- ticket.state = Ticket::State.lookup(name: 'pending reminder')
- ticket.pending_time = '2016-11-10 07:00:00 UTC'
- ticket.updated_at = '2016-11-01 15:25:40 UTC'
- ticket.save!
- article_agent = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2016-11-01 15:25:40 UTC',
- updated_at: '2016-11-01 15:25:40 UTC',
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- ticket.state = Ticket::State.lookup(name: 'open')
- ticket.updated_at = '2016-11-01 15:59:14 UTC'
- ticket.save!
- article_customer = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2016-11-01 15:59:14 UTC',
- updated_at: '2016-11-01 15:59:14 UTC',
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- ticket.state = Ticket::State.lookup(name: 'pending reminder')
- ticket.pending_time = '2016-11-18 07:00:00 UTC'
- ticket.updated_at = '2016-11-01 15:59:58 UTC'
- ticket.save!
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-03 15:00:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- ticket.state = Ticket::State.lookup(name: 'open')
- ticket.updated_at = '2016-11-07 13:26:36 UTC'
- ticket.save!
- article_customer = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2016-11-07 13:26:36 UTC',
- updated_at: '2016-11-07 13:26:36 UTC',
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-09 09:27:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-09 09:27:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- article_agent = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2016-11-07 14:26:36 UTC',
- updated_at: '2016-11-07 14:26:36 UTC',
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-09 10:26:36 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-09 10:26:36 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- delete = sla.destroy!
- assert(delete, 'sla destroy')
- delete = ticket.destroy!
- assert(delete, 'ticket destroy')
- calendar.destroy!
- end
- test 'ticket sla + observer check' do
- # cleanup
- delete = Sla.destroy_all
- assert(delete, 'sla destroy_all')
- delete = Ticket.destroy_all
- assert(delete, 'ticket destroy_all')
- ticket = Ticket.create!(
- title: 'some title observer#1',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2016-11-01 13:56:21 UTC',
- updated_at: '2016-11-01 13:56:21 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- assert_nil(ticket.escalation_at, 'ticket.escalation_at verify')
- article_customer = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'web').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2016-11-01 13:56:21 UTC',
- updated_at: '2016-11-01 13:56:21 UTC',
- )
- # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 7:00-18:00
- calendar = Calendar.create_or_update(
- name: 'EU',
- timezone: 'Europe/Berlin',
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['08:00', '20:00'] ]
- },
- sat: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- sun: {
- active: false,
- timeframes: [ ['08:00', '17:00'] ]
- },
- },
- public_holidays: {
- '2016-11-01' => {
- 'active' => true,
- 'summary' => 'test 1',
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- sla = Sla.create_or_update(
- name: 'test sla 1',
- condition: {},
- calendar_id: calendar.id,
- first_response_time: 60,
- update_time: 120,
- solution_time: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-02 08:00:00 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 08:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-02 09:00:00 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- article_agent = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- created_at: '2016-11-07 13:26:36 UTC',
- updated_at: '2016-11-07 13:26:36 UTC',
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-07 15:26:36 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 08:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-07 15:26:36 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 3:00-18:00
- calendar.update!(
- business_hours: {
- mon: {
- active: true,
- timeframes: [ ['04:00', '20:00'] ]
- },
- tue: {
- active: true,
- timeframes: [ ['04:00', '20:00'] ]
- },
- wed: {
- active: true,
- timeframes: [ ['04:00', '20:00'] ]
- },
- thu: {
- active: true,
- timeframes: [ ['04:00', '20:00'] ]
- },
- fri: {
- active: true,
- timeframes: [ ['04:00', '20:00'] ]
- },
- sat: {
- active: false,
- timeframes: [ ['04:00', '13:00'] ]
- },
- sun: {
- active: false,
- timeframes: [ ['04:00', '17:00'] ]
- },
- },
- public_holidays: {
- '2016-11-01' => {
- 'active' => true,
- 'summary' => 'test 1',
- },
- },
- default: true,
- ical_url: nil,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.escalation_at.gmtime.to_s, '2016-11-07 15:26:36 UTC', 'ticket.escalation_at verify 1')
- assert_equal(ticket.first_response_escalation_at.gmtime.to_s, '2016-11-02 04:00:00 UTC', 'ticket.first_response_escalation_at verify 1')
- assert_equal(ticket.update_escalation_at.gmtime.to_s, '2016-11-07 15:26:36 UTC', 'ticket.update_escalation_at verify 1')
- assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1')
- delete = sla.destroy!
- assert(delete, 'sla destroy')
- delete = ticket.destroy!
- assert(delete, 'ticket destroy')
- calendar.destroy!
- end
- end
|