ticket_trigger_recursive_disabled_test.rb 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293
  1. require 'test_helper'
  2. class TicketTriggerRecursiveDisabledTest < ActiveSupport::TestCase
  3. setup do
  4. Setting.set('ticket_trigger_recursive', false)
  5. end
  6. test '1 basic' do
  7. trigger1 = Trigger.create_or_update(
  8. name: 'aaa loop check',
  9. condition: {
  10. 'article.subject' => {
  11. 'operator' => 'contains',
  12. 'value' => 'Thanks for your inquiry',
  13. },
  14. },
  15. perform: {
  16. 'ticket.tags' => {
  17. 'operator' => 'add',
  18. 'value' => 'should_not_loop',
  19. },
  20. 'notification.email' => {
  21. 'body' => 'some lala',
  22. 'recipient' => 'ticket_customer',
  23. 'subject' => 'Thanks for your inquiry - loop check (#{ticket.title})!',
  24. },
  25. },
  26. disable_notification: true,
  27. active: true,
  28. created_by_id: 1,
  29. updated_by_id: 1,
  30. )
  31. trigger2 = Trigger.create_or_update(
  32. name: 'auto reply',
  33. condition: {
  34. 'ticket.action' => {
  35. 'operator' => 'is',
  36. 'value' => 'create',
  37. },
  38. 'ticket.state_id' => {
  39. 'operator' => 'is',
  40. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  41. }
  42. },
  43. perform: {
  44. 'notification.email' => {
  45. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  46. 'recipient' => 'ticket_customer',
  47. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  48. },
  49. 'ticket.priority_id' => {
  50. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  51. },
  52. 'ticket.tags' => {
  53. 'operator' => 'add',
  54. 'value' => 'aa, kk',
  55. },
  56. },
  57. disable_notification: true,
  58. active: true,
  59. created_by_id: 1,
  60. updated_by_id: 1,
  61. )
  62. trigger3 = Trigger.create_or_update(
  63. name: 'auto tag 1',
  64. condition: {
  65. 'ticket.action' => {
  66. 'operator' => 'is',
  67. 'value' => 'update',
  68. },
  69. 'ticket.state_id' => {
  70. 'operator' => 'is',
  71. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  72. }
  73. },
  74. perform: {
  75. 'ticket.priority_id' => {
  76. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  77. },
  78. 'ticket.tags' => {
  79. 'operator' => 'remove',
  80. 'value' => 'kk',
  81. },
  82. },
  83. disable_notification: true,
  84. active: true,
  85. created_by_id: 1,
  86. updated_by_id: 1,
  87. )
  88. trigger4 = Trigger.create_or_update(
  89. name: 'auto tag 2',
  90. condition: {
  91. 'ticket.state_id' => {
  92. 'operator' => 'is',
  93. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  94. }
  95. },
  96. perform: {
  97. 'ticket.tags' => {
  98. 'operator' => 'add',
  99. 'value' => 'abc',
  100. },
  101. },
  102. disable_notification: true,
  103. active: true,
  104. created_by_id: 1,
  105. updated_by_id: 1,
  106. )
  107. trigger5 = Trigger.create_or_update(
  108. name: 'not matching',
  109. condition: {
  110. 'ticket.state_id' => {
  111. 'operator' => 'is',
  112. 'value' => Ticket::State.lookup(name: 'closed').id.to_s,
  113. }
  114. },
  115. perform: {
  116. 'ticket.priority_id' => {
  117. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  118. },
  119. },
  120. disable_notification: true,
  121. active: true,
  122. created_by_id: 1,
  123. updated_by_id: 1,
  124. )
  125. trigger6 = Trigger.create_or_update(
  126. name: 'zzz last',
  127. condition: {
  128. 'article.subject' => {
  129. 'operator' => 'contains',
  130. 'value' => 'some subject 1234',
  131. },
  132. },
  133. perform: {
  134. 'ticket.tags' => {
  135. 'operator' => 'add',
  136. 'value' => 'article_create_trigger',
  137. },
  138. 'notification.email' => {
  139. 'body' => 'some lala',
  140. 'recipient' => 'ticket_customer',
  141. 'subject' => 'Thanks for your inquiry - 1234 check (#{ticket.title})!',
  142. },
  143. },
  144. disable_notification: true,
  145. active: true,
  146. created_by_id: 1,
  147. updated_by_id: 1,
  148. )
  149. ticket1 = Ticket.create!(
  150. title: "some <b>title</b>\n äöüß",
  151. group: Group.lookup(name: 'Users'),
  152. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  153. updated_by_id: 1,
  154. created_by_id: 1,
  155. )
  156. Ticket::Article.create!(
  157. ticket_id: ticket1.id,
  158. from: 'some_sender@example.com',
  159. to: 'some_recipient@example.com',
  160. subject: 'some subject',
  161. message_id: 'some@id',
  162. body: "some message <b>note</b>\nnew line",
  163. internal: false,
  164. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  165. type: Ticket::Article::Type.find_by(name: 'note'),
  166. updated_by_id: 1,
  167. created_by_id: 1,
  168. )
  169. ticket1.reload
  170. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  171. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  172. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  173. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  174. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  175. assert_equal([], ticket1.tag_list)
  176. Observer::Transaction.commit
  177. ticket1.reload
  178. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  179. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  180. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  181. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  182. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  183. assert_equal(%w[aa kk abc], ticket1.tag_list)
  184. article1 = ticket1.articles.last
  185. assert_match('Zammad <zammad@localhost>', article1.from)
  186. assert_match('nicole.braun@zammad.org', article1.to)
  187. assert_match('Thanks for your inquiry (some <b>title</b> äöüß)!', article1.subject)
  188. assert_match('Braun<br>some &lt;b&gt;title&lt;/b&gt;', article1.body)
  189. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt;<br>&gt; new line', article1.body)
  190. assert_equal('text/html', article1.content_type)
  191. ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
  192. ticket1.save!
  193. Observer::Transaction.commit
  194. ticket1.reload
  195. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  196. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  197. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  198. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  199. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  200. assert_equal(%w[aa kk abc], ticket1.tag_list)
  201. ticket1.state = Ticket::State.lookup(name: 'open')
  202. ticket1.save!
  203. Observer::Transaction.commit
  204. ticket1.reload
  205. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  206. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  207. assert_equal('open', ticket1.state.name, 'ticket1.state verify')
  208. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  209. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  210. assert_equal(%w[aa kk abc], ticket1.tag_list)
  211. ticket1.state = Ticket::State.lookup(name: 'new')
  212. ticket1.save!
  213. Observer::Transaction.commit
  214. ticket1.reload
  215. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  216. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  217. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  218. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  219. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  220. assert_equal(%w[aa abc], ticket1.tag_list)
  221. ticket2 = Ticket.create!(
  222. title: "some title\n äöüß",
  223. group: Group.lookup(name: 'Users'),
  224. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  225. state: Ticket::State.lookup(name: 'open'),
  226. priority: Ticket::Priority.lookup(name: '2 normal'),
  227. updated_by_id: 1,
  228. created_by_id: 1,
  229. )
  230. assert_equal('some title äöüß', ticket2.title, 'ticket2.title verify')
  231. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  232. assert_equal('open', ticket2.state.name, 'ticket2.state verify')
  233. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  234. assert_equal(0, ticket2.articles.count, 'ticket2.articles verify')
  235. assert_equal([], ticket2.tag_list)
  236. Observer::Transaction.commit
  237. ticket2.reload
  238. assert_equal('some title äöüß', ticket2.title, 'ticket2.title verify')
  239. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  240. assert_equal('open', ticket2.state.name, 'ticket2.state verify')
  241. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  242. assert_equal(0, ticket2.articles.count, 'ticket2.articles verify')
  243. assert_equal([], ticket2.tag_list)
  244. ticket3 = Ticket.create!(
  245. title: "some <b>title</b>\n äöüß3",
  246. group: Group.lookup(name: 'Users'),
  247. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  248. updated_by_id: 1,
  249. created_by_id: 1,
  250. )
  251. assert(ticket3, 'ticket3 created')
  252. Ticket::Article.create!(
  253. ticket_id: ticket3.id,
  254. from: 'some_sender@example.com',
  255. to: 'some_recipient@example.com',
  256. subject: 'some subject 1234',
  257. message_id: 'some@id',
  258. content_type: 'text/html',
  259. body: 'some message <b>note</b><br>new line',
  260. internal: false,
  261. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  262. type: Ticket::Article::Type.find_by(name: 'note'),
  263. updated_by_id: 1,
  264. created_by_id: 1,
  265. )
  266. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  267. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  268. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  269. assert_equal('2 normal', ticket3.priority.name, 'ticket3.priority verify')
  270. assert_equal(1, ticket3.articles.count, 'ticket3.articles verify')
  271. assert_equal([], ticket3.tag_list)
  272. Observer::Transaction.commit
  273. ticket3.reload
  274. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  275. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  276. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  277. assert_equal('3 high', ticket3.priority.name, 'ticket3.priority verify')
  278. assert_equal(3, ticket3.articles.count, 'ticket3.articles verify')
  279. assert_equal(%w[aa kk abc article_create_trigger], ticket3.tag_list)
  280. article3 = ticket3.articles[1]
  281. assert_match('Zammad <zammad@localhost>', article3.from)
  282. assert_match('nicole.braun@zammad.org', article3.to)
  283. assert_match('Thanks for your inquiry (some <b>title</b> äöüß3)!', article3.subject)
  284. assert_match('Braun<br>some &lt;b&gt;title&lt;/b&gt;', article3.body)
  285. assert_match('&gt; some message note<br>&gt; new line', article3.body)
  286. assert_no_match('&gt; some message &lt;b&gt;note&lt;/b&gt;<br>&gt; new line', article3.body)
  287. assert_equal('text/html', article3.content_type)
  288. article3 = ticket3.articles[2]
  289. assert_match('Zammad <zammad@localhost>', article3.from)
  290. assert_match('nicole.braun@zammad.org', article3.to)
  291. assert_match('Thanks for your inquiry - 1234 check (some <b>title</b> äöüß3)!', article3.subject)
  292. assert_equal('text/html', article3.content_type)
  293. Ticket::Article.create!(
  294. ticket_id: ticket3.id,
  295. from: 'some_sender@example.com',
  296. to: 'some_recipient@example.com',
  297. subject: 'some subject - not 1234',
  298. message_id: 'some@id',
  299. content_type: 'text/html',
  300. body: 'some message <b>note</b><br>new line',
  301. internal: false,
  302. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  303. type: Ticket::Article::Type.find_by(name: 'note'),
  304. updated_by_id: 1,
  305. created_by_id: 1,
  306. )
  307. Observer::Transaction.commit
  308. ticket3.reload
  309. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  310. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  311. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  312. assert_equal('3 high', ticket3.priority.name, 'ticket3.priority verify')
  313. assert_equal(4, ticket3.articles.count, 'ticket3.articles verify')
  314. assert_equal(%w[aa abc article_create_trigger], ticket3.tag_list)
  315. Ticket::Article.create!(
  316. ticket_id: ticket3.id,
  317. from: 'some_sender@example.com',
  318. to: 'some_recipient@example.com',
  319. subject: 'some subject NOT 1234',
  320. message_id: 'some@id',
  321. content_type: 'text/html',
  322. body: 'some message <b>note</b><br>new line',
  323. internal: false,
  324. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  325. type: Ticket::Article::Type.find_by(name: 'note'),
  326. updated_by_id: 1,
  327. created_by_id: 1,
  328. )
  329. Observer::Transaction.commit
  330. ticket3.reload
  331. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  332. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  333. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  334. assert_equal('3 high', ticket3.priority.name, 'ticket3.priority verify')
  335. assert_equal(5, ticket3.articles.count, 'ticket3.articles verify')
  336. assert_equal(%w[aa abc article_create_trigger], ticket3.tag_list)
  337. Ticket::Article.create!(
  338. ticket_id: ticket3.id,
  339. from: 'some_sender@example.com',
  340. to: 'some_recipient@example.com',
  341. subject: 'some subject 1234',
  342. message_id: 'some@id',
  343. content_type: 'text/html',
  344. body: 'some message <b>note</b><br>new line',
  345. internal: false,
  346. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  347. type: Ticket::Article::Type.find_by(name: 'note'),
  348. updated_by_id: 1,
  349. created_by_id: 1,
  350. )
  351. Observer::Transaction.commit
  352. ticket3.reload
  353. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  354. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  355. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  356. assert_equal('3 high', ticket3.priority.name, 'ticket3.priority verify')
  357. assert_equal(7, ticket3.articles.count, 'ticket3.articles verify')
  358. assert_equal(%w[aa abc article_create_trigger], ticket3.tag_list)
  359. end
  360. test '2 actions - create' do
  361. trigger1 = Trigger.create_or_update(
  362. name: 'auto reply',
  363. condition: {
  364. 'ticket.action' => {
  365. 'operator' => 'is',
  366. 'value' => 'create',
  367. },
  368. 'ticket.state_id' => {
  369. 'operator' => 'is',
  370. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  371. }
  372. },
  373. perform: {
  374. 'notification.email' => {
  375. 'body' => 'dasdasdasd',
  376. 'recipient' => 'ticket_customer',
  377. 'subject' => 'asdasdas',
  378. },
  379. 'ticket.priority_id' => {
  380. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  381. },
  382. },
  383. disable_notification: true,
  384. active: true,
  385. created_by_id: 1,
  386. updated_by_id: 1,
  387. )
  388. ticket1 = Ticket.create!(
  389. title: "some title\n äöüß",
  390. group: Group.lookup(name: 'Users'),
  391. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  392. updated_by_id: 1,
  393. created_by_id: 1,
  394. )
  395. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  396. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  397. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  398. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  399. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  400. Observer::Transaction.commit
  401. ticket1.reload
  402. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  403. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  404. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  405. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  406. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  407. article1 = ticket1.articles.last
  408. assert_match('Zammad <zammad@localhost>', article1.from)
  409. assert_match('nicole.braun@zammad.org', article1.to)
  410. assert_match('asdasdas', article1.subject)
  411. assert_match('dasdasdasd', article1.body)
  412. assert_equal('text/html', article1.content_type)
  413. ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
  414. ticket1.save!
  415. Observer::Transaction.commit
  416. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  417. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  418. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  419. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  420. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  421. ticket1.state = Ticket::State.lookup(name: 'open')
  422. ticket1.save!
  423. Observer::Transaction.commit
  424. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  425. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  426. assert_equal('open', ticket1.state.name, 'ticket1.state verify')
  427. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  428. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  429. ticket1.state = Ticket::State.lookup(name: 'new')
  430. ticket1.save!
  431. Observer::Transaction.commit
  432. ticket1.reload
  433. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  434. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  435. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  436. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  437. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  438. end
  439. test '2 actions - update' do
  440. trigger1 = Trigger.create_or_update(
  441. name: 'auto reply',
  442. condition: {
  443. 'ticket.action' => {
  444. 'operator' => 'is',
  445. 'value' => 'update',
  446. },
  447. 'ticket.state_id' => {
  448. 'operator' => 'is',
  449. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  450. }
  451. },
  452. perform: {
  453. 'notification.email' => {
  454. 'body' => 'dasdasdasd',
  455. 'recipient' => 'ticket_customer',
  456. 'subject' => 'asdasdas',
  457. },
  458. 'ticket.priority_id' => {
  459. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  460. },
  461. },
  462. disable_notification: true,
  463. active: true,
  464. created_by_id: 1,
  465. updated_by_id: 1,
  466. )
  467. ticket1 = Ticket.create!(
  468. title: "some title\n äöüß",
  469. group: Group.lookup(name: 'Users'),
  470. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  471. updated_by_id: 1,
  472. created_by_id: 1,
  473. )
  474. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  475. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  476. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  477. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  478. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  479. Observer::Transaction.commit
  480. ticket1.reload
  481. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  482. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  483. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  484. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  485. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  486. ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
  487. ticket1.save!
  488. Observer::Transaction.commit
  489. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  490. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  491. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  492. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  493. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  494. ticket1.state = Ticket::State.lookup(name: 'open')
  495. ticket1.save!
  496. Observer::Transaction.commit
  497. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  498. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  499. assert_equal('open', ticket1.state.name, 'ticket1.state verify')
  500. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  501. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  502. ticket1.state = Ticket::State.lookup(name: 'new')
  503. ticket1.save!
  504. Observer::Transaction.commit
  505. ticket1.reload
  506. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  507. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  508. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  509. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  510. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  511. end
  512. test '3 auto replys' do
  513. roles = Role.where(name: 'Customer')
  514. customer1 = User.create_or_update(
  515. login: 'postmaster@example.com',
  516. firstname: 'Trigger',
  517. lastname: 'Customer1',
  518. email: 'postmaster@example.com',
  519. password: 'customerpw',
  520. active: true,
  521. roles: roles,
  522. updated_at: '2015-02-05 16:37:00',
  523. updated_by_id: 1,
  524. created_by_id: 1,
  525. )
  526. customer2 = User.create_or_update(
  527. login: 'ticket-auto-reply-customer2@example.com',
  528. firstname: 'Trigger',
  529. lastname: 'Customer2',
  530. email: 'ticket-auto-reply-customer2@example.com',
  531. password: 'customerpw',
  532. active: true,
  533. organization_id: nil,
  534. roles: roles,
  535. updated_at: '2015-02-05 16:37:00',
  536. updated_by_id: 1,
  537. created_by_id: 1,
  538. )
  539. trigger1 = Trigger.create_or_update(
  540. name: 'auto reply - new ticket',
  541. condition: {
  542. 'ticket.action' => {
  543. 'operator' => 'is',
  544. 'value' => 'create',
  545. },
  546. 'ticket.state_id' => {
  547. 'operator' => 'is not',
  548. 'value' => Ticket::State.lookup(name: 'closed').id,
  549. },
  550. 'article.type_id' => {
  551. 'operator' => 'is',
  552. 'value' => [
  553. Ticket::Article::Type.lookup(name: 'email').id,
  554. Ticket::Article::Type.lookup(name: 'phone').id,
  555. Ticket::Article::Type.lookup(name: 'web').id,
  556. ],
  557. },
  558. },
  559. perform: {
  560. 'notification.email' => {
  561. 'body' => '<p>Your request (Ticket##{ticket.number}) has been received and will be reviewed by our support staff.<p>
  562. <br/>
  563. <p>To provide additional information, please reply to this email or click on the following link:
  564. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  565. </p>
  566. <br/>
  567. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  568. 'recipient' => 'ticket_customer',
  569. 'subject' => 'Thanks for your inquiry (#{ticket.title})',
  570. },
  571. },
  572. disable_notification: true,
  573. active: true,
  574. created_by_id: 1,
  575. updated_by_id: 1,
  576. )
  577. trigger2 = Trigger.create_or_update(
  578. name: 'auto reply (on follow up of tickets)',
  579. condition: {
  580. 'ticket.action' => {
  581. 'operator' => 'is',
  582. 'value' => 'update',
  583. },
  584. 'article.sender_id' => {
  585. 'operator' => 'is',
  586. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  587. },
  588. 'article.type_id' => {
  589. 'operator' => 'is',
  590. 'value' => [
  591. Ticket::Article::Type.lookup(name: 'email').id,
  592. Ticket::Article::Type.lookup(name: 'phone').id,
  593. Ticket::Article::Type.lookup(name: 'web').id,
  594. ],
  595. },
  596. },
  597. perform: {
  598. 'notification.email' => {
  599. 'body' => '<p>Your follow up for (#{config.ticket_hook}##{ticket.number}) has been received and will be reviewed by our support staff.<p>
  600. <br/>
  601. <p>To provide additional information, please reply to this email or click on the following link:
  602. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  603. </p>
  604. <br/>
  605. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  606. 'recipient' => 'ticket_customer',
  607. 'subject' => 'Thanks for your follow up (#{ticket.title})',
  608. },
  609. },
  610. active: true,
  611. created_by_id: 1,
  612. updated_by_id: 1,
  613. )
  614. trigger3 = Trigger.create_or_update(
  615. name: 'not matching',
  616. condition: {
  617. 'ticket.action' => {
  618. 'operator' => 'is',
  619. 'value' => 'create',
  620. },
  621. 'ticket.state_id' => {
  622. 'operator' => 'is',
  623. 'value' => Ticket::State.lookup(name: 'closed').id.to_s,
  624. }
  625. },
  626. perform: {
  627. 'notification.email' => {
  628. 'body' => '2some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  629. 'recipient' => 'ticket_customer',
  630. 'subject' => '2Thanks for your inquiry (#{ticket.title})!',
  631. },
  632. },
  633. disable_notification: true,
  634. active: true,
  635. created_by_id: 1,
  636. updated_by_id: 1,
  637. )
  638. # process mail without Precedence header
  639. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  640. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, content)
  641. assert_equal('aaäöüßad asd', ticket_p.title)
  642. assert_equal('Users', ticket_p.group.name)
  643. assert_equal('new', ticket_p.state.name)
  644. assert_equal(2, ticket_p.articles.count)
  645. article_p = ticket_p.articles.last
  646. assert_match('Thanks for your inquiry (aaäöüßad asd)', article_p.subject)
  647. assert_match('Zammad <zammad@localhost>', article_p.from)
  648. assert_no_match('config\.', article_p.body)
  649. assert_match('http://zammad.example.com', article_p.body)
  650. assert_no_match('ticket.', article_p.body)
  651. assert_match(ticket_p.number, article_p.body)
  652. assert_equal('text/html', article_p.content_type)
  653. ticket_p.priority = Ticket::Priority.lookup(name: '2 normal')
  654. ticket_p.save!
  655. Observer::Transaction.commit
  656. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  657. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  658. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  659. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  660. assert_equal(2, ticket_p.articles.count, 'ticket_p.articles verify')
  661. article_p = Ticket::Article.create!(
  662. ticket_id: ticket_p.id,
  663. from: 'some_sender@example.com',
  664. to: 'some_recipient@example.com',
  665. subject: 'some subject',
  666. message_id: 'some@id',
  667. body: 'some message note',
  668. internal: false,
  669. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  670. type: Ticket::Article::Type.find_by(name: 'note'),
  671. updated_by_id: 1,
  672. created_by_id: 1,
  673. )
  674. Observer::Transaction.commit
  675. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  676. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  677. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  678. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  679. assert_equal(3, ticket_p.articles.count, 'ticket_p.articles verify')
  680. article_p = Ticket::Article.create!(
  681. ticket_id: ticket_p.id,
  682. from: 'some_sender@example.com',
  683. to: 'some_recipient@example.com',
  684. subject: 'some subject',
  685. message_id: 'some@id',
  686. body: 'some message note',
  687. internal: false,
  688. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  689. type: Ticket::Article::Type.find_by(name: 'email'),
  690. updated_by_id: 1,
  691. created_by_id: 1,
  692. )
  693. Observer::Transaction.commit
  694. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  695. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  696. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  697. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  698. assert_equal(4, ticket_p.articles.count, 'ticket_p.articles verify')
  699. article_p = Ticket::Article.create!(
  700. ticket_id: ticket_p.id,
  701. from: 'some_sender@example.com',
  702. to: 'some_recipient@example.com',
  703. subject: 'some subject',
  704. message_id: 'some@id',
  705. body: 'some message note',
  706. internal: false,
  707. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  708. type: Ticket::Article::Type.find_by(name: 'email'),
  709. updated_by_id: 1,
  710. created_by_id: 1,
  711. )
  712. Observer::Transaction.commit
  713. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  714. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  715. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  716. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  717. assert_equal(6, ticket_p.articles.count, 'ticket_p.articles verify')
  718. article_p = ticket_p.articles.last
  719. assert_match('Thanks for your follow up (aaäöüßad asd)', article_p.subject)
  720. assert_match('Zammad <zammad@localhost>', article_p.from)
  721. assert_no_match('config\.', article_p.body)
  722. assert_match('http://zammad.example.com', article_p.body)
  723. assert_no_match('ticket.', article_p.body)
  724. assert_match(ticket_p.number, article_p.body)
  725. assert_equal('text/html', article_p.content_type)
  726. ticket_p.state = Ticket::State.lookup(name: 'open')
  727. ticket_p.save!
  728. article_p = Ticket::Article.create!(
  729. ticket_id: ticket_p.id,
  730. from: 'some_sender@example.com',
  731. to: 'some_recipient@example.com',
  732. subject: 'some subject',
  733. message_id: 'some@id',
  734. body: 'some message note',
  735. internal: false,
  736. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  737. type: Ticket::Article::Type.find_by(name: 'email'),
  738. updated_by_id: 1,
  739. created_by_id: 1,
  740. )
  741. Observer::Transaction.commit
  742. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  743. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  744. assert_equal('open', ticket_p.state.name, 'ticket_p.state verify')
  745. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  746. assert_equal(8, ticket_p.articles.count, 'ticket_p.articles verify')
  747. article_p = ticket_p.articles.last
  748. assert_match('Thanks for your follow up (aaäöüßad asd)', article_p.subject)
  749. assert_match('Zammad <zammad@localhost>', article_p.from)
  750. assert_no_match('config\.', article_p.body)
  751. assert_match('http://zammad.example.com', article_p.body)
  752. assert_no_match('ticket.', article_p.body)
  753. assert_match(ticket_p.number, article_p.body)
  754. assert_equal('text/html', article_p.content_type)
  755. # process mail without Precedence header
  756. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  757. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, content)
  758. assert_equal('new', ticket_p.state.name)
  759. assert_equal(2, ticket_p.articles.count)
  760. # process mail with Precedence header (no auto response)
  761. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail2.box'))
  762. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, content)
  763. assert_equal('new', ticket_p.state.name)
  764. assert_equal(1, ticket_p.articles.count)
  765. # process mail with abuse@ (no auto response)
  766. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail3.box'))
  767. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, content)
  768. assert_equal('new', ticket_p.state.name)
  769. assert_equal(1, ticket_p.articles.count)
  770. end
  771. test '4 has changed' do
  772. roles = Role.where(name: 'Customer')
  773. customer1 = User.create_or_update(
  774. login: 'postmaster@example.com',
  775. firstname: 'Trigger',
  776. lastname: 'Customer1',
  777. email: 'postmaster@example.com',
  778. password: 'customerpw',
  779. active: true,
  780. roles: roles,
  781. updated_at: '2015-02-05 16:37:00',
  782. updated_by_id: 1,
  783. created_by_id: 1,
  784. )
  785. customer2 = User.create_or_update(
  786. login: 'ticket-has-changed-customer2@example.com',
  787. firstname: 'Trigger',
  788. lastname: 'Customer2',
  789. email: 'ticket-has-changed-customer2@example.com',
  790. password: 'customerpw',
  791. active: true,
  792. organization_id: nil,
  793. roles: roles,
  794. updated_at: '2015-02-05 16:37:00',
  795. updated_by_id: 1,
  796. created_by_id: 1,
  797. )
  798. groups = Group.where(name: 'Users')
  799. roles = Role.where(name: 'Agent')
  800. agent1 = User.create_or_update(
  801. login: 'agent-has-changed@example.com',
  802. firstname: 'Has Changed',
  803. lastname: 'Agent1',
  804. email: 'agent-has-changed@example.com',
  805. password: 'agentpw',
  806. active: true,
  807. roles: roles,
  808. groups: groups,
  809. updated_at: '2015-02-05 16:37:00',
  810. updated_by_id: 1,
  811. created_by_id: 1,
  812. )
  813. trigger1 = Trigger.create_or_update(
  814. name: 'owner update - to customer',
  815. condition: {
  816. 'ticket.owner_id' => {
  817. 'operator' => 'has changed',
  818. 'pre_condition' => 'current_user.id',
  819. 'value' => '',
  820. 'value_completion' => '',
  821. }
  822. },
  823. perform: {
  824. 'notification.email' => {
  825. 'body' => '<p>The owner of ticket (Ticket##{ticket.number}) has changed.<p>
  826. <br/>
  827. <p>To provide additional information, please reply to this email or click on the following link:
  828. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  829. </p>
  830. <br/>
  831. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  832. 'recipient' => 'ticket_customer',
  833. 'subject' => 'Owner has changed (#{ticket.title})',
  834. },
  835. },
  836. disable_notification: true,
  837. active: true,
  838. created_by_id: 1,
  839. updated_by_id: 1,
  840. )
  841. # process mail without Precedence header
  842. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  843. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, content)
  844. assert_equal('aaäöüßad asd', ticket_p.title)
  845. assert_equal('Users', ticket_p.group.name)
  846. assert_equal('new', ticket_p.state.name)
  847. assert_equal(1, ticket_p.articles.count)
  848. article_p = ticket_p.articles.last
  849. Observer::Transaction.commit
  850. ticket_p.owner = agent1
  851. ticket_p.save!
  852. Observer::Transaction.commit
  853. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  854. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  855. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  856. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  857. assert_equal(2, ticket_p.articles.count, 'ticket_p.articles verify')
  858. #p ticket_p.articles.last.inspect
  859. article_p = ticket_p.articles.last
  860. assert_match('Owner has changed', article_p.subject)
  861. assert_match('Zammad <zammad@localhost>', article_p.from)
  862. assert_match('martin@example.com', article_p.to)
  863. assert_no_match('config\.', article_p.body)
  864. assert_match('http://zammad.example.com', article_p.body)
  865. assert_no_match('ticket.', article_p.body)
  866. assert_match(ticket_p.number, article_p.body)
  867. assert_equal('text/html', article_p.content_type)
  868. trigger1 = Trigger.create_or_update(
  869. name: 'owner update - to customer',
  870. condition: {
  871. 'ticket.owner_id' => {
  872. 'operator' => 'has changed',
  873. 'pre_condition' => 'current_user.id',
  874. 'value' => '',
  875. 'value_completion' => '',
  876. },
  877. 'ticket.priority_id' => {
  878. 'operator' => 'is',
  879. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  880. },
  881. },
  882. perform: {
  883. 'notification.email' => {
  884. 'body' => '<p>The owner of ticket (Ticket##{ticket.number}) has changed.<p>
  885. <br/>
  886. <p>To provide additional information, please reply to this email or click on the following link:
  887. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  888. </p>
  889. <br/>
  890. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  891. 'recipient' => 'ticket_customer',
  892. 'subject' => 'Owner has changed (#{ticket.title})',
  893. },
  894. },
  895. disable_notification: true,
  896. active: true,
  897. created_by_id: 1,
  898. updated_by_id: 1,
  899. )
  900. # process mail without Precedence header
  901. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  902. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, content)
  903. assert_equal('aaäöüßad asd', ticket_p.title)
  904. assert_equal('Users', ticket_p.group.name)
  905. assert_equal('new', ticket_p.state.name)
  906. assert_equal(1, ticket_p.articles.count)
  907. article_p = ticket_p.articles.last
  908. Observer::Transaction.commit
  909. assert_equal(1, ticket_p.articles.count)
  910. ticket_p.priority = Ticket::Priority.lookup(name: '1 low')
  911. ticket_p.save!
  912. Observer::Transaction.commit
  913. assert_equal(1, ticket_p.articles.count)
  914. ticket_p.priority = Ticket::Priority.lookup(name: '3 high')
  915. ticket_p.save!
  916. Observer::Transaction.commit
  917. assert_equal(1, ticket_p.articles.count)
  918. ticket_p.owner = agent1
  919. ticket_p.save!
  920. Observer::Transaction.commit
  921. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  922. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  923. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  924. assert_equal('3 high', ticket_p.priority.name, 'ticket_p.priority verify')
  925. assert_equal(2, ticket_p.articles.count, 'ticket_p.articles verify')
  926. #p ticket_p.articles.last.inspect
  927. article_p = ticket_p.articles.last
  928. assert_match('Owner has changed', article_p.subject)
  929. assert_match('Zammad <zammad@localhost>', article_p.from)
  930. assert_match('martin@example.com', article_p.to)
  931. assert_no_match('config\.', article_p.body)
  932. assert_match('http://zammad.example.com', article_p.body)
  933. assert_no_match('ticket.', article_p.body)
  934. assert_match(ticket_p.number, article_p.body)
  935. assert_equal('text/html', article_p.content_type)
  936. # should trigger
  937. trigger1 = Trigger.create_or_update(
  938. name: 'owner update - to customer',
  939. condition: {
  940. 'ticket.owner_id' => {
  941. 'operator' => 'has changed',
  942. 'pre_condition' => 'current_user.id',
  943. 'value' => '',
  944. 'value_completion' => '',
  945. },
  946. 'ticket.priority_id' => {
  947. 'operator' => 'is',
  948. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  949. },
  950. 'ticket.action' => {
  951. 'operator' => 'is not',
  952. 'value' => 'create',
  953. },
  954. },
  955. perform: {
  956. 'notification.email' => {
  957. 'body' => '<p>The owner of ticket (Ticket##{ticket.number}) has changed.<p>
  958. <br/>
  959. <p>To provide additional information, please reply to this email or click on the following link:
  960. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  961. </p>
  962. <br/>
  963. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  964. 'recipient' => 'ticket_customer',
  965. 'subject' => 'Owner has changed (#{ticket.title})',
  966. },
  967. },
  968. disable_notification: true,
  969. active: true,
  970. created_by_id: 1,
  971. updated_by_id: 1,
  972. )
  973. # process mail without Precedence header
  974. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  975. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, content)
  976. assert_equal('aaäöüßad asd', ticket_p.title)
  977. assert_equal('Users', ticket_p.group.name)
  978. assert_equal('new', ticket_p.state.name)
  979. assert_equal(1, ticket_p.articles.count)
  980. article_p = ticket_p.articles.last
  981. Observer::Transaction.commit
  982. assert_equal(1, ticket_p.articles.count)
  983. ticket_p.priority = Ticket::Priority.lookup(name: '1 low')
  984. ticket_p.save!
  985. Observer::Transaction.commit
  986. assert_equal(1, ticket_p.articles.count)
  987. ticket_p.priority = Ticket::Priority.lookup(name: '3 high')
  988. ticket_p.save!
  989. Observer::Transaction.commit
  990. assert_equal(1, ticket_p.articles.count)
  991. ticket_p.owner = agent1
  992. ticket_p.save!
  993. Observer::Transaction.commit
  994. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  995. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  996. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  997. assert_equal('3 high', ticket_p.priority.name, 'ticket_p.priority verify')
  998. assert_equal(2, ticket_p.articles.count, 'ticket_p.articles verify')
  999. #p ticket_p.articles.last.inspect
  1000. article_p = ticket_p.articles.last
  1001. assert_match('Owner has changed', article_p.subject)
  1002. assert_match('Zammad <zammad@localhost>', article_p.from)
  1003. assert_match('martin@example.com', article_p.to)
  1004. assert_no_match('config\.', article_p.body)
  1005. assert_match('http://zammad.example.com', article_p.body)
  1006. assert_no_match('ticket.', article_p.body)
  1007. assert_match(ticket_p.number, article_p.body)
  1008. assert_equal('text/html', article_p.content_type)
  1009. # should not trigger
  1010. trigger1 = Trigger.create_or_update(
  1011. name: 'owner update - to customer',
  1012. condition: {
  1013. 'ticket.owner_id' => {
  1014. 'operator' => 'has changed',
  1015. 'pre_condition' => 'current_user.id',
  1016. 'value' => '',
  1017. 'value_completion' => '',
  1018. },
  1019. 'ticket.action' => {
  1020. 'operator' => 'is',
  1021. 'value' => 'create',
  1022. },
  1023. },
  1024. perform: {
  1025. 'notification.email' => {
  1026. 'body' => '<p>The owner of ticket (Ticket##{ticket.number}) has changed.<p>
  1027. <br/>
  1028. <p>To provide additional information, please reply to this email or click on the following link:
  1029. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  1030. </p>
  1031. <br/>
  1032. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  1033. 'recipient' => 'ticket_customer',
  1034. 'subject' => 'Owner has changed (#{ticket.title})',
  1035. },
  1036. },
  1037. disable_notification: true,
  1038. active: true,
  1039. created_by_id: 1,
  1040. updated_by_id: 1,
  1041. )
  1042. # process mail without Precedence header
  1043. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  1044. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, content)
  1045. assert_equal(1, ticket_p.articles.count)
  1046. Observer::Transaction.commit
  1047. assert_equal(1, ticket_p.articles.count)
  1048. ticket_p.owner = agent1
  1049. ticket_p.save!
  1050. Observer::Transaction.commit
  1051. assert_equal(1, ticket_p.articles.count)
  1052. end
  1053. test '5 notify owner' do
  1054. trigger1 = Trigger.create_or_update(
  1055. name: 'aaa notify mail',
  1056. condition: {
  1057. 'ticket.state_id' => {
  1058. 'operator' => 'is',
  1059. 'value' => Ticket::State.all.pluck(:id),
  1060. },
  1061. 'ticket.action' => {
  1062. 'operator' => 'is',
  1063. 'value' => 'update',
  1064. },
  1065. },
  1066. perform: {
  1067. 'notification.email' => {
  1068. 'body' => 'some lala',
  1069. 'recipient' => 'ticket_owner',
  1070. 'subject' => 'CC NOTE (#{ticket.title})!',
  1071. },
  1072. },
  1073. disable_notification: true,
  1074. active: true,
  1075. created_by_id: 1,
  1076. updated_by_id: 1,
  1077. )
  1078. groups = Group.where(name: 'Users')
  1079. roles = Role.where(name: 'Agent')
  1080. agent = User.create_or_update(
  1081. login: 'agent@example.com',
  1082. firstname: 'Trigger',
  1083. lastname: 'Agent1',
  1084. email: 'agent@example.com',
  1085. password: 'agentpw',
  1086. active: true,
  1087. roles: roles,
  1088. groups: groups,
  1089. updated_by_id: 1,
  1090. created_by_id: 1,
  1091. )
  1092. ticket1 = Ticket.create!(
  1093. title: 'test 123',
  1094. owner: agent,
  1095. group: Group.lookup(name: 'Users'),
  1096. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1097. updated_by_id: 1,
  1098. created_by_id: 1,
  1099. )
  1100. Ticket::Article.create!(
  1101. ticket_id: ticket1.id,
  1102. from: 'some_sender@example.com',
  1103. to: 'some_recipient@example.com',
  1104. subject: 'some subject',
  1105. message_id: 'some@id',
  1106. body: "some message <b>note</b>\nnew line",
  1107. internal: false,
  1108. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1109. type: Ticket::Article::Type.find_by(name: 'note'),
  1110. updated_by_id: 1,
  1111. created_by_id: 1,
  1112. )
  1113. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1114. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1115. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1116. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1117. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1118. assert_equal([], ticket1.tag_list)
  1119. Observer::Transaction.commit
  1120. assert_equal(1, ticket1.articles.count)
  1121. Ticket::Article.create!(
  1122. ticket_id: ticket1.id,
  1123. from: 'some_sender@example.com',
  1124. to: 'some_recipient@example.com',
  1125. subject: 'update',
  1126. message_id: 'some@id',
  1127. content_type: 'text/html',
  1128. body: 'update',
  1129. internal: false,
  1130. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1131. type: Ticket::Article::Type.find_by(name: 'note'),
  1132. updated_by_id: 1,
  1133. created_by_id: 1,
  1134. )
  1135. Observer::Transaction.commit
  1136. assert_equal(3, ticket1.articles.count)
  1137. trigger1 = Trigger.create_or_update(
  1138. name: 'aaa notify mail 2',
  1139. condition: {
  1140. 'ticket.state_id' => {
  1141. 'operator' => 'is',
  1142. 'value' => Ticket::State.all.pluck(:id),
  1143. },
  1144. 'ticket.action' => {
  1145. 'operator' => 'is',
  1146. 'value' => 'update',
  1147. },
  1148. },
  1149. perform: {
  1150. 'notification.email' => {
  1151. 'body' => 'some lala',
  1152. 'recipient' => 'ticket_owner',
  1153. 'subject' => 'CC NOTE (#{ticket.title})!',
  1154. },
  1155. },
  1156. disable_notification: true,
  1157. active: true,
  1158. created_by_id: 1,
  1159. updated_by_id: 1,
  1160. )
  1161. Ticket::Article.create!(
  1162. ticket_id: ticket1.id,
  1163. from: 'some_sender@example.com',
  1164. to: 'some_recipient@example.com',
  1165. subject: 'update',
  1166. message_id: 'some@id',
  1167. content_type: 'text/html',
  1168. body: 'update',
  1169. internal: false,
  1170. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1171. type: Ticket::Article::Type.find_by(name: 'note'),
  1172. updated_by_id: 1,
  1173. created_by_id: 1,
  1174. )
  1175. Observer::Transaction.commit
  1176. assert_equal(6, ticket1.articles.count)
  1177. end
  1178. test '6 owner auto assignment' do
  1179. trigger1 = Trigger.create_or_update(
  1180. name: 'aaa auto assignment',
  1181. condition: {
  1182. 'ticket.owner_id' => {
  1183. 'operator' => 'is',
  1184. 'pre_condition' => 'not_set',
  1185. 'value' => '',
  1186. 'value_completion' => '',
  1187. },
  1188. 'ticket.action' => {
  1189. 'operator' => 'is',
  1190. 'value' => 'update',
  1191. },
  1192. },
  1193. perform: {
  1194. 'ticket.owner_id' => {
  1195. 'pre_condition' => 'current_user.id',
  1196. 'value' => '',
  1197. 'value_completion' => '',
  1198. },
  1199. },
  1200. disable_notification: true,
  1201. active: true,
  1202. created_by_id: 1,
  1203. updated_by_id: 1,
  1204. )
  1205. groups = Group.where(name: 'Users')
  1206. roles = Role.where(name: 'Agent')
  1207. agent = User.create_or_update(
  1208. login: 'agent@example.com',
  1209. firstname: 'Trigger',
  1210. lastname: 'Agent1',
  1211. email: 'agent@example.com',
  1212. password: 'agentpw',
  1213. active: true,
  1214. roles: roles,
  1215. groups: groups,
  1216. updated_by_id: 1,
  1217. created_by_id: 1,
  1218. )
  1219. ticket1 = Ticket.create!(
  1220. title: 'test 123',
  1221. #owner: agent,
  1222. group: Group.lookup(name: 'Users'),
  1223. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1224. updated_by_id: 1,
  1225. created_by_id: 1,
  1226. )
  1227. Ticket::Article.create!(
  1228. ticket_id: ticket1.id,
  1229. from: 'some_sender@example.com',
  1230. to: 'some_recipient@example.com',
  1231. subject: 'some subject',
  1232. message_id: 'some@id',
  1233. body: "some message <b>note</b>\nnew line",
  1234. internal: false,
  1235. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1236. type: Ticket::Article::Type.find_by(name: 'note'),
  1237. updated_by_id: 1,
  1238. created_by_id: 1,
  1239. )
  1240. Observer::Transaction.commit
  1241. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1242. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1243. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1244. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1245. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1246. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1247. assert_equal([], ticket1.tag_list)
  1248. UserInfo.current_user_id = agent.id
  1249. Ticket::Article.create!(
  1250. ticket_id: ticket1.id,
  1251. from: 'some_sender@example.com',
  1252. to: 'some_recipient@example.com',
  1253. subject: 'update',
  1254. message_id: 'some@id',
  1255. content_type: 'text/html',
  1256. body: 'update',
  1257. internal: false,
  1258. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1259. type: Ticket::Article::Type.find_by(name: 'note'),
  1260. )
  1261. Observer::Transaction.commit
  1262. UserInfo.current_user_id = nil
  1263. ticket1.reload
  1264. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1265. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1266. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1267. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1268. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1269. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1270. assert_equal([], ticket1.tag_list)
  1271. UserInfo.current_user_id = agent.id
  1272. ticket1.owner_id = 1
  1273. ticket1.save!
  1274. Observer::Transaction.commit
  1275. UserInfo.current_user_id = nil
  1276. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1277. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1278. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1279. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1280. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1281. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1282. assert_equal([], ticket1.tag_list)
  1283. end
  1284. test '6.1 owner auto assignment based on organization' do
  1285. trigger1 = Trigger.create_or_update(
  1286. name: 'aaa auto assignment',
  1287. condition: {
  1288. 'ticket.organization_id' => {
  1289. 'operator' => 'is not',
  1290. 'pre_condition' => 'not_set',
  1291. 'value' => '',
  1292. 'value_completion' => '',
  1293. },
  1294. 'ticket.action' => {
  1295. 'operator' => 'is',
  1296. 'value' => 'update',
  1297. },
  1298. },
  1299. perform: {
  1300. 'ticket.owner_id' => {
  1301. 'pre_condition' => 'current_user.id',
  1302. 'value' => '',
  1303. 'value_completion' => '',
  1304. },
  1305. },
  1306. disable_notification: true,
  1307. active: true,
  1308. created_by_id: 1,
  1309. updated_by_id: 1,
  1310. )
  1311. roles = Role.where(name: 'Agent')
  1312. groups = Group.where(name: 'Users')
  1313. agent = User.create_or_update(
  1314. login: 'agent@example.com',
  1315. firstname: 'Trigger',
  1316. lastname: 'Agent1',
  1317. email: 'agent@example.com',
  1318. password: 'agentpw',
  1319. active: true,
  1320. roles: roles,
  1321. groups: groups,
  1322. updated_by_id: 1,
  1323. created_by_id: 1,
  1324. )
  1325. roles = Role.where(name: 'Customer')
  1326. customer = User.create_or_update(
  1327. login: 'customer@example.com',
  1328. firstname: 'Trigger',
  1329. lastname: 'Customer1',
  1330. email: 'customer@example.com',
  1331. password: 'customerpw',
  1332. vip: true,
  1333. active: true,
  1334. roles: roles,
  1335. updated_by_id: 1,
  1336. created_by_id: 1,
  1337. )
  1338. ticket1 = Ticket.create!(
  1339. title: 'test 123',
  1340. group: Group.lookup(name: 'Users'),
  1341. customer: customer,
  1342. updated_by_id: 1,
  1343. created_by_id: 1,
  1344. )
  1345. Ticket::Article.create!(
  1346. ticket_id: ticket1.id,
  1347. from: 'some_sender@example.com',
  1348. to: 'some_recipient@example.com',
  1349. subject: 'some subject',
  1350. message_id: 'some@id',
  1351. body: "some message <b>note</b>\nnew line",
  1352. internal: false,
  1353. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1354. type: Ticket::Article::Type.find_by(name: 'note'),
  1355. updated_by_id: 1,
  1356. created_by_id: 1,
  1357. )
  1358. Observer::Transaction.commit
  1359. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1360. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1361. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1362. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1363. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1364. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1365. assert_equal([], ticket1.tag_list)
  1366. ticket1.update!(customer: User.lookup(email: 'nicole.braun@zammad.org') )
  1367. UserInfo.current_user_id = agent.id
  1368. Ticket::Article.create!(
  1369. ticket_id: ticket1.id,
  1370. from: 'some_sender@example.com',
  1371. to: 'some_recipient@example.com',
  1372. subject: 'update',
  1373. message_id: 'some@id',
  1374. content_type: 'text/html',
  1375. body: 'update',
  1376. internal: false,
  1377. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1378. type: Ticket::Article::Type.find_by(name: 'note'),
  1379. )
  1380. Observer::Transaction.commit
  1381. UserInfo.current_user_id = nil
  1382. ticket1.reload
  1383. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1384. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1385. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1386. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1387. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1388. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1389. assert_equal([], ticket1.tag_list)
  1390. end
  1391. test '6.2 owner auto assignment based on organization' do
  1392. trigger1 = Trigger.create_or_update(
  1393. name: 'aaa auto assignment',
  1394. condition: {
  1395. 'ticket.organization_id' => {
  1396. 'operator' => 'is',
  1397. 'pre_condition' => 'not_set',
  1398. 'value' => '',
  1399. 'value_completion' => '',
  1400. },
  1401. 'ticket.action' => {
  1402. 'operator' => 'is',
  1403. 'value' => 'update',
  1404. },
  1405. },
  1406. perform: {
  1407. 'ticket.owner_id' => {
  1408. 'pre_condition' => 'current_user.id',
  1409. 'value' => '',
  1410. 'value_completion' => '',
  1411. },
  1412. },
  1413. disable_notification: true,
  1414. active: true,
  1415. created_by_id: 1,
  1416. updated_by_id: 1,
  1417. )
  1418. groups = Group.where(name: 'Users')
  1419. roles = Role.where(name: 'Agent')
  1420. agent = User.create_or_update(
  1421. login: 'agent@example.com',
  1422. firstname: 'Trigger',
  1423. lastname: 'Agent1',
  1424. email: 'agent@example.com',
  1425. password: 'agentpw',
  1426. active: true,
  1427. roles: roles,
  1428. groups: groups,
  1429. updated_by_id: 1,
  1430. created_by_id: 1,
  1431. )
  1432. roles = Role.where(name: 'Customer')
  1433. customer = User.create_or_update(
  1434. login: 'customer@example.com',
  1435. firstname: 'Trigger',
  1436. lastname: 'Customer1',
  1437. email: 'customer@example.com',
  1438. password: 'customerpw',
  1439. vip: true,
  1440. active: true,
  1441. roles: roles,
  1442. updated_by_id: 1,
  1443. created_by_id: 1,
  1444. )
  1445. ticket1 = Ticket.create!(
  1446. title: 'test 123',
  1447. group: Group.lookup(name: 'Users'),
  1448. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1449. updated_by_id: 1,
  1450. created_by_id: 1,
  1451. )
  1452. Ticket::Article.create!(
  1453. ticket_id: ticket1.id,
  1454. from: 'some_sender@example.com',
  1455. to: 'some_recipient@example.com',
  1456. subject: 'some subject',
  1457. message_id: 'some@id',
  1458. body: "some message <b>note</b>\nnew line",
  1459. internal: false,
  1460. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1461. type: Ticket::Article::Type.find_by(name: 'note'),
  1462. updated_by_id: 1,
  1463. created_by_id: 1,
  1464. )
  1465. Observer::Transaction.commit
  1466. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1467. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1468. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1469. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1470. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1471. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1472. assert_equal([], ticket1.tag_list)
  1473. ticket1.update!(customer: customer )
  1474. UserInfo.current_user_id = agent.id
  1475. Ticket::Article.create!(
  1476. ticket_id: ticket1.id,
  1477. from: 'some_sender@example.com',
  1478. to: 'some_recipient@example.com',
  1479. subject: 'update',
  1480. message_id: 'some@id',
  1481. content_type: 'text/html',
  1482. body: 'update',
  1483. internal: false,
  1484. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1485. type: Ticket::Article::Type.find_by(name: 'note'),
  1486. )
  1487. Observer::Transaction.commit
  1488. UserInfo.current_user_id = nil
  1489. ticket1.reload
  1490. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1491. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1492. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1493. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1494. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1495. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1496. assert_equal([], ticket1.tag_list)
  1497. end
  1498. test '7 owner auto assignment' do
  1499. trigger1 = Trigger.create_or_update(
  1500. name: 'aaa auto assignment',
  1501. condition: {
  1502. 'ticket.owner_id' => {
  1503. 'operator' => 'is',
  1504. 'pre_condition' => 'not_set',
  1505. 'value' => '',
  1506. 'value_completion' => '',
  1507. },
  1508. 'article.type_id' => {
  1509. 'operator' => 'is',
  1510. 'value' => Ticket::Article::Type.find_by(name: 'note'),
  1511. },
  1512. 'article.sender_id' => {
  1513. 'operator' => 'is',
  1514. 'value' => Ticket::Article::Sender.find_by(name: 'Agent'),
  1515. },
  1516. },
  1517. perform: {
  1518. 'ticket.owner_id' => {
  1519. 'pre_condition' => 'current_user.id',
  1520. 'value' => '',
  1521. 'value_completion' => '',
  1522. },
  1523. },
  1524. disable_notification: true,
  1525. active: true,
  1526. created_by_id: 1,
  1527. updated_by_id: 1,
  1528. )
  1529. groups = Group.where(name: 'Users')
  1530. roles = Role.where(name: 'Agent')
  1531. agent1 = User.create_or_update(
  1532. login: 'agent@example.com',
  1533. firstname: 'Trigger',
  1534. lastname: 'Agent1',
  1535. email: 'agent@example.com',
  1536. password: 'agentpw',
  1537. active: true,
  1538. roles: roles,
  1539. groups: groups,
  1540. updated_by_id: 1,
  1541. created_by_id: 1,
  1542. )
  1543. agent2 = User.create_or_update(
  1544. login: 'agent@example.com',
  1545. firstname: 'Trigger',
  1546. lastname: 'Agent2',
  1547. email: 'agent@example.com',
  1548. password: 'agentpw',
  1549. active: true,
  1550. roles: roles,
  1551. groups: groups,
  1552. updated_by_id: 1,
  1553. created_by_id: 1,
  1554. )
  1555. ticket1 = Ticket.create!(
  1556. title: 'test 123',
  1557. #owner: agent,
  1558. group: Group.lookup(name: 'Users'),
  1559. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1560. updated_by_id: 1,
  1561. created_by_id: 1,
  1562. )
  1563. Ticket::Article.create!(
  1564. ticket_id: ticket1.id,
  1565. from: 'some_sender@example.com',
  1566. to: 'some_recipient@example.com',
  1567. subject: 'some subject',
  1568. message_id: 'some@id',
  1569. body: "some message <b>note</b>\nnew line",
  1570. internal: false,
  1571. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1572. type: Ticket::Article::Type.find_by(name: 'note'),
  1573. updated_by_id: 1,
  1574. created_by_id: 1,
  1575. )
  1576. Observer::Transaction.commit
  1577. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1578. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1579. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1580. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1581. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1582. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1583. assert_equal([], ticket1.tag_list)
  1584. UserInfo.current_user_id = agent1.id
  1585. Ticket::Article.create!(
  1586. ticket_id: ticket1.id,
  1587. from: 'some_sender@example.com',
  1588. to: 'some_recipient@example.com',
  1589. subject: 'update',
  1590. message_id: 'some@id',
  1591. content_type: 'text/html',
  1592. body: 'update',
  1593. internal: false,
  1594. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1595. type: Ticket::Article::Type.find_by(name: 'note'),
  1596. )
  1597. Observer::Transaction.commit
  1598. UserInfo.current_user_id = nil
  1599. ticket1.reload
  1600. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1601. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1602. assert_equal(agent1.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1603. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1604. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1605. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1606. assert_equal([], ticket1.tag_list)
  1607. UserInfo.current_user_id = agent1.id
  1608. ticket1.owner_id = 1
  1609. ticket1.save!
  1610. Observer::Transaction.commit
  1611. UserInfo.current_user_id = nil
  1612. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1613. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1614. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1615. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1616. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1617. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1618. assert_equal([], ticket1.tag_list)
  1619. UserInfo.current_user_id = agent1.id
  1620. Ticket::Article.create!(
  1621. ticket_id: ticket1.id,
  1622. from: 'some_sender@example.com',
  1623. to: 'some_recipient@example.com',
  1624. subject: 'update',
  1625. message_id: 'some@id',
  1626. content_type: 'text/html',
  1627. body: 'update',
  1628. internal: false,
  1629. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  1630. type: Ticket::Article::Type.find_by(name: 'note'),
  1631. )
  1632. Observer::Transaction.commit
  1633. UserInfo.current_user_id = nil
  1634. ticket1.reload
  1635. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1636. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1637. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1638. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1639. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1640. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  1641. assert_equal([], ticket1.tag_list)
  1642. UserInfo.current_user_id = agent2.id
  1643. ticket1.owner_id = agent2.id
  1644. ticket1.save!
  1645. Observer::Transaction.commit
  1646. UserInfo.current_user_id = nil
  1647. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1648. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1649. assert_equal(agent2.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1650. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1651. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1652. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  1653. assert_equal([], ticket1.tag_list)
  1654. UserInfo.current_user_id = agent1.id
  1655. Ticket::Article.create!(
  1656. ticket_id: ticket1.id,
  1657. from: 'some_sender@example.com',
  1658. to: 'some_recipient@example.com',
  1659. subject: 'update',
  1660. message_id: 'some@id',
  1661. content_type: 'text/html',
  1662. body: 'update',
  1663. internal: false,
  1664. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1665. type: Ticket::Article::Type.find_by(name: 'note'),
  1666. )
  1667. Observer::Transaction.commit
  1668. UserInfo.current_user_id = nil
  1669. ticket1.reload
  1670. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1671. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1672. assert_equal(agent1.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1673. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1674. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1675. assert_equal(4, ticket1.articles.count, 'ticket1.articles verify')
  1676. assert_equal([], ticket1.tag_list)
  1677. end
  1678. test '8 owner auto assignment' do
  1679. trigger1 = Trigger.create_or_update(
  1680. name: 'aaa auto assignment',
  1681. condition: {
  1682. 'ticket.owner_id' => {
  1683. 'operator' => 'is',
  1684. 'pre_condition' => 'not_set',
  1685. 'value' => '',
  1686. 'value_completion' => '',
  1687. },
  1688. 'ticket.priority_id' => {
  1689. 'operator' => 'has changed',
  1690. 'pre_condition' => '',
  1691. 'value' => '2',
  1692. 'value_completion' => '',
  1693. },
  1694. 'ticket.action' => {
  1695. 'operator' => 'is',
  1696. 'value' => 'update',
  1697. },
  1698. },
  1699. perform: {
  1700. 'ticket.owner_id' => {
  1701. 'pre_condition' => 'current_user.id',
  1702. 'value' => '',
  1703. 'value_completion' => '',
  1704. },
  1705. },
  1706. disable_notification: true,
  1707. active: true,
  1708. created_by_id: 1,
  1709. updated_by_id: 1,
  1710. )
  1711. groups = Group.where(name: 'Users')
  1712. roles = Role.where(name: 'Agent')
  1713. agent = User.create_or_update(
  1714. login: 'agent@example.com',
  1715. firstname: 'Trigger',
  1716. lastname: 'Agent1',
  1717. email: 'agent@example.com',
  1718. password: 'agentpw',
  1719. active: true,
  1720. roles: roles,
  1721. groups: groups,
  1722. updated_by_id: 1,
  1723. created_by_id: 1,
  1724. )
  1725. ticket1 = Ticket.create!(
  1726. title: 'test 123',
  1727. #owner: agent,
  1728. group: Group.lookup(name: 'Users'),
  1729. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1730. updated_by_id: 1,
  1731. created_by_id: 1,
  1732. )
  1733. Ticket::Article.create!(
  1734. ticket_id: ticket1.id,
  1735. from: 'some_sender@example.com',
  1736. to: 'some_recipient@example.com',
  1737. subject: 'some subject',
  1738. message_id: 'some@id',
  1739. body: "some message <b>note</b>\nnew line",
  1740. internal: false,
  1741. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1742. type: Ticket::Article::Type.find_by(name: 'note'),
  1743. updated_by_id: 1,
  1744. created_by_id: 1,
  1745. )
  1746. Observer::Transaction.commit
  1747. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1748. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1749. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1750. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1751. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1752. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1753. assert_equal([], ticket1.tag_list)
  1754. UserInfo.current_user_id = agent.id
  1755. Ticket::Article.create!(
  1756. ticket_id: ticket1.id,
  1757. from: 'some_sender@example.com',
  1758. to: 'some_recipient@example.com',
  1759. subject: 'update',
  1760. message_id: 'some@id',
  1761. content_type: 'text/html',
  1762. body: 'update',
  1763. internal: false,
  1764. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1765. type: Ticket::Article::Type.find_by(name: 'note'),
  1766. )
  1767. Observer::Transaction.commit
  1768. UserInfo.current_user_id = nil
  1769. ticket1.reload
  1770. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1771. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1772. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1773. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1774. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1775. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1776. assert_equal([], ticket1.tag_list)
  1777. UserInfo.current_user_id = agent.id
  1778. ticket1.priority = Ticket::Priority.find_by(name: '1 low')
  1779. ticket1.save!
  1780. Observer::Transaction.commit
  1781. UserInfo.current_user_id = nil
  1782. ticket1.reload
  1783. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1784. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1785. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1786. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1787. assert_equal('1 low', ticket1.priority.name, 'ticket1.priority verify')
  1788. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1789. assert_equal([], ticket1.tag_list)
  1790. UserInfo.current_user_id = agent.id
  1791. ticket1.owner_id = 1
  1792. ticket1.save!
  1793. Observer::Transaction.commit
  1794. UserInfo.current_user_id = nil
  1795. ticket1.reload
  1796. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1797. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1798. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1799. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1800. assert_equal('1 low', ticket1.priority.name, 'ticket1.priority verify')
  1801. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1802. assert_equal([], ticket1.tag_list)
  1803. UserInfo.current_user_id = agent.id
  1804. ticket1.owner_id = agent.id
  1805. ticket1.save!
  1806. Observer::Transaction.commit
  1807. UserInfo.current_user_id = nil
  1808. ticket1.reload
  1809. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1810. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1811. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1812. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1813. assert_equal('1 low', ticket1.priority.name, 'ticket1.priority verify')
  1814. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1815. assert_equal([], ticket1.tag_list)
  1816. end
  1817. test '9 vip priority set' do
  1818. trigger1 = Trigger.create_or_update(
  1819. name: 'aaa vip priority',
  1820. condition: {
  1821. 'customer.vip' => {
  1822. 'operator' => 'is',
  1823. 'value' => true,
  1824. },
  1825. },
  1826. perform: {
  1827. 'ticket.priority_id' => {
  1828. 'value' => Ticket::Priority.find_by(name: '3 high').id,
  1829. },
  1830. },
  1831. disable_notification: true,
  1832. active: true,
  1833. created_by_id: 1,
  1834. updated_by_id: 1,
  1835. )
  1836. groups = Group.where(name: 'Users')
  1837. roles = Role.where(name: 'Agent')
  1838. agent = User.create_or_update(
  1839. login: 'agent@example.com',
  1840. firstname: 'Trigger',
  1841. lastname: 'Agent1',
  1842. email: 'agent@example.com',
  1843. password: 'agentpw',
  1844. active: true,
  1845. roles: roles,
  1846. groups: groups,
  1847. updated_by_id: 1,
  1848. created_by_id: 1,
  1849. )
  1850. roles = Role.where(name: 'Customer')
  1851. customer = User.create_or_update(
  1852. login: 'customer@example.com',
  1853. firstname: 'Trigger',
  1854. lastname: 'Customer1',
  1855. email: 'customer@example.com',
  1856. password: 'customerpw',
  1857. vip: true,
  1858. active: true,
  1859. roles: roles,
  1860. updated_by_id: 1,
  1861. created_by_id: 1,
  1862. )
  1863. ticket1 = Ticket.create!(
  1864. title: 'test 123',
  1865. owner: agent,
  1866. customer: customer,
  1867. group: Group.lookup(name: 'Users'),
  1868. updated_by_id: 1,
  1869. created_by_id: 1,
  1870. )
  1871. Ticket::Article.create!(
  1872. ticket_id: ticket1.id,
  1873. from: 'some_sender@example.com',
  1874. to: 'some_recipient@example.com',
  1875. subject: 'some subject',
  1876. message_id: 'some@id',
  1877. body: "some message <b>note</b>\nnew line",
  1878. internal: false,
  1879. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1880. type: Ticket::Article::Type.find_by(name: 'note'),
  1881. updated_by_id: 1,
  1882. created_by_id: 1,
  1883. )
  1884. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1885. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1886. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1887. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  1888. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1889. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1890. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1891. assert_equal([], ticket1.tag_list)
  1892. Observer::Transaction.commit
  1893. ticket1.reload
  1894. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1895. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1896. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1897. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  1898. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1899. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  1900. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1901. assert_equal([], ticket1.tag_list)
  1902. customer.vip = false
  1903. customer.save!
  1904. ticket2 = Ticket.create!(
  1905. title: 'test 123',
  1906. owner: agent,
  1907. customer: customer,
  1908. group: Group.lookup(name: 'Users'),
  1909. updated_by_id: 1,
  1910. created_by_id: 1,
  1911. )
  1912. Ticket::Article.create!(
  1913. ticket_id: ticket2.id,
  1914. from: 'some_sender@example.com',
  1915. to: 'some_recipient@example.com',
  1916. subject: 'some subject',
  1917. message_id: 'some@id',
  1918. body: "some message <b>note</b>\nnew line",
  1919. internal: false,
  1920. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1921. type: Ticket::Article::Type.find_by(name: 'note'),
  1922. updated_by_id: 1,
  1923. created_by_id: 1,
  1924. )
  1925. assert_equal('test 123', ticket2.title, 'ticket2.title verify')
  1926. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  1927. assert_equal(agent.id, ticket2.owner_id, 'ticket2.owner_id verify')
  1928. assert_equal(customer.id, ticket2.customer_id, 'ticket2.customer_id verify')
  1929. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  1930. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  1931. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  1932. assert_equal([], ticket2.tag_list)
  1933. Observer::Transaction.commit
  1934. ticket2.reload
  1935. assert_equal('test 123', ticket2.title, 'ticket2.title verify')
  1936. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  1937. assert_equal(agent.id, ticket2.owner_id, 'ticket2.owner_id verify')
  1938. assert_equal(customer.id, ticket2.customer_id, 'ticket2.customer_id verify')
  1939. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  1940. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  1941. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  1942. assert_equal([], ticket2.tag_list)
  1943. end
  1944. test '10 owner auto assignment notify to customer' do
  1945. trigger1 = Trigger.create_or_update(
  1946. name: 'aaa auto assignment',
  1947. condition: {
  1948. 'ticket.owner_id' => {
  1949. 'operator' => 'has changed',
  1950. 'pre_condition' => '',
  1951. 'value' => '2',
  1952. 'value_completion' => '',
  1953. },
  1954. },
  1955. perform: {
  1956. 'notification.email' => {
  1957. 'body' => 'some lala',
  1958. 'recipient' => 'ticket_customer',
  1959. 'subject' => 'NEW OWNER (#{ticket.title})!',
  1960. },
  1961. },
  1962. disable_notification: true,
  1963. active: true,
  1964. created_by_id: 1,
  1965. updated_by_id: 1,
  1966. )
  1967. groups = Group.where(name: 'Users')
  1968. roles = Role.where(name: 'Agent')
  1969. agent1 = User.create_or_update(
  1970. login: 'agent1@example.com',
  1971. firstname: 'Trigger',
  1972. lastname: 'Agent1',
  1973. email: 'agent1@example.com',
  1974. password: 'agentpw',
  1975. active: true,
  1976. roles: roles,
  1977. groups: groups,
  1978. updated_by_id: 1,
  1979. created_by_id: 1,
  1980. )
  1981. agent2 = User.create_or_update(
  1982. login: 'agent2@example.com',
  1983. firstname: 'Trigger',
  1984. lastname: 'Agent2',
  1985. email: 'agent2@example.com',
  1986. password: 'agentpw',
  1987. active: true,
  1988. roles: roles,
  1989. groups: groups,
  1990. updated_by_id: 1,
  1991. created_by_id: 1,
  1992. )
  1993. ticket1 = Ticket.create!(
  1994. title: 'test 123',
  1995. group: Group.lookup(name: 'Users'),
  1996. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1997. updated_by_id: 1,
  1998. created_by_id: 1,
  1999. )
  2000. Ticket::Article.create!(
  2001. ticket_id: ticket1.id,
  2002. from: 'some_sender@example.com',
  2003. to: 'some_recipient@example.com',
  2004. subject: 'some subject',
  2005. message_id: 'some@id',
  2006. body: "some message <b>note</b>\nnew line",
  2007. internal: false,
  2008. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2009. type: Ticket::Article::Type.find_by(name: 'note'),
  2010. updated_by_id: 1,
  2011. created_by_id: 1,
  2012. )
  2013. Observer::Transaction.commit
  2014. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2015. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2016. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  2017. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2018. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2019. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  2020. assert_equal([], ticket1.tag_list)
  2021. UserInfo.current_user_id = agent1.id
  2022. ticket1.owner_id = agent1.id
  2023. ticket1.save!
  2024. Observer::Transaction.commit
  2025. UserInfo.current_user_id = nil
  2026. ticket1.reload
  2027. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2028. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2029. assert_equal(agent1.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2030. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2031. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2032. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2033. assert_equal([], ticket1.tag_list)
  2034. UserInfo.current_user_id = agent1.id
  2035. ticket1.owner_id = agent1.id
  2036. ticket1.save!
  2037. Observer::Transaction.commit
  2038. UserInfo.current_user_id = nil
  2039. ticket1.reload
  2040. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2041. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2042. assert_equal(agent1.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2043. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2044. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2045. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2046. assert_equal([], ticket1.tag_list)
  2047. UserInfo.current_user_id = agent1.id
  2048. ticket1.owner_id = agent2.id
  2049. ticket1.save!
  2050. Observer::Transaction.commit
  2051. UserInfo.current_user_id = nil
  2052. ticket1.reload
  2053. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2054. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2055. assert_equal(agent2.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2056. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2057. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2058. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  2059. assert_equal([], ticket1.tag_list)
  2060. end
  2061. test '11 notify to customer on public note' do
  2062. trigger1 = Trigger.create_or_update(
  2063. name: 'aaa notify to customer on public note',
  2064. condition: {
  2065. 'article.internal' => {
  2066. 'operator' => 'is',
  2067. 'value' => 'false',
  2068. },
  2069. 'article.sender_id' => {
  2070. 'operator' => 'is',
  2071. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  2072. },
  2073. 'article.type_id' => {
  2074. 'operator' => 'is',
  2075. 'value' => [
  2076. Ticket::Article::Type.lookup(name: 'note').id,
  2077. ],
  2078. },
  2079. },
  2080. perform: {
  2081. 'notification.email' => {
  2082. 'body' => 'some lala',
  2083. 'recipient' => 'ticket_customer',
  2084. 'subject' => 'UPDATE (#{ticket.title})!',
  2085. },
  2086. },
  2087. disable_notification: true,
  2088. active: true,
  2089. created_by_id: 1,
  2090. updated_by_id: 1,
  2091. )
  2092. groups = Group.where(name: 'Users')
  2093. roles = Role.where(name: 'Agent')
  2094. agent = User.create_or_update(
  2095. login: 'agent@example.com',
  2096. firstname: 'Trigger',
  2097. lastname: 'Agent1',
  2098. email: 'agent@example.com',
  2099. password: 'agentpw',
  2100. active: true,
  2101. roles: roles,
  2102. groups: groups,
  2103. updated_by_id: 1,
  2104. created_by_id: 1,
  2105. )
  2106. roles = Role.where(name: 'Customer')
  2107. customer = User.create_or_update(
  2108. login: 'customer@example.com',
  2109. firstname: 'Trigger',
  2110. lastname: 'Customer1',
  2111. email: 'customer@example.com',
  2112. password: 'customerpw',
  2113. vip: true,
  2114. active: true,
  2115. roles: roles,
  2116. updated_by_id: 1,
  2117. created_by_id: 1,
  2118. )
  2119. ticket1 = Ticket.create!(
  2120. title: 'test 123',
  2121. owner: agent,
  2122. customer: customer,
  2123. group: Group.lookup(name: 'Users'),
  2124. updated_by_id: 1,
  2125. created_by_id: 1,
  2126. )
  2127. Ticket::Article.create!(
  2128. ticket_id: ticket1.id,
  2129. from: 'some_sender@example.com',
  2130. to: 'some_recipient@example.com',
  2131. subject: 'some subject',
  2132. message_id: 'some@id',
  2133. body: "some message <b>note</b>\nnew line",
  2134. internal: false,
  2135. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2136. type: Ticket::Article::Type.find_by(name: 'note'),
  2137. updated_by_id: 1,
  2138. created_by_id: 1,
  2139. )
  2140. Observer::Transaction.commit
  2141. ticket1.reload
  2142. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2143. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2144. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2145. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2146. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2147. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2148. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2149. assert_equal([], ticket1.tag_list)
  2150. Ticket::Article.create!(
  2151. ticket_id: ticket1.id,
  2152. from: 'some_sender@example.com',
  2153. to: 'some_recipient@example.com',
  2154. subject: 'some subject',
  2155. message_id: 'some@id',
  2156. body: "some message <b>note</b>\nnew line",
  2157. internal: true,
  2158. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2159. type: Ticket::Article::Type.find_by(name: 'note'),
  2160. updated_by_id: 1,
  2161. created_by_id: 1,
  2162. )
  2163. Observer::Transaction.commit
  2164. ticket1.reload
  2165. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2166. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2167. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2168. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2169. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2170. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2171. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  2172. assert_equal([], ticket1.tag_list)
  2173. Ticket::Article.create!(
  2174. ticket_id: ticket1.id,
  2175. from: 'some_sender@example.com',
  2176. to: 'some_recipient@example.com',
  2177. subject: 'some subject',
  2178. message_id: 'some@id',
  2179. body: "some message <b>note</b>\nnew line",
  2180. internal: false,
  2181. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2182. type: Ticket::Article::Type.find_by(name: 'note'),
  2183. updated_by_id: 1,
  2184. created_by_id: 1,
  2185. )
  2186. Observer::Transaction.commit
  2187. ticket1.reload
  2188. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2189. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2190. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2191. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2192. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2193. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2194. assert_equal(5, ticket1.articles.count, 'ticket1.articles verify')
  2195. assert_equal([], ticket1.tag_list)
  2196. ticket1.priority = Ticket::Priority.find_by(name: '3 high')
  2197. ticket1.save!
  2198. article = Ticket::Article.create!(
  2199. ticket_id: ticket1.id,
  2200. from: 'some_sender@example.com',
  2201. to: 'some_recipient@example.com',
  2202. subject: 'some subject',
  2203. message_id: 'some@id',
  2204. body: "some message <b>note</b>\nnew line",
  2205. internal: true,
  2206. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2207. type: Ticket::Article::Type.find_by(name: 'note'),
  2208. updated_by_id: 1,
  2209. created_by_id: 1,
  2210. )
  2211. Observer::Transaction.commit
  2212. ticket1.reload
  2213. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2214. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2215. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2216. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2217. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2218. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  2219. assert_equal(6, ticket1.articles.count, 'ticket1.articles verify')
  2220. assert_equal([], ticket1.tag_list)
  2221. article.internal = false
  2222. article.save!
  2223. Observer::Transaction.commit
  2224. ticket1.reload
  2225. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2226. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2227. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2228. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2229. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2230. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  2231. assert_equal(6, ticket1.articles.count, 'ticket1.articles verify')
  2232. assert_equal([], ticket1.tag_list)
  2233. Ticket::Article.create!(
  2234. ticket_id: ticket1.id,
  2235. from: 'some_sender@example.com',
  2236. to: 'some_recipient@example.com',
  2237. subject: 'some subject',
  2238. message_id: 'some@id',
  2239. body: "some message <b>note</b>\nnew line",
  2240. internal: true,
  2241. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2242. type: Ticket::Article::Type.find_by(name: 'note'),
  2243. updated_by_id: 1,
  2244. created_by_id: 1,
  2245. )
  2246. Observer::Transaction.commit
  2247. ticket1.reload
  2248. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2249. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2250. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2251. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2252. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2253. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  2254. assert_equal(7, ticket1.articles.count, 'ticket1.articles verify')
  2255. assert_equal([], ticket1.tag_list)
  2256. end
  2257. test '12 notify on owner change' do
  2258. trigger1 = Trigger.create_or_update(
  2259. name: 'aaa notify to customer on public note',
  2260. condition: {
  2261. 'ticket.owner_id' => {
  2262. 'operator' => 'has changed',
  2263. 'pre_condition' => 'current_user.id',
  2264. 'value' => '',
  2265. 'value_completion' => '',
  2266. }
  2267. },
  2268. perform: {
  2269. 'notification.email' => {
  2270. 'body' => 'some lala',
  2271. 'recipient' => 'ticket_customer',
  2272. 'subject' => 'UPDATE (#{ticket.title})!',
  2273. },
  2274. },
  2275. disable_notification: true,
  2276. active: true,
  2277. created_by_id: 1,
  2278. updated_by_id: 1,
  2279. )
  2280. Trigger.create_or_update(
  2281. name: 'auto reply (on new tickets)',
  2282. condition: {
  2283. 'ticket.action' => {
  2284. 'operator' => 'is',
  2285. 'value' => 'create',
  2286. },
  2287. 'ticket.state_id' => {
  2288. 'operator' => 'is not',
  2289. 'value' => Ticket::State.lookup(name: 'closed').id,
  2290. },
  2291. 'article.type_id' => {
  2292. 'operator' => 'is',
  2293. 'value' => [
  2294. Ticket::Article::Type.lookup(name: 'email').id,
  2295. Ticket::Article::Type.lookup(name: 'phone').id,
  2296. Ticket::Article::Type.lookup(name: 'web').id,
  2297. ],
  2298. },
  2299. 'article.sender_id' => {
  2300. 'operator' => 'is',
  2301. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  2302. },
  2303. },
  2304. perform: {
  2305. 'notification.email' => {
  2306. 'body' => '<div>Your request <b>(#{config.ticket_hook}#{ticket.number})</b> has been received and will be reviewed by our support staff.</div>
  2307. <br/>
  2308. <div>To provide additional information, please reply to this email or click on the following link (for initial login, please request a new password):
  2309. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  2310. </div>
  2311. <br/>
  2312. <div>Your #{config.product_name} Team</div>
  2313. <br/>
  2314. <div><i><a href="https://zammad.com">Zammad</a>, your customer support system</i></div>',
  2315. 'recipient' => 'ticket_customer',
  2316. 'subject' => 'Thanks for your inquiry (#{ticket.title})',
  2317. },
  2318. },
  2319. active: true,
  2320. created_by_id: 1,
  2321. updated_by_id: 1,
  2322. )
  2323. Trigger.create_or_update(
  2324. name: 'auto reply (on follow up of tickets)',
  2325. condition: {
  2326. 'ticket.action' => {
  2327. 'operator' => 'is',
  2328. 'value' => 'update',
  2329. },
  2330. 'article.sender_id' => {
  2331. 'operator' => 'is',
  2332. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  2333. },
  2334. 'article.type_id' => {
  2335. 'operator' => 'is',
  2336. 'value' => [
  2337. Ticket::Article::Type.lookup(name: 'email').id,
  2338. Ticket::Article::Type.lookup(name: 'phone').id,
  2339. Ticket::Article::Type.lookup(name: 'web').id,
  2340. ],
  2341. },
  2342. },
  2343. perform: {
  2344. 'notification.email' => {
  2345. 'body' => '<div>Your follow up for <b>(#{config.ticket_hook}#{ticket.number})</b> has been received and will be reviewed by our support staff.</div>
  2346. <br/>
  2347. <div>To provide additional information, please reply to this email or click on the following link:
  2348. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  2349. </div>
  2350. <br/>
  2351. <div>Your #{config.product_name} Team</div>
  2352. <br/>
  2353. <div><i><a href="https://zammad.com">Zammad</a>, your customer support system</i></div>',
  2354. 'recipient' => 'ticket_customer',
  2355. 'subject' => 'Thanks for your follow up (#{ticket.title})',
  2356. },
  2357. },
  2358. active: true,
  2359. created_by_id: 1,
  2360. updated_by_id: 1,
  2361. )
  2362. groups = Group.where(name: 'Users')
  2363. roles = Role.where(name: 'Agent')
  2364. agent = User.create_or_update(
  2365. login: 'agent@example.com',
  2366. firstname: 'Trigger',
  2367. lastname: 'Agent1',
  2368. email: 'agent@example.com',
  2369. password: 'agentpw',
  2370. active: true,
  2371. roles: roles,
  2372. groups: groups,
  2373. updated_by_id: 1,
  2374. created_by_id: 1,
  2375. )
  2376. roles = Role.where(name: 'Customer')
  2377. customer = User.create_or_update(
  2378. login: 'customer@example.com',
  2379. firstname: 'Trigger',
  2380. lastname: 'Customer1',
  2381. email: 'customer@example.com',
  2382. password: 'customerpw',
  2383. vip: true,
  2384. active: true,
  2385. roles: roles,
  2386. updated_by_id: 1,
  2387. created_by_id: 1,
  2388. )
  2389. ticket1 = Ticket.create!(
  2390. title: 'test 123',
  2391. #owner: agent,
  2392. customer: customer,
  2393. group: Group.lookup(name: 'Users'),
  2394. updated_by_id: 1,
  2395. created_by_id: 1,
  2396. )
  2397. Ticket::Article.create!(
  2398. ticket_id: ticket1.id,
  2399. from: 'some_sender@example.com',
  2400. to: 'some_recipient@example.com',
  2401. subject: 'some subject',
  2402. message_id: 'some@id',
  2403. body: "some message <b>note</b>\nnew line",
  2404. internal: false,
  2405. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2406. type: Ticket::Article::Type.find_by(name: 'web'),
  2407. updated_by_id: 1,
  2408. created_by_id: 1,
  2409. )
  2410. Observer::Transaction.commit
  2411. ticket1.reload
  2412. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2413. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2414. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  2415. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2416. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2417. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2418. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2419. assert_equal([], ticket1.tag_list)
  2420. UserInfo.current_user_id = agent.id
  2421. ticket1.owner_id = agent.id
  2422. ticket1.save!
  2423. Observer::Transaction.commit
  2424. UserInfo.current_user_id = nil
  2425. ticket1.reload
  2426. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2427. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2428. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2429. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2430. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2431. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2432. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  2433. assert_equal([], ticket1.tag_list)
  2434. Ticket::Article.create!(
  2435. ticket_id: ticket1.id,
  2436. from: 'some_sender@example.com',
  2437. to: 'some_recipient@example.com',
  2438. subject: 'some subject',
  2439. message_id: 'some@id',
  2440. body: "some message <b>note</b>\nnew line",
  2441. internal: false,
  2442. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2443. type: Ticket::Article::Type.find_by(name: 'web'),
  2444. updated_by_id: 1,
  2445. created_by_id: 1,
  2446. )
  2447. Observer::Transaction.commit
  2448. ticket1.reload
  2449. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2450. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2451. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2452. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2453. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2454. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2455. assert_equal(5, ticket1.articles.count, 'ticket1.articles verify')
  2456. assert_equal([], ticket1.tag_list)
  2457. UserInfo.current_user_id = agent.id
  2458. ticket1.owner_id = 1
  2459. ticket1.save!
  2460. Observer::Transaction.commit
  2461. UserInfo.current_user_id = nil
  2462. ticket1.reload
  2463. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2464. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2465. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  2466. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2467. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2468. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2469. assert_equal(6, ticket1.articles.count, 'ticket1.articles verify')
  2470. assert_equal([], ticket1.tag_list)
  2471. end
  2472. test '1 empty condition should not create errors' do
  2473. assert_raises(Exception) do
  2474. trigger_empty = Trigger.create_or_update(
  2475. name: 'aaa loop check',
  2476. condition: {
  2477. 'ticket.number' => {
  2478. 'operator' => 'contains',
  2479. 'value' => '',
  2480. },
  2481. },
  2482. perform: {
  2483. 'notification.email' => {
  2484. 'body' => 'some lala',
  2485. 'recipient' => 'ticket_customer',
  2486. 'subject' => 'Thanks for your inquiry - loop check (#{ticket.title})!',
  2487. },
  2488. },
  2489. disable_notification: true,
  2490. active: true,
  2491. created_by_id: 1,
  2492. updated_by_id: 1,
  2493. )
  2494. end
  2495. end
  2496. test 'article_last_sender trigger -> reply_to' do
  2497. trigger = Trigger.create_or_update(
  2498. name: 'auto reply',
  2499. condition: {
  2500. 'ticket.action' => {
  2501. 'operator' => 'is',
  2502. 'value' => 'create',
  2503. },
  2504. 'ticket.state_id' => {
  2505. 'operator' => 'is',
  2506. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2507. }
  2508. },
  2509. perform: {
  2510. 'notification.email' => {
  2511. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2512. 'recipient' => 'article_last_sender',
  2513. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2514. },
  2515. },
  2516. disable_notification: true,
  2517. active: true,
  2518. created_by_id: 1,
  2519. updated_by_id: 1,
  2520. )
  2521. ticket1 = Ticket.create!(
  2522. title: "some <b>title</b>\n äöüß",
  2523. group: Group.lookup(name: 'Users'),
  2524. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2525. updated_by_id: 1,
  2526. created_by_id: 1,
  2527. )
  2528. Ticket::Article.create!(
  2529. ticket_id: ticket1.id,
  2530. from: 'some_sender@example.com',
  2531. to: 'some_recipient+from@example.com',
  2532. reply_to: 'some_recipient+reply_to@example.com',
  2533. subject: 'some subject',
  2534. message_id: 'some@id',
  2535. body: "some message <b>note</b>\nnew line",
  2536. internal: false,
  2537. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2538. type: Ticket::Article::Type.find_by(name: 'note'),
  2539. updated_by_id: 1,
  2540. created_by_id: 1,
  2541. )
  2542. Observer::Transaction.commit
  2543. ticket1.reload
  2544. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2545. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2546. auto_response = ticket1.articles.last
  2547. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2548. assert_match('some_recipient+reply_to@example.com', auto_response.to)
  2549. end
  2550. test 'article_last_sender trigger -> from' do
  2551. trigger = Trigger.create_or_update(
  2552. name: 'auto reply',
  2553. condition: {
  2554. 'ticket.action' => {
  2555. 'operator' => 'is',
  2556. 'value' => 'create',
  2557. },
  2558. 'ticket.state_id' => {
  2559. 'operator' => 'is',
  2560. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2561. }
  2562. },
  2563. perform: {
  2564. 'notification.email' => {
  2565. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2566. 'recipient' => 'article_last_sender',
  2567. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2568. },
  2569. },
  2570. disable_notification: true,
  2571. active: true,
  2572. created_by_id: 1,
  2573. updated_by_id: 1,
  2574. )
  2575. ticket1 = Ticket.create!(
  2576. title: "some <b>title</b>\n äöüß",
  2577. group: Group.lookup(name: 'Users'),
  2578. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2579. updated_by_id: 1,
  2580. created_by_id: 1,
  2581. )
  2582. Ticket::Article.create!(
  2583. ticket_id: ticket1.id,
  2584. from: 'some_sender+from@example.com',
  2585. to: 'some_recipient@example.com',
  2586. subject: 'some subject',
  2587. message_id: 'some@id',
  2588. body: "some message <b>note</b>\nnew line",
  2589. internal: false,
  2590. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2591. type: Ticket::Article::Type.find_by(name: 'email'),
  2592. updated_by_id: 1,
  2593. created_by_id: 1,
  2594. )
  2595. Observer::Transaction.commit
  2596. ticket1.reload
  2597. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2598. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2599. auto_response = ticket1.articles.last
  2600. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2601. assert_match('some_sender+from@example.com', auto_response.to)
  2602. end
  2603. test 'article_last_sender trigger -> origin_by_id' do
  2604. trigger = Trigger.create_or_update(
  2605. name: 'auto reply',
  2606. condition: {
  2607. 'ticket.action' => {
  2608. 'operator' => 'is',
  2609. 'value' => 'create',
  2610. },
  2611. 'ticket.state_id' => {
  2612. 'operator' => 'is',
  2613. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2614. }
  2615. },
  2616. perform: {
  2617. 'notification.email' => {
  2618. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2619. 'recipient' => 'article_last_sender',
  2620. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2621. },
  2622. },
  2623. disable_notification: true,
  2624. active: true,
  2625. created_by_id: 1,
  2626. updated_by_id: 1,
  2627. )
  2628. roles = Role.where(name: 'Customer')
  2629. customer1 = User.create_or_update(
  2630. login: 'customer+origin_by_id@example.com',
  2631. firstname: 'Trigger',
  2632. lastname: 'Customer1',
  2633. email: 'customer+origin_by_id@example.com',
  2634. password: 'customerpw',
  2635. active: true,
  2636. roles: roles,
  2637. updated_at: '2015-02-05 16:37:00',
  2638. updated_by_id: 1,
  2639. created_by_id: 1,
  2640. )
  2641. ticket1 = Ticket.create!(
  2642. title: "some <b>title</b>\n äöüß",
  2643. group: Group.lookup(name: 'Users'),
  2644. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2645. updated_by_id: 1,
  2646. created_by_id: 1,
  2647. )
  2648. Ticket::Article.create!(
  2649. ticket_id: ticket1.id,
  2650. to: 'some_recipient@example.com',
  2651. subject: 'some subject',
  2652. message_id: 'some@id',
  2653. body: "some message <b>note</b>\nnew line",
  2654. internal: false,
  2655. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2656. type: Ticket::Article::Type.find_by(name: 'email'),
  2657. origin_by_id: customer1.id,
  2658. updated_by_id: 1,
  2659. created_by_id: 1,
  2660. )
  2661. Observer::Transaction.commit
  2662. ticket1.reload
  2663. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2664. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2665. auto_response = ticket1.articles.last
  2666. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2667. assert_match('customer+origin_by_id@example.com', auto_response.to)
  2668. end
  2669. test 'article_last_sender trigger -> created_by_id' do
  2670. trigger = Trigger.create_or_update(
  2671. name: 'auto reply',
  2672. condition: {
  2673. 'ticket.action' => {
  2674. 'operator' => 'is',
  2675. 'value' => 'create',
  2676. },
  2677. 'ticket.state_id' => {
  2678. 'operator' => 'is',
  2679. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2680. }
  2681. },
  2682. perform: {
  2683. 'notification.email' => {
  2684. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2685. 'recipient' => 'article_last_sender',
  2686. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2687. },
  2688. },
  2689. disable_notification: true,
  2690. active: true,
  2691. created_by_id: 1,
  2692. updated_by_id: 1,
  2693. )
  2694. roles = Role.where(name: 'Customer')
  2695. customer1 = User.create_or_update(
  2696. login: 'customer+created_by_id@example.com',
  2697. firstname: 'Trigger',
  2698. lastname: 'Customer1',
  2699. email: 'customer+created_by_id@example.com',
  2700. password: 'customerpw',
  2701. active: true,
  2702. roles: roles,
  2703. updated_at: '2015-02-05 16:37:00',
  2704. updated_by_id: 1,
  2705. created_by_id: 1,
  2706. )
  2707. ticket1 = Ticket.create!(
  2708. title: "some <b>title</b>\n äöüß",
  2709. group: Group.lookup(name: 'Users'),
  2710. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2711. updated_by_id: 1,
  2712. created_by_id: 1,
  2713. )
  2714. Ticket::Article.create!(
  2715. ticket_id: ticket1.id,
  2716. to: 'some_recipient@example.com',
  2717. subject: 'some subject',
  2718. message_id: 'some@id',
  2719. body: "some message <b>note</b>\nnew line",
  2720. internal: false,
  2721. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2722. type: Ticket::Article::Type.find_by(name: 'email'),
  2723. updated_by_id: customer1.id,
  2724. created_by_id: customer1.id,
  2725. )
  2726. Observer::Transaction.commit
  2727. ticket1.reload
  2728. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2729. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2730. auto_response = ticket1.articles.last
  2731. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2732. assert_match('customer+created_by_id@example.com', auto_response.to)
  2733. end
  2734. test 'multiple recipients owner_id, article_last_sender(reply_to) trigger' do
  2735. trigger = Trigger.create_or_update(
  2736. name: 'auto reply',
  2737. condition: {
  2738. 'ticket.action' => {
  2739. 'operator' => 'is',
  2740. 'value' => 'create',
  2741. },
  2742. 'ticket.state_id' => {
  2743. 'operator' => 'is',
  2744. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2745. }
  2746. },
  2747. perform: {
  2748. 'notification.email' => {
  2749. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2750. 'recipient' => %w[ticket_owner article_last_sender],
  2751. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2752. },
  2753. },
  2754. disable_notification: true,
  2755. active: true,
  2756. created_by_id: 1,
  2757. updated_by_id: 1,
  2758. )
  2759. admin = User.create_or_update(
  2760. login: 'admin+owner_recipient@example.com',
  2761. firstname: 'Role',
  2762. lastname: "Admin#{name}",
  2763. email: 'admin+owner_recipient@example.com',
  2764. password: 'adminpw',
  2765. active: true,
  2766. roles: Role.where(name: %w[Admin Agent]),
  2767. groups: Group.where(name: 'Users'),
  2768. updated_by_id: 1,
  2769. created_by_id: 1,
  2770. )
  2771. ticket1 = Ticket.create!(
  2772. title: "some <b>title</b>\n äöüß",
  2773. group: Group.lookup(name: 'Users'),
  2774. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2775. owner_id: admin.id,
  2776. updated_by_id: 1,
  2777. created_by_id: 1,
  2778. )
  2779. Ticket::Article.create!(
  2780. ticket_id: ticket1.id,
  2781. from: 'some_sender@example.com',
  2782. to: 'some_recipient+from@example.com',
  2783. reply_to: 'some_recipient+reply_to@example.com',
  2784. subject: 'some subject',
  2785. message_id: 'some@id',
  2786. body: "some message <b>note</b>\nnew line",
  2787. internal: false,
  2788. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2789. type: Ticket::Article::Type.find_by(name: 'note'),
  2790. updated_by_id: 1,
  2791. created_by_id: 1,
  2792. )
  2793. Observer::Transaction.commit
  2794. ticket1.reload
  2795. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2796. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2797. auto_response = ticket1.articles.last
  2798. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2799. assert_match('some_recipient+reply_to@example.com', auto_response.to)
  2800. assert_match('admin+owner_recipient@example.com', auto_response.to)
  2801. end
  2802. test 'article_last_sender trigger -> invalid reply_to' do
  2803. trigger = Trigger.create_or_update(
  2804. name: 'auto reply',
  2805. condition: {
  2806. 'ticket.action' => {
  2807. 'operator' => 'is',
  2808. 'value' => 'create',
  2809. },
  2810. 'ticket.state_id' => {
  2811. 'operator' => 'is',
  2812. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2813. }
  2814. },
  2815. perform: {
  2816. 'notification.email' => {
  2817. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2818. 'recipient' => 'article_last_sender',
  2819. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2820. },
  2821. },
  2822. disable_notification: true,
  2823. active: true,
  2824. created_by_id: 1,
  2825. updated_by_id: 1,
  2826. )
  2827. ticket1 = Ticket.create!(
  2828. title: "some <b>title</b>\n äöüß",
  2829. group: Group.lookup(name: 'Users'),
  2830. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2831. updated_by_id: 1,
  2832. created_by_id: 1,
  2833. )
  2834. Ticket::Article.create!(
  2835. ticket_id: ticket1.id,
  2836. from: 'some_sender@example.com',
  2837. to: 'some_recipient+from@example.com',
  2838. reply_to: 'Blub blub blub some_recipient+reply_to@example',
  2839. subject: 'some subject',
  2840. message_id: 'some@id',
  2841. body: "some message <b>note</b>\nnew line",
  2842. internal: false,
  2843. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2844. type: Ticket::Article::Type.find_by(name: 'note'),
  2845. updated_by_id: 1,
  2846. created_by_id: 1,
  2847. )
  2848. Observer::Transaction.commit
  2849. ticket1.reload
  2850. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2851. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  2852. end
  2853. test '2 loop check' do
  2854. trigger1 = Trigger.create_or_update(
  2855. name: 'aaa loop check',
  2856. condition: {
  2857. 'ticket.state_id' => {
  2858. 'operator' => 'is',
  2859. 'value' => Ticket::State.all.pluck(:id),
  2860. },
  2861. 'article.sender_id' => {
  2862. 'operator' => 'is',
  2863. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  2864. },
  2865. 'article.type_id' => {
  2866. 'operator' => 'is',
  2867. 'value' => [
  2868. Ticket::Article::Type.lookup(name: 'email').id,
  2869. Ticket::Article::Type.lookup(name: 'phone').id,
  2870. Ticket::Article::Type.lookup(name: 'web').id,
  2871. ],
  2872. },
  2873. },
  2874. perform: {
  2875. 'notification.email' => {
  2876. 'body' => 'some lala',
  2877. 'recipient' => 'ticket_customer',
  2878. 'subject' => 'Thanks for your inquiry - loop check (#{ticket.title})!',
  2879. },
  2880. },
  2881. disable_notification: true,
  2882. active: true,
  2883. created_by_id: 1,
  2884. updated_by_id: 1,
  2885. )
  2886. ticket1 = Ticket.create!(
  2887. title: 'loop try 1',
  2888. group: Group.lookup(name: 'Users'),
  2889. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2890. updated_by_id: 1,
  2891. created_by_id: 1,
  2892. )
  2893. Ticket::Article.create!(
  2894. ticket_id: ticket1.id,
  2895. from: 'some_loop_sender@example.com',
  2896. to: 'some_loop_recipient@example.com',
  2897. subject: 'some subject',
  2898. message_id: 'some@id',
  2899. body: "some message <b>note</b>\nnew line",
  2900. internal: false,
  2901. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2902. type: Ticket::Article::Type.find_by(name: 'email'),
  2903. updated_by_id: 1,
  2904. created_by_id: 1,
  2905. )
  2906. ticket1.reload
  2907. assert_equal(1, ticket1.articles.count)
  2908. Observer::Transaction.commit
  2909. ticket1.reload
  2910. assert_equal(2, ticket1.articles.count)
  2911. ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
  2912. ticket1.save!
  2913. Observer::Transaction.commit
  2914. ticket1.reload
  2915. assert_equal(2, ticket1.articles.count)
  2916. Ticket::Article.create!(
  2917. ticket_id: ticket1.id,
  2918. from: 'some_loop_sender@example.com',
  2919. to: 'some_loop_recipient@example.com',
  2920. subject: 'some subject 1234',
  2921. message_id: 'some@id',
  2922. content_type: 'text/html',
  2923. body: 'some message <b>note</b><br>new line',
  2924. internal: false,
  2925. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2926. type: Ticket::Article::Type.find_by(name: 'email'),
  2927. updated_by_id: 1,
  2928. created_by_id: 1,
  2929. )
  2930. Observer::Transaction.commit
  2931. ticket1.reload
  2932. assert_equal(4, ticket1.articles.count)
  2933. assert_equal('some_loop_sender@example.com', ticket1.articles[2].from)
  2934. assert_equal('nicole.braun@zammad.org', ticket1.articles[3].to)
  2935. Ticket::Article.create!(
  2936. ticket_id: ticket1.id,
  2937. from: 'some_loop_sender@example.com',
  2938. to: 'some_loop_recipient@example.com',
  2939. subject: 'some subject 1234',
  2940. message_id: 'some@id',
  2941. content_type: 'text/html',
  2942. body: 'some message <b>note</b><br>new line',
  2943. internal: false,
  2944. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2945. type: Ticket::Article::Type.find_by(name: 'email'),
  2946. updated_by_id: 1,
  2947. created_by_id: 1,
  2948. )
  2949. Observer::Transaction.commit
  2950. ticket1.reload
  2951. assert_equal(6, ticket1.articles.count)
  2952. assert_equal('some_loop_sender@example.com', ticket1.articles[4].from)
  2953. assert_equal('nicole.braun@zammad.org', ticket1.articles[5].to)
  2954. Ticket::Article.create!(
  2955. ticket_id: ticket1.id,
  2956. from: 'some_loop_sender@example.com',
  2957. to: 'some_loop_recipient@example.com',
  2958. subject: 'some subject 1234',
  2959. message_id: 'some@id',
  2960. content_type: 'text/html',
  2961. body: 'some message <b>note</b><br>new line',
  2962. internal: false,
  2963. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2964. type: Ticket::Article::Type.find_by(name: 'email'),
  2965. updated_by_id: 1,
  2966. created_by_id: 1,
  2967. )
  2968. Observer::Transaction.commit
  2969. ticket1.reload
  2970. assert_equal(8, ticket1.articles.count)
  2971. assert_equal('some_loop_sender@example.com', ticket1.articles[6].from)
  2972. assert_equal('nicole.braun@zammad.org', ticket1.articles[7].to)
  2973. Ticket::Article.create!(
  2974. ticket_id: ticket1.id,
  2975. from: 'some_loop_sender@example.com',
  2976. to: 'some_loop_recipient@example.com',
  2977. subject: 'some subject 1234',
  2978. message_id: 'some@id',
  2979. content_type: 'text/html',
  2980. body: 'some message <b>note</b><br>new line',
  2981. internal: false,
  2982. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2983. type: Ticket::Article::Type.find_by(name: 'email'),
  2984. updated_by_id: 1,
  2985. created_by_id: 1,
  2986. )
  2987. Observer::Transaction.commit
  2988. ticket1.reload
  2989. assert_equal(10, ticket1.articles.count)
  2990. assert_equal('some_loop_sender@example.com', ticket1.articles[8].from)
  2991. assert_equal('nicole.braun@zammad.org', ticket1.articles[9].to)
  2992. Ticket::Article.create!(
  2993. ticket_id: ticket1.id,
  2994. from: 'some_loop_sender@example.com',
  2995. to: 'some_loop_recipient@example.com',
  2996. subject: 'some subject 1234',
  2997. message_id: 'some@id',
  2998. content_type: 'text/html',
  2999. body: 'some message <b>note</b><br>new line',
  3000. internal: false,
  3001. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3002. type: Ticket::Article::Type.find_by(name: 'email'),
  3003. updated_by_id: 1,
  3004. created_by_id: 1,
  3005. )
  3006. Observer::Transaction.commit
  3007. ticket1.reload
  3008. assert_equal(12, ticket1.articles.count)
  3009. assert_equal('some_loop_sender@example.com', ticket1.articles[10].from)
  3010. assert_equal('nicole.braun@zammad.org', ticket1.articles[11].to)
  3011. Ticket::Article.create!(
  3012. ticket_id: ticket1.id,
  3013. from: 'some_loop_sender@example.com',
  3014. to: 'some_loop_recipient@example.com',
  3015. subject: 'some subject 1234',
  3016. message_id: 'some@id',
  3017. content_type: 'text/html',
  3018. body: 'some message <b>note</b><br>new line',
  3019. internal: false,
  3020. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3021. type: Ticket::Article::Type.find_by(name: 'email'),
  3022. updated_by_id: 1,
  3023. created_by_id: 1,
  3024. )
  3025. Observer::Transaction.commit
  3026. ticket1.reload
  3027. assert_equal(14, ticket1.articles.count)
  3028. assert_equal('some_loop_sender@example.com', ticket1.articles[12].from)
  3029. assert_equal('nicole.braun@zammad.org', ticket1.articles[13].to)
  3030. Ticket::Article.create!(
  3031. ticket_id: ticket1.id,
  3032. from: 'some_loop_sender@example.com',
  3033. to: 'some_loop_recipient@example.com',
  3034. subject: 'some subject 1234',
  3035. message_id: 'some@id',
  3036. content_type: 'text/html',
  3037. body: 'some message <b>note</b><br>new line',
  3038. internal: false,
  3039. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3040. type: Ticket::Article::Type.find_by(name: 'email'),
  3041. updated_by_id: 1,
  3042. created_by_id: 1,
  3043. )
  3044. Observer::Transaction.commit
  3045. ticket1.reload
  3046. assert_equal(16, ticket1.articles.count)
  3047. assert_equal('some_loop_sender@example.com', ticket1.articles[14].from)
  3048. assert_equal('nicole.braun@zammad.org', ticket1.articles[15].to)
  3049. Ticket::Article.create!(
  3050. ticket_id: ticket1.id,
  3051. from: 'some_loop_sender@example.com',
  3052. to: 'some_loop_recipient@example.com',
  3053. subject: 'some subject 1234',
  3054. message_id: 'some@id',
  3055. content_type: 'text/html',
  3056. body: 'some message <b>note</b><br>new line',
  3057. internal: false,
  3058. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3059. type: Ticket::Article::Type.find_by(name: 'email'),
  3060. updated_by_id: 1,
  3061. created_by_id: 1,
  3062. )
  3063. Observer::Transaction.commit
  3064. ticket1.reload
  3065. assert_equal(18, ticket1.articles.count)
  3066. assert_equal('some_loop_sender@example.com', ticket1.articles[16].from)
  3067. assert_equal('nicole.braun@zammad.org', ticket1.articles[17].to)
  3068. Ticket::Article.create!(
  3069. ticket_id: ticket1.id,
  3070. from: 'some_loop_sender@example.com',
  3071. to: 'some_loop_recipient@example.com',
  3072. subject: 'some subject 1234',
  3073. message_id: 'some@id',
  3074. content_type: 'text/html',
  3075. body: 'some message <b>note</b><br>new line',
  3076. internal: false,
  3077. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3078. type: Ticket::Article::Type.find_by(name: 'email'),
  3079. updated_by_id: 1,
  3080. created_by_id: 1,
  3081. )
  3082. Observer::Transaction.commit
  3083. ticket1.reload
  3084. assert_equal(20, ticket1.articles.count)
  3085. assert_equal('some_loop_sender@example.com', ticket1.articles[18].from)
  3086. assert_equal('nicole.braun@zammad.org', ticket1.articles[19].to)
  3087. Ticket::Article.create!(
  3088. ticket_id: ticket1.id,
  3089. from: 'some_loop_sender@example.com',
  3090. to: 'some_loop_recipient@example.com',
  3091. subject: 'some subject 1234',
  3092. message_id: 'some@id',
  3093. content_type: 'text/html',
  3094. body: 'some message <b>note</b><br>new line',
  3095. internal: false,
  3096. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3097. type: Ticket::Article::Type.find_by(name: 'email'),
  3098. updated_by_id: 1,
  3099. created_by_id: 1,
  3100. )
  3101. Observer::Transaction.commit
  3102. ticket1.reload
  3103. assert_equal(21, ticket1.articles.count)
  3104. assert_equal('some_loop_sender@example.com', ticket1.articles[20].from)
  3105. Ticket::Article.create!(
  3106. ticket_id: ticket1.id,
  3107. from: 'some_loop_sender@example.com',
  3108. to: 'some_loop_recipient@example.com',
  3109. subject: 'some subject 1234',
  3110. message_id: 'some@id',
  3111. content_type: 'text/html',
  3112. body: 'some message <b>note</b><br>new line',
  3113. internal: false,
  3114. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3115. type: Ticket::Article::Type.find_by(name: 'email'),
  3116. updated_by_id: 1,
  3117. created_by_id: 1,
  3118. )
  3119. Observer::Transaction.commit
  3120. ticket1.reload
  3121. assert_equal(22, ticket1.articles.count)
  3122. assert_equal('some_loop_sender@example.com', ticket1.articles[21].from)
  3123. end
  3124. test '3 invalid condition' do
  3125. trigger1 = Trigger.create_or_update(
  3126. name: 'aaa loop check',
  3127. condition: {
  3128. 'ticket.action' => {
  3129. 'operator' => 'is',
  3130. 'value' => 'create',
  3131. },
  3132. },
  3133. perform: {
  3134. 'ticket.tags' => {
  3135. 'operator' => 'add',
  3136. 'value' => 'xxx',
  3137. },
  3138. },
  3139. disable_notification: true,
  3140. active: true,
  3141. created_by_id: 1,
  3142. updated_by_id: 1,
  3143. )
  3144. trigger1.update_column(:condition, {
  3145. 'ticket.action' => {
  3146. 'operator' => 'is',
  3147. 'value' => 'create',
  3148. },
  3149. 'ticket.first_response_at' => {
  3150. 'operator' => 'before (absolute)',
  3151. 'value' => 'invalid invalid 4',
  3152. },
  3153. })
  3154. assert_equal('invalid invalid 4', trigger1.condition['ticket.first_response_at']['value'])
  3155. trigger2 = Trigger.create_or_update(
  3156. name: 'auto reply',
  3157. condition: {
  3158. 'ticket.action' => {
  3159. 'operator' => 'is',
  3160. 'value' => 'create',
  3161. },
  3162. 'ticket.state_id' => {
  3163. 'operator' => 'is',
  3164. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3165. }
  3166. },
  3167. perform: {
  3168. 'notification.email' => {
  3169. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3170. 'recipient' => 'ticket_customer',
  3171. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3172. },
  3173. 'ticket.priority_id' => {
  3174. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  3175. },
  3176. 'ticket.tags' => {
  3177. 'operator' => 'add',
  3178. 'value' => 'aa, kk',
  3179. },
  3180. },
  3181. disable_notification: true,
  3182. active: true,
  3183. created_by_id: 1,
  3184. updated_by_id: 1,
  3185. )
  3186. ticket1 = Ticket.create!(
  3187. title: "some <b>title</b>\n äöüß",
  3188. group: Group.lookup(name: 'Users'),
  3189. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3190. updated_by_id: 1,
  3191. created_by_id: 1,
  3192. )
  3193. Ticket::Article.create!(
  3194. ticket_id: ticket1.id,
  3195. from: 'some_sender@example.com',
  3196. to: 'some_recipient@example.com',
  3197. subject: 'some subject',
  3198. message_id: 'some@id',
  3199. body: "some message <b>note</b>\nnew line",
  3200. internal: false,
  3201. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3202. type: Ticket::Article::Type.find_by(name: 'note'),
  3203. updated_by_id: 1,
  3204. created_by_id: 1,
  3205. )
  3206. ticket1.reload
  3207. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  3208. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3209. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3210. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3211. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3212. assert_equal([], ticket1.tag_list)
  3213. Observer::Transaction.commit
  3214. ticket1.reload
  3215. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  3216. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3217. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3218. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  3219. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3220. assert_equal(%w[aa kk], ticket1.tag_list)
  3221. article1 = ticket1.articles.last
  3222. assert_match('Zammad <zammad@localhost>', article1.from)
  3223. assert_match('nicole.braun@zammad.org', article1.to)
  3224. assert_match('Thanks for your inquiry (some <b>title</b> äöüß)!', article1.subject)
  3225. assert_match('Braun<br>some &lt;b&gt;title&lt;/b&gt;', article1.body)
  3226. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt;<br>&gt; new line', article1.body)
  3227. assert_equal('text/html', article1.content_type)
  3228. end
  3229. test '4 tag based auto response' do
  3230. trigger1 = Trigger.create_or_update(
  3231. name: '100 add tag if sender 1',
  3232. condition: {
  3233. 'ticket.action' => {
  3234. 'operator' => 'is',
  3235. 'value' => 'create',
  3236. },
  3237. 'article.from' => {
  3238. 'operator' => 'contains',
  3239. 'value' => 'sender1',
  3240. },
  3241. },
  3242. perform: {
  3243. 'ticket.tags' => {
  3244. 'operator' => 'add',
  3245. 'value' => 'sender1',
  3246. },
  3247. },
  3248. disable_notification: true,
  3249. active: true,
  3250. created_by_id: 1,
  3251. updated_by_id: 1,
  3252. )
  3253. trigger2 = Trigger.create_or_update(
  3254. name: '200 add tag if sender 2',
  3255. condition: {
  3256. 'ticket.action' => {
  3257. 'operator' => 'is',
  3258. 'value' => 'create',
  3259. },
  3260. 'article.from' => {
  3261. 'operator' => 'contains',
  3262. 'value' => 'sender2',
  3263. },
  3264. },
  3265. perform: {
  3266. 'ticket.tags' => {
  3267. 'operator' => 'add',
  3268. 'value' => 'sender2',
  3269. },
  3270. },
  3271. disable_notification: true,
  3272. active: true,
  3273. created_by_id: 1,
  3274. updated_by_id: 1,
  3275. )
  3276. trigger3 = Trigger.create_or_update(
  3277. name: '300 auto reply',
  3278. condition: {
  3279. 'ticket.action' => {
  3280. 'operator' => 'is',
  3281. 'value' => 'create',
  3282. },
  3283. 'ticket.state_id' => {
  3284. 'operator' => 'is',
  3285. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3286. },
  3287. 'ticket.tags' => {
  3288. #'operator' => 'contains one not',
  3289. 'operator' => 'contains all not',
  3290. 'value' => 'sender1, sender2',
  3291. },
  3292. },
  3293. perform: {
  3294. 'notification.email' => {
  3295. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3296. 'recipient' => 'ticket_customer',
  3297. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3298. },
  3299. },
  3300. disable_notification: true,
  3301. active: true,
  3302. created_by_id: 1,
  3303. updated_by_id: 1,
  3304. )
  3305. ticket1 = Ticket.create!(
  3306. title: 'test 1',
  3307. group: Group.lookup(name: 'Users'),
  3308. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3309. updated_by_id: 1,
  3310. created_by_id: 1,
  3311. )
  3312. Ticket::Article.create!(
  3313. ticket_id: ticket1.id,
  3314. from: 'sender1@example.com',
  3315. to: 'some_recipient@example.com',
  3316. subject: 'some subject',
  3317. message_id: 'some@id',
  3318. body: "some message <b>note</b>\nnew line",
  3319. internal: false,
  3320. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3321. type: Ticket::Article::Type.find_by(name: 'email'),
  3322. updated_by_id: 1,
  3323. created_by_id: 1,
  3324. )
  3325. ticket1.reload
  3326. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3327. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3328. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3329. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3330. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3331. assert_equal([], ticket1.tag_list)
  3332. Observer::Transaction.commit
  3333. ticket1.reload
  3334. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3335. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3336. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3337. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3338. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3339. assert_equal(%w[sender1], ticket1.tag_list)
  3340. ticket2 = Ticket.create!(
  3341. title: 'test 2',
  3342. group: Group.lookup(name: 'Users'),
  3343. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3344. updated_by_id: 1,
  3345. created_by_id: 1,
  3346. )
  3347. Ticket::Article.create!(
  3348. ticket_id: ticket2.id,
  3349. from: 'sender2@example.com',
  3350. to: 'some_recipient@example.com',
  3351. subject: 'some subject',
  3352. message_id: 'some@id',
  3353. body: "some message <b>note</b>\nnew line",
  3354. internal: false,
  3355. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3356. type: Ticket::Article::Type.find_by(name: 'email'),
  3357. updated_by_id: 1,
  3358. created_by_id: 1,
  3359. )
  3360. ticket2.reload
  3361. assert_equal('test 2', ticket2.title, 'ticket2.title verify')
  3362. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3363. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3364. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3365. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  3366. assert_equal([], ticket2.tag_list)
  3367. Observer::Transaction.commit
  3368. ticket2.reload
  3369. assert_equal('test 2', ticket2.title, 'ticket2.title verify')
  3370. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3371. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3372. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3373. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  3374. assert_equal(%w[sender2], ticket2.tag_list)
  3375. ticket3 = Ticket.create!(
  3376. title: 'test 3',
  3377. group: Group.lookup(name: 'Users'),
  3378. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3379. updated_by_id: 1,
  3380. created_by_id: 1,
  3381. )
  3382. assert(ticket3, 'ticket3 created')
  3383. Ticket::Article.create!(
  3384. ticket_id: ticket3.id,
  3385. from: 'sender0@example.com',
  3386. to: 'some_recipient@example.com',
  3387. subject: 'some subject',
  3388. message_id: 'some@id',
  3389. body: "some message <b>note</b>\nnew line",
  3390. internal: false,
  3391. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3392. type: Ticket::Article::Type.find_by(name: 'email'),
  3393. updated_by_id: 1,
  3394. created_by_id: 1,
  3395. )
  3396. ticket3.reload
  3397. assert_equal('test 3', ticket3.title, 'ticket3.title verify')
  3398. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  3399. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  3400. assert_equal('2 normal', ticket3.priority.name, 'ticket3.priority verify')
  3401. assert_equal(1, ticket3.articles.count, 'ticket3.articles verify')
  3402. assert_equal([], ticket3.tag_list)
  3403. Observer::Transaction.commit
  3404. ticket3.reload
  3405. assert_equal('test 3', ticket3.title, 'ticket3.title verify')
  3406. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  3407. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  3408. assert_equal('2 normal', ticket3.priority.name, 'ticket3.priority verify')
  3409. assert_equal(2, ticket3.articles.count, 'ticket3.articles verify')
  3410. assert_equal([], ticket3.tag_list)
  3411. article1 = ticket3.articles.last
  3412. end
  3413. test 'article.body' do
  3414. trigger1 = Trigger.create_or_update(
  3415. name: 'auto reply',
  3416. condition: {
  3417. 'ticket.action' => {
  3418. 'operator' => 'is',
  3419. 'value' => 'create',
  3420. },
  3421. 'ticket.state_id' => {
  3422. 'operator' => 'is',
  3423. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3424. },
  3425. 'article.body' => {
  3426. 'operator' => 'contains',
  3427. 'value' => 'hello',
  3428. },
  3429. },
  3430. perform: {
  3431. 'notification.email' => {
  3432. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3433. 'recipient' => 'ticket_customer',
  3434. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3435. },
  3436. 'ticket.tags' => {
  3437. 'operator' => 'add',
  3438. 'value' => 'aa, kk',
  3439. },
  3440. },
  3441. disable_notification: true,
  3442. active: true,
  3443. created_by_id: 1,
  3444. updated_by_id: 1,
  3445. )
  3446. ticket1 = Ticket.create!(
  3447. title: 'test 1',
  3448. group: Group.lookup(name: 'Users'),
  3449. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3450. updated_by_id: 1,
  3451. created_by_id: 1,
  3452. )
  3453. Ticket::Article.create!(
  3454. ticket_id: ticket1.id,
  3455. from: 'some_sender@example.com',
  3456. to: 'some_recipient@example.com',
  3457. subject: 'some subject',
  3458. message_id: 'some@id',
  3459. body: 'some message <b>note</b> hello ',
  3460. internal: false,
  3461. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3462. type: Ticket::Article::Type.find_by(name: 'note'),
  3463. updated_by_id: 1,
  3464. created_by_id: 1,
  3465. )
  3466. ticket1.reload
  3467. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3468. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3469. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3470. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3471. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3472. assert_equal([], ticket1.tag_list)
  3473. Observer::Transaction.commit
  3474. ticket1.reload
  3475. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3476. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3477. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3478. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3479. assert_equal(%w[aa kk], ticket1.tag_list)
  3480. article1 = ticket1.articles.last
  3481. assert_match('Zammad <zammad@localhost>', article1.from)
  3482. assert_match('nicole.braun@zammad.org', article1.to)
  3483. assert_match('Thanks for your inquiry (test 1)!', article1.subject)
  3484. assert_match('some message', article1.body)
  3485. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt; hello', article1.body)
  3486. assert_equal('text/html', article1.content_type)
  3487. ticket2 = Ticket.create!(
  3488. title: 'test 1',
  3489. group: Group.lookup(name: 'Users'),
  3490. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3491. updated_by_id: 1,
  3492. created_by_id: 1,
  3493. )
  3494. Ticket::Article.create!(
  3495. ticket_id: ticket2.id,
  3496. from: 'some_sender@example.com',
  3497. to: 'some_recipient@example.com',
  3498. subject: 'some subject',
  3499. message_id: 'some@id',
  3500. body: 'some message <b>note</b>',
  3501. internal: false,
  3502. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3503. type: Ticket::Article::Type.find_by(name: 'note'),
  3504. updated_by_id: 1,
  3505. created_by_id: 1,
  3506. )
  3507. ticket2.reload
  3508. assert_equal('test 1', ticket2.title, 'ticket2.title verify')
  3509. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3510. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3511. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3512. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  3513. assert_equal([], ticket2.tag_list)
  3514. Observer::Transaction.commit
  3515. ticket2.reload
  3516. assert_equal('test 1', ticket2.title, 'ticket2.title verify')
  3517. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3518. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3519. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  3520. assert_equal(%w[], ticket2.tag_list)
  3521. trigger1 = Trigger.create_or_update(
  3522. name: 'auto reply',
  3523. condition: {
  3524. 'ticket.action' => {
  3525. 'operator' => 'is',
  3526. 'value' => 'create',
  3527. },
  3528. 'ticket.state_id' => {
  3529. 'operator' => 'is',
  3530. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3531. },
  3532. 'article.body' => {
  3533. 'operator' => 'contains not',
  3534. 'value' => 'hello',
  3535. },
  3536. },
  3537. perform: {
  3538. 'notification.email' => {
  3539. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3540. 'recipient' => 'ticket_customer',
  3541. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3542. },
  3543. 'ticket.tags' => {
  3544. 'operator' => 'add',
  3545. 'value' => 'aa, kk',
  3546. },
  3547. },
  3548. disable_notification: true,
  3549. active: true,
  3550. created_by_id: 1,
  3551. updated_by_id: 1,
  3552. )
  3553. ticket3 = Ticket.create!(
  3554. title: 'test 1',
  3555. group: Group.lookup(name: 'Users'),
  3556. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3557. updated_by_id: 1,
  3558. created_by_id: 1,
  3559. )
  3560. Ticket::Article.create!(
  3561. ticket_id: ticket3.id,
  3562. from: 'some_sender@example.com',
  3563. to: 'some_recipient@example.com',
  3564. subject: 'some subject',
  3565. message_id: 'some@id',
  3566. body: 'some message <b>note</b> hello ',
  3567. internal: false,
  3568. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3569. type: Ticket::Article::Type.find_by(name: 'note'),
  3570. updated_by_id: 1,
  3571. created_by_id: 1,
  3572. )
  3573. ticket3.reload
  3574. assert_equal('test 1', ticket3.title, 'ticket3.title verify')
  3575. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  3576. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  3577. assert_equal('2 normal', ticket3.priority.name, 'ticket3.priority verify')
  3578. assert_equal(1, ticket3.articles.count, 'ticket3.articles verify')
  3579. assert_equal([], ticket3.tag_list)
  3580. Observer::Transaction.commit
  3581. ticket3.reload
  3582. assert_equal('test 1', ticket3.title, 'ticket3.title verify')
  3583. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  3584. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  3585. assert_equal(1, ticket3.articles.count, 'ticket3.articles verify')
  3586. assert_equal(%w[], ticket3.tag_list)
  3587. ticket4 = Ticket.create!(
  3588. title: 'test 1',
  3589. group: Group.lookup(name: 'Users'),
  3590. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3591. updated_by_id: 1,
  3592. created_by_id: 1,
  3593. )
  3594. Ticket::Article.create!(
  3595. ticket_id: ticket4.id,
  3596. from: 'some_sender@example.com',
  3597. to: 'some_recipient@example.com',
  3598. subject: 'some subject',
  3599. message_id: 'some@id',
  3600. body: 'some message <b>note</b> 2',
  3601. internal: false,
  3602. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3603. type: Ticket::Article::Type.find_by(name: 'note'),
  3604. updated_by_id: 1,
  3605. created_by_id: 1,
  3606. )
  3607. ticket4.reload
  3608. assert_equal('test 1', ticket4.title, 'ticket4.title verify')
  3609. assert_equal('Users', ticket4.group.name, 'ticket4.group verify')
  3610. assert_equal('new', ticket4.state.name, 'ticket4.state verify')
  3611. assert_equal('2 normal', ticket4.priority.name, 'ticket4.priority verify')
  3612. assert_equal(1, ticket4.articles.count, 'ticket4.articles verify')
  3613. assert_equal([], ticket4.tag_list)
  3614. Observer::Transaction.commit
  3615. ticket4.reload
  3616. assert_equal('test 1', ticket4.title, 'ticket4.title verify')
  3617. assert_equal('Users', ticket4.group.name, 'ticket4.group verify')
  3618. assert_equal('new', ticket4.state.name, 'ticket4.state verify')
  3619. assert_equal(2, ticket4.articles.count, 'ticket4.articles verify')
  3620. assert_equal(%w[aa kk], ticket4.tag_list)
  3621. article4 = ticket4.articles.last
  3622. assert_match('Zammad <zammad@localhost>', article4.from)
  3623. assert_match('nicole.braun@zammad.org', article4.to)
  3624. assert_match('Thanks for your inquiry (test 1)!', article4.subject)
  3625. assert_match('some message', article4.body)
  3626. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt; 2', article4.body)
  3627. assert_equal('text/html', article4.content_type)
  3628. end
  3629. test 'change owner' do
  3630. roles = Role.where(name: 'Agent')
  3631. groups = Group.where(name: 'Users')
  3632. agent1 = User.create_or_update(
  3633. login: 'agent-has-changed@example.com',
  3634. firstname: 'Has Changed',
  3635. lastname: 'Agent1',
  3636. email: 'agent-has-changed@example.com',
  3637. password: 'agentpw',
  3638. active: true,
  3639. roles: roles,
  3640. groups: groups,
  3641. updated_at: '2015-02-05 16:37:00',
  3642. updated_by_id: 1,
  3643. created_by_id: 1,
  3644. )
  3645. agent2 = User.create_or_update(
  3646. login: 'agent-has-changed2@example.com',
  3647. firstname: 'Has Changed',
  3648. lastname: 'Agent2',
  3649. email: 'agent-has-changed2@example.com',
  3650. password: 'agentpw',
  3651. active: true,
  3652. roles: roles,
  3653. groups: groups,
  3654. updated_at: '2015-02-05 16:37:00',
  3655. updated_by_id: 1,
  3656. created_by_id: 1,
  3657. )
  3658. # multi tag trigger with changed owner
  3659. trigger1 = Trigger.create_or_update(
  3660. name: 'change owner',
  3661. condition: {
  3662. 'ticket.owner_id' => {
  3663. 'operator' => 'has changed',
  3664. },
  3665. 'ticket.tags' => {
  3666. 'operator' => 'contains one not',
  3667. 'value' => 'nosendmail test123'
  3668. }
  3669. },
  3670. perform: {
  3671. 'ticket.tags' => {
  3672. 'operator' => 'add',
  3673. 'value' => '123'
  3674. },
  3675. 'notification.email' => {
  3676. 'body' => 'some lala',
  3677. 'recipient' => 'ticket_customer',
  3678. 'subject' => 'Thanks for your inquiry - 1234 check (#{ticket.title})!',
  3679. },
  3680. },
  3681. disable_notification: true,
  3682. active: true,
  3683. created_by_id: 1,
  3684. updated_by_id: 1,
  3685. )
  3686. # single tag trigger with changed owner
  3687. trigger2 = Trigger.create_or_update(
  3688. name: 'change owner',
  3689. condition: {
  3690. 'ticket.owner_id' => {
  3691. 'operator' => 'has changed',
  3692. },
  3693. 'ticket.tags' => {
  3694. 'operator' => 'contains one not',
  3695. 'value' => 'nosendmail2',
  3696. }
  3697. },
  3698. perform: {
  3699. 'ticket.tags' => {
  3700. 'operator' => 'add',
  3701. 'value' => '123'
  3702. },
  3703. 'notification.email' => {
  3704. 'body' => 'some lala',
  3705. 'recipient' => 'ticket_customer',
  3706. 'subject' => 'Thanks for your inquiry - 1234 check (#{ticket.title})!',
  3707. },
  3708. },
  3709. disable_notification: true,
  3710. active: true,
  3711. created_by_id: 1,
  3712. updated_by_id: 1,
  3713. )
  3714. ticket1 = Ticket.create!(
  3715. title: "some title\n äöüß",
  3716. group: Group.lookup(name: 'Users'),
  3717. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3718. updated_by_id: 1,
  3719. created_by_id: 1,
  3720. )
  3721. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  3722. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3723. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3724. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3725. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  3726. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3727. assert_equal([], ticket1.tag_list, 'ticket1.tag_list')
  3728. ticket2 = Ticket.create!(
  3729. title: "some title\n äöüß",
  3730. group: Group.lookup(name: 'Users'),
  3731. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3732. updated_by_id: 1,
  3733. created_by_id: 1,
  3734. )
  3735. assert_equal('some title äöüß', ticket2.title, 'ticket1.title verify')
  3736. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3737. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3738. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3739. assert_equal(0, ticket2.articles.count, 'ticket2.articles verify')
  3740. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3741. assert_equal([], ticket1.tag_list, 'ticket2.tag_list')
  3742. # control test - should pass
  3743. # create common object tag
  3744. tag_object = Tag::Object.create_or_update(name: 'Ticket')
  3745. # add tag
  3746. ticket1.tag_add('thisisthebestjob', agent1.id)
  3747. # change owner
  3748. ticket1.owner_id = agent1.id
  3749. ticket1.save!
  3750. Observer::Transaction.commit
  3751. # this will add a tag by trigger
  3752. ticket1.reload
  3753. assert_equal('some title äöüß', ticket1.title, 'ticket2.title verify')
  3754. assert_equal('Users', ticket1.group.name, 'ticket2.group verify')
  3755. assert_equal('new', ticket1.state.name, 'ticket2.state verify')
  3756. assert_equal('2 normal', ticket1.priority.name, 'ticket2.priority verify')
  3757. assert_equal(1, ticket1.articles.count, 'ticket2.articles verify') # articles.count must be 1 if the tag is added
  3758. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3759. assert_equal(%w[thisisthebestjob 123], ticket1.tag_list, 'ticket2.tag_list')
  3760. # add tag nosendmail (to test the bug)
  3761. ticket1.tag_add('nosendmail', agent2.id)
  3762. # change owner
  3763. ticket1.owner_id = agent2.id
  3764. ticket1.save!
  3765. Observer::Transaction.commit
  3766. ticket1.reload
  3767. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  3768. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3769. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3770. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3771. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify') # articles.count must be 0 if adding tag is skipped
  3772. assert_equal('agent-has-changed2@example.com', agent2.login, 'verify agent')
  3773. assert_equal(%w[thisisthebestjob 123 nosendmail], ticket1.tag_list, 'ticket1.tag_list')
  3774. # add tag (to test the bug)
  3775. ticket1.tag_add('test123', agent2.id)
  3776. # change owner
  3777. ticket1.owner_id = agent1.id
  3778. ticket1.save!
  3779. Observer::Transaction.commit
  3780. ticket1.reload
  3781. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  3782. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3783. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3784. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3785. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify') # articles.count must be 0 if adding tag is skipped
  3786. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3787. assert_equal(%w[thisisthebestjob 123 nosendmail test123], ticket1.tag_list, 'ticket1.tag_list')
  3788. # add tag single tag 'nosendmail2' (to test the bug)
  3789. ticket2.tag_add('nosendmail2', agent1.id)
  3790. # change owner
  3791. ticket2.owner_id = agent1.id
  3792. ticket2.save!
  3793. Observer::Transaction.commit
  3794. ticket2.reload
  3795. assert_equal('some title äöüß', ticket2.title, 'ticket2.title verify')
  3796. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3797. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3798. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3799. assert_equal(0, ticket2.articles.count, 'ticket2.articles verify') # articles.count must be 0 if adding tag is skipped
  3800. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3801. assert_equal(['nosendmail2'], ticket2.tag_list, 'ticket2.tag_list')
  3802. end
  3803. test 'trigger auto reply with umlaut in form' do
  3804. trigger1 = Trigger.create_or_update(
  3805. name: 'auto reply',
  3806. condition: {
  3807. 'ticket.action' => {
  3808. 'operator' => 'is',
  3809. 'value' => 'create',
  3810. },
  3811. 'ticket.state_id' => {
  3812. 'operator' => 'is',
  3813. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3814. },
  3815. },
  3816. perform: {
  3817. 'notification.email' => {
  3818. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3819. 'recipient' => 'article_last_sender',
  3820. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3821. },
  3822. },
  3823. disable_notification: true,
  3824. active: true,
  3825. created_by_id: 1,
  3826. updated_by_id: 1,
  3827. )
  3828. ticket1 = Ticket.create!(
  3829. title: 'test 1',
  3830. group: Group.lookup(name: 'Users'),
  3831. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3832. updated_by_id: 1,
  3833. created_by_id: 1,
  3834. )
  3835. Ticket::Article.create!(
  3836. ticket_id: ticket1.id,
  3837. from: 'Sabine Schütz <some_sender@example.com>',
  3838. to: 'some_recipient@example.com',
  3839. subject: 'some subject',
  3840. message_id: 'some@id',
  3841. body: 'some message <b>note</b> hello ',
  3842. internal: false,
  3843. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3844. type: Ticket::Article::Type.find_by(name: 'email'),
  3845. updated_by_id: 1,
  3846. created_by_id: 1,
  3847. )
  3848. ticket1.reload
  3849. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3850. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3851. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3852. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3853. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3854. assert_equal('Sabine Schütz <some_sender@example.com>', ticket1.articles.first.from, 'ticket1.articles.first.from verify')
  3855. assert_equal([], ticket1.tag_list)
  3856. Observer::Transaction.commit
  3857. ticket1.reload
  3858. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3859. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3860. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3861. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3862. article1 = ticket1.articles.last
  3863. assert_match('Zammad <zammad@localhost>', article1.from)
  3864. assert_match('some_sender@example.com', article1.to)
  3865. assert_match('Thanks for your inquiry (test 1)!', article1.subject)
  3866. assert_match('some message', article1.body)
  3867. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt; hello', article1.body)
  3868. assert_equal('text/html', article1.content_type)
  3869. end
  3870. test 'trigger auto reply with 2 sender addresses in form' do
  3871. trigger1 = Trigger.create_or_update(
  3872. name: 'auto reply',
  3873. condition: {
  3874. 'ticket.action' => {
  3875. 'operator' => 'is',
  3876. 'value' => 'create',
  3877. },
  3878. 'ticket.state_id' => {
  3879. 'operator' => 'is',
  3880. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3881. },
  3882. },
  3883. perform: {
  3884. 'notification.email' => {
  3885. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3886. 'recipient' => 'article_last_sender',
  3887. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3888. },
  3889. },
  3890. disable_notification: true,
  3891. active: true,
  3892. created_by_id: 1,
  3893. updated_by_id: 1,
  3894. )
  3895. ticket1, article1, user, mail = Channel::EmailParser.new.process({}, File.read(Rails.root.join('test', 'data', 'mail', 'mail065.box')))
  3896. assert_equal('aaäöüßad asd', ticket1.title, 'ticket1.title verify')
  3897. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3898. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3899. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3900. article1 = ticket1.articles.last
  3901. assert_match('Zammad <zammad@localhost>', article1.from)
  3902. assert_match('smith@example.com', article1.to)
  3903. assert_match('Thanks for your inquiry (aaäöüßad asd)!', article1.subject)
  3904. assert_match('some text<br><br>aaäöüßad asd', article1.body)
  3905. assert_equal('text/html', article1.content_type)
  3906. end
  3907. test 'make sure attachments should be attached with content id' do
  3908. trigger1 = Trigger.create_or_update(
  3909. name: 'auto reply',
  3910. condition: {
  3911. 'ticket.action' => {
  3912. 'operator' => 'is',
  3913. 'value' => 'create',
  3914. },
  3915. 'ticket.state_id' => {
  3916. 'operator' => 'is',
  3917. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3918. },
  3919. },
  3920. perform: {
  3921. 'notification.email' => {
  3922. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}<br><img tabindex="0" style="width: 192px; height: 192px" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCADAAMADAREAAhEBAxEB/8QAHgABAAICAwEBAQAAAAAAAAAAAAcICQoFBgsDAQT/xAA7EAAABwEAAQMCAgYJAgcAAAAAAQIDBAUGBwgJERITIQoUFRciMXa1FiMyNzg5QVF3JLIYGSc1QkVh/8QAHQEBAAICAwEBAAAAAAAAAAAAAAQFAwYCBwgBCf/EAEURAAICAgEDAgMEBAkLBAMAAAECAAMEEQUGEiETMQciQQgUMlEjYXF2FTM1QnJzgZGzFjY3OFJiobGytLUXGILBJTRD/9oADAMBAAIRAxEAPwDU/G4SPARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARLM+HPi5uvNDyU5T4086cbiaXp+iTU/piTGflwM3TxYsiyv9PZx4xk+5WZ+nhzLSelk/qnGjLJslLNKT++Atjk6Wquy1z/uo">',
  3923. 'recipient' => 'article_last_sender',
  3924. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3925. },
  3926. },
  3927. disable_notification: true,
  3928. active: true,
  3929. created_by_id: 1,
  3930. updated_by_id: 1,
  3931. )
  3932. ticket1, article1, user, mail = Channel::EmailParser.new.process({}, File.read(Rails.root.join('test', 'data', 'mail', 'mail065.box')))
  3933. assert_equal('aaäöüßad asd', ticket1.title, 'ticket1.title verify')
  3934. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3935. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3936. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3937. article1 = ticket1.articles.last
  3938. assert_match('Zammad <zammad@localhost>', article1.from)
  3939. assert_match('smith@example.com', article1.to)
  3940. assert_match('Thanks for your inquiry (aaäöüßad asd)!', article1.subject)
  3941. assert_match(/.+cid:.+?@zammad.example.com.+/, article1.body)
  3942. assert_equal(1, article1.attachments.count)
  3943. assert_equal('789', article1.attachments[0].size)
  3944. assert_equal('text/html', article1.content_type)
  3945. end
  3946. end