ticket_selector.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. window.onload = function() {
  2. var ticketData = {
  3. "number": "72008",
  4. "title": "asdfasdf",
  5. "group_id": 1,
  6. "owner_id": 6,
  7. "updated_by_id": 6,
  8. "created_by_id": 6,
  9. "customer_id": 6,
  10. "state_id": 4,
  11. "priority_id": 2,
  12. "created_at": "2017-02-09T09:16:56.192Z",
  13. "updated_at": "2017-02-09T09:16:56.192Z",
  14. "pending_time": "2017-02-09T09:16:56.192Z",
  15. "aaaaa": "1234568791",
  16. "anrede": "Herr",
  17. "asdf": "",
  18. "organization_id": 6,
  19. "organization": {
  20. "name": "harald test gmbh",
  21. "domain": "www.harald-ist-cool.de",
  22. "shared": true,
  23. "note": "<div>harald test gmbh</div>",
  24. "member_ids": [
  25. 6,
  26. 2
  27. ],
  28. "active": true,
  29. "created_at": "2017-02-09T09:16:56.192Z",
  30. "updated_at": "2017-02-09T09:16:56.192Z",
  31. "domain_assignment": false,
  32. "updated_by_id": 6,
  33. "created_by_id": 6,
  34. "id": 6
  35. },
  36. "group": {
  37. "name": "Users",
  38. "assignment_timeout": null,
  39. "follow_up_possible": "reject",
  40. "follow_up_assignment": true,
  41. "email_address_id": 1,
  42. "signature_id": 1,
  43. "note": "Standard Group/Pool for Tickets.",
  44. "active": true,
  45. "updated_at": "2017-01-18T13:45:30.528Z",
  46. "id": 1
  47. },
  48. "owner": {
  49. "login": "-",
  50. "firstname": "-",
  51. "lastname": "",
  52. "email": "",
  53. "web": "",
  54. "password": "",
  55. "phone": "",
  56. "fax": "",
  57. "mobile": "",
  58. "street": "",
  59. "zip": "",
  60. "city": "",
  61. "country": "",
  62. "organization_id": null,
  63. "department": "",
  64. "note": "",
  65. "role_ids": [],
  66. "group_ids": [],
  67. "active": false,
  68. "updated_at": "2016-08-02T14:25:24.053Z",
  69. "address": "",
  70. "vip": false,
  71. "anrede": null,
  72. "asdf": null,
  73. "id": 1
  74. },
  75. "state": {
  76. "name": "closed",
  77. "note": null,
  78. "active": true,
  79. "id": 4
  80. },
  81. "priority": {
  82. "name": "2 normal",
  83. "note": null,
  84. "active": true,
  85. "updated_at": "2016-08-02T14:25:24.677Z",
  86. "id": 2
  87. },
  88. "article": {
  89. "from": "Test Master Agent",
  90. "to": "agent1@example.com",
  91. "cc": "agent1+cc@example.com",
  92. "body": "asdfasdfasdf<br><br><div data-signature=\"true\" data-signature-id=\"1\"> Test Master Agent<br><br>--<br> Super Support - Waterford Business Park<br> 5201 Blue Lagoon Drive - 8th Floor &amp; 9th Floor - Miami, 33126 USA<br> Email: hot@example.com - Web: http://www.example.com/<br>--</div>",
  93. "content_type": "text/html",
  94. "ticket_id": "2",
  95. "type_id": 1,
  96. "sender_id": 1,
  97. "internal": false,
  98. "in_reply_to": "<20170217100622.2.152971@zammad.example.com>",
  99. "form_id": "326044216"
  100. },
  101. "customer": {
  102. "login": "hc@zammad.com",
  103. "firstname": "Harald",
  104. "lastname": "Customer",
  105. "email": "hc@zammad.com",
  106. "web": "zammad.com",
  107. "password": "",
  108. "phone": "1234567894",
  109. "fax": "",
  110. "mobile": "",
  111. "street": "",
  112. "zip": "",
  113. "city": "",
  114. "country": "",
  115. "organization_id": 6,
  116. "created_by_id": 6,
  117. "updated_by_id": 6,
  118. "department": "",
  119. "note": "",
  120. "role_ids": [
  121. 3
  122. ],
  123. "group_ids": [],
  124. "active": true,
  125. "created_at": "2017-02-09T09:16:56.192Z",
  126. "updated_at": "2017-02-09T09:16:56.192Z",
  127. "address": "Walter-Gropius-Straße 17, 80807 München, Germany",
  128. "web": "www.harald-ist-cool.de",
  129. "vip": false,
  130. "id": 434
  131. },
  132. "tags": ["tag a", "tag b"],
  133. "escalation_at": "2017-02-09T09:16:56.192Z",
  134. "last_contact_agent_at": "2017-02-09T09:16:56.192Z",
  135. "last_contact_agent_at": "2017-02-09T09:16:56.192Z",
  136. "last_contact_at": "2017-02-09T09:16:56.192Z",
  137. "last_contact_customer_at": "2017-02-09T09:16:56.192Z",
  138. "first_response_at": "2017-02-09T09:16:56.192Z",
  139. "close_at": "2017-02-09T09:16:56.192Z",
  140. "id": 8
  141. };
  142. App.User.refresh([{
  143. "login": "hh@zammad.com",
  144. "firstname": "Harald",
  145. "lastname": "Habebe",
  146. "email": "hh@zammad.com",
  147. "web": "",
  148. "password": "",
  149. "phone": "",
  150. "fax": "",
  151. "mobile": "",
  152. "street": "",
  153. "zip": "",
  154. "city": "",
  155. "country": "",
  156. "organization_id": 6,
  157. "department": "",
  158. "note": "",
  159. "role_ids": [
  160. 1,
  161. 2,
  162. 5,
  163. 6,
  164. 4
  165. ],
  166. "group_ids": [
  167. 1
  168. ],
  169. "active": true,
  170. "updated_at": "2017-02-09T09:17:04.770Z",
  171. "address": "",
  172. "vip": false,
  173. "anrede": "",
  174. "asdf": "",
  175. "id": 6
  176. }]);
  177. var sessionData = App.User.find(6);
  178. /*
  179. * ------------------------------------------------------------------------
  180. * Test functions
  181. * ------------------------------------------------------------------------
  182. */
  183. var testContains = function (key, value, ticket) {
  184. setting = {
  185. "condition": {
  186. [key]: {
  187. "operator": "contains",
  188. "value": value
  189. },
  190. }
  191. };
  192. result = App.Ticket.selector(ticket, setting['condition']);
  193. equal(result, true, result);
  194. setting = {
  195. "condition": {
  196. [key]: {
  197. "operator": "contains not",
  198. "value": value
  199. },
  200. }
  201. };
  202. result = App.Ticket.selector(ticket, setting['condition']);
  203. equal(result, false, result);
  204. };
  205. var testIs = function (key, value, ticket) {
  206. setting = {
  207. "condition": {
  208. [key]: {
  209. "operator": "is",
  210. "value": value
  211. },
  212. }
  213. };
  214. result = App.Ticket.selector(ticket, setting['condition']);
  215. equal(result, true, result);
  216. setting = {
  217. "condition": {
  218. [key]: {
  219. "operator": "is not",
  220. "value": value
  221. },
  222. }
  223. };
  224. result = App.Ticket.selector(ticket, setting['condition']);
  225. equal(result, false, result);
  226. };
  227. var testPreConditionUser = function (key, specificValue, ticket, session) {
  228. App.Session.set(6);
  229. setting = {
  230. "condition": {
  231. [key]: {
  232. "operator": "is",
  233. "pre_condition": "current_user.id",
  234. "value": "",
  235. "value_completion": ""
  236. },
  237. }
  238. };
  239. result = App.Ticket.selector(ticket, setting['condition']);
  240. equal(result, true, result);
  241. setting = {
  242. "condition": {
  243. [key]: {
  244. "operator": "is not",
  245. "pre_condition": "current_user.id",
  246. "value": "",
  247. "value_completion": ""
  248. },
  249. }
  250. };
  251. result = App.Ticket.selector(ticket, setting['condition']);
  252. equal(result, false, result);
  253. setting = {
  254. "condition": {
  255. [key]: {
  256. "operator": "is",
  257. "pre_condition": "specific",
  258. "value": specificValue,
  259. "value_completion": "Nicole Braun <nicole.braun@zammad.org>"
  260. }
  261. }
  262. };
  263. result = App.Ticket.selector(ticket, setting['condition']);
  264. equal(result, true, result);
  265. setting = {
  266. "condition": {
  267. [key]: {
  268. "operator": "is not",
  269. "pre_condition": "specific",
  270. "value": specificValue,
  271. "value_completion": "Nicole Braun <nicole.braun@zammad.org>"
  272. }
  273. }
  274. };
  275. result = App.Ticket.selector(ticket, setting['condition']);
  276. equal(result, false, result);
  277. setting = {
  278. "condition": {
  279. [key]: {
  280. "operator": "is not",
  281. "pre_condition": "specific",
  282. "value": specificValue,
  283. "value_completion": "Nicole Braun <nicole.braun@zammad.org>"
  284. }
  285. }
  286. };
  287. result = App.Ticket.selector(ticket, setting['condition']);
  288. equal(result, false, result);
  289. setting = {
  290. "condition": {
  291. [key]: {
  292. "operator": "is",
  293. "pre_condition": "not_set",
  294. }
  295. }
  296. };
  297. result = App.Ticket.selector(ticket, setting['condition']);
  298. equal(result, false, result);
  299. setting = {
  300. "condition": {
  301. [key]: {
  302. "operator": "is not",
  303. "pre_condition": "not_set",
  304. }
  305. }
  306. };
  307. result = App.Ticket.selector(ticket, setting['condition']);
  308. equal(result, true, result);
  309. };
  310. var testPreConditionOrganization = function (key, specificValue, ticket, session) {
  311. App.Session.set(6);
  312. setting = {
  313. "condition": {
  314. [key]: {
  315. "operator": "is",
  316. "pre_condition": "current_user.organization_id",
  317. "value": "",
  318. "value_completion": ""
  319. },
  320. }
  321. };
  322. result = App.Ticket.selector(ticket, setting['condition']);
  323. equal(result, true, result);
  324. setting = {
  325. "condition": {
  326. [key]: {
  327. "operator": "is not",
  328. "pre_condition": "current_user.organization_id",
  329. "value": "",
  330. "value_completion": ""
  331. },
  332. }
  333. };
  334. result = App.Ticket.selector(ticket, setting['condition']);
  335. equal(result, false, result);
  336. setting = {
  337. "condition": {
  338. [key]: {
  339. "operator": "is",
  340. "pre_condition": "specific",
  341. "value": specificValue,
  342. "value_completion": "Nicole Braun <nicole.braun@zammad.org>"
  343. }
  344. }
  345. };
  346. result = App.Ticket.selector(ticket, setting['condition']);
  347. equal(result, true, result);
  348. setting = {
  349. "condition": {
  350. [key]: {
  351. "operator": "is not",
  352. "pre_condition": "specific",
  353. "value": specificValue,
  354. "value_completion": "Nicole Braun <nicole.braun@zammad.org>"
  355. }
  356. }
  357. };
  358. result = App.Ticket.selector(ticket, setting['condition']);
  359. equal(result, false, result);
  360. setting = {
  361. "condition": {
  362. [key]: {
  363. "operator": "is not",
  364. "pre_condition": "specific",
  365. "value": specificValue,
  366. "value_completion": "Nicole Braun <nicole.braun@zammad.org>"
  367. }
  368. }
  369. };
  370. result = App.Ticket.selector(ticket, setting['condition']);
  371. equal(result, false, result);
  372. setting = {
  373. "condition": {
  374. [key]: {
  375. "operator": "is",
  376. "pre_condition": "not_set",
  377. }
  378. }
  379. };
  380. result = App.Ticket.selector(ticket, setting['condition']);
  381. equal(result, false, result);
  382. setting = {
  383. "condition": {
  384. [key]: {
  385. "operator": "is not",
  386. "pre_condition": "not_set",
  387. }
  388. }
  389. };
  390. result = App.Ticket.selector(ticket, setting['condition']);
  391. equal(result, true, result);
  392. };
  393. var testPreConditionTags = function (key, ticket) {
  394. App.Session.set(6);
  395. setting = {
  396. "condition": {
  397. "ticket.tags": {
  398. "operator": "contains one",
  399. "value": "tag a",
  400. },
  401. }
  402. };
  403. result = App.Ticket.selector(ticket, setting['condition']);
  404. equal(result, true, result);
  405. setting = {
  406. "condition": {
  407. "ticket.tags": {
  408. "operator": "contains one",
  409. "value": "tag aa",
  410. },
  411. }
  412. };
  413. result = App.Ticket.selector(ticket, setting['condition']);
  414. equal(result, false, result);
  415. setting = {
  416. "condition": {
  417. "ticket.tags": {
  418. "operator": "contains all",
  419. "value": "tag a",
  420. },
  421. }
  422. };
  423. result = App.Ticket.selector(ticket, setting['condition']);
  424. equal(result, true, result);
  425. setting = {
  426. "condition": {
  427. "ticket.tags": {
  428. "operator": "contains all",
  429. "value": ["tag a", "not existing"],
  430. },
  431. }
  432. };
  433. result = App.Ticket.selector(ticket, setting['condition']);
  434. equal(result, false, result);
  435. setting = {
  436. "condition": {
  437. "ticket.tags": {
  438. "operator": "contains all not",
  439. "value": "tag a",
  440. },
  441. }
  442. };
  443. result = App.Ticket.selector(ticket, setting['condition']);
  444. equal(result, false, result);
  445. setting = {
  446. "condition": {
  447. "ticket.tags": {
  448. "operator": "contains all not",
  449. "value": ["tag a", "tag b"],
  450. },
  451. }
  452. };
  453. result = App.Ticket.selector(ticket, setting['condition']);
  454. equal(result, false, result);
  455. setting = {
  456. "condition": {
  457. "ticket.tags": {
  458. "operator": "contains all not",
  459. "value": ["tag a", "tag b", "tag c"],
  460. },
  461. }
  462. };
  463. result = App.Ticket.selector(ticket, setting['condition']);
  464. equal(result, false, result);
  465. setting = {
  466. "condition": {
  467. "ticket.tags": {
  468. "operator": "contains all not",
  469. "value": ["tag c", "tag d"],
  470. },
  471. }
  472. };
  473. result = App.Ticket.selector(ticket, setting['condition']);
  474. equal(result, true, result);
  475. setting = {
  476. "condition": {
  477. "ticket.tags": {
  478. "operator": "contains one not",
  479. "value": "tag a",
  480. },
  481. }
  482. };
  483. result = App.Ticket.selector(ticket, setting['condition']);
  484. equal(result, true, result);
  485. setting = {
  486. "condition": {
  487. "ticket.tags": {
  488. "operator": "contains one not",
  489. "value": ["tag a", "tag b"],
  490. },
  491. }
  492. };
  493. result = App.Ticket.selector(ticket, setting['condition']);
  494. equal(result, false, result);
  495. setting = {
  496. "condition": {
  497. "ticket.tags": {
  498. "operator": "contains one not",
  499. "value": ["tag a", "tag c"],
  500. },
  501. }
  502. };
  503. result = App.Ticket.selector(ticket, setting['condition']);
  504. equal(result, true, result);
  505. setting = {
  506. "condition": {
  507. "ticket.tags": {
  508. "operator": "contains one not",
  509. "value": ["tag c"],
  510. },
  511. }
  512. };
  513. result = App.Ticket.selector(ticket, setting['condition']);
  514. equal(result, true, result);
  515. };
  516. var testTime = function (key, value, ticket) {
  517. valueDate = new Date(value);
  518. compareDate = new Date( valueDate.setHours( valueDate.getHours() - 1 ) ).toISOString();
  519. setting = {
  520. "condition": {
  521. [key]: {
  522. "operator": "after (absolute)",
  523. "value": compareDate
  524. },
  525. }
  526. };
  527. result = App.Ticket.selector(ticket, setting['condition']);
  528. equal(result, true, result);
  529. valueDate = new Date(value);
  530. compareDate = new Date( valueDate.setHours( valueDate.getHours() + 1 ) ).toISOString();
  531. setting = {
  532. "condition": {
  533. [key]: {
  534. "operator": "after (absolute)",
  535. "value": compareDate
  536. },
  537. }
  538. };
  539. result = App.Ticket.selector(ticket, setting['condition']);
  540. equal(result, false, result);
  541. valueDate = new Date(value);
  542. compareDate = new Date( valueDate.setHours( valueDate.getHours() - 1 ) ).toISOString();
  543. setting = {
  544. "condition": {
  545. [key]: {
  546. "operator": "before (absolute)",
  547. "value": compareDate
  548. },
  549. }
  550. };
  551. result = App.Ticket.selector(ticket, setting['condition']);
  552. equal(result, false, result);
  553. valueDate = new Date(value);
  554. compareDate = new Date( valueDate.setHours( valueDate.getHours() + 1 ) ).toISOString();
  555. setting = {
  556. "condition": {
  557. [key]: {
  558. "operator": "before (absolute)",
  559. "value": compareDate
  560. },
  561. }
  562. };
  563. result = App.Ticket.selector(ticket, setting['condition']);
  564. equal(result, true, result);
  565. valueDate = new Date(value);
  566. compareDate = new Date( valueDate.setHours( valueDate.getHours() + 2 ) ).toISOString();
  567. setting = {
  568. "condition": {
  569. [key]: {
  570. "operator": "before (relative)",
  571. "value": 1,
  572. "range": "hour"
  573. },
  574. }
  575. };
  576. result = App.Ticket.selector(ticket, setting['condition']);
  577. equal(result, true, result);
  578. };
  579. var testTimeBeforeRelative = function (key, value, range, expectedResult, ticket) {
  580. setting = {
  581. "condition": {
  582. [key]: {
  583. "operator": "before (relative)",
  584. "value": value,
  585. "range": range
  586. },
  587. }
  588. };
  589. result = App.Ticket.selector(ticket, setting['condition']);
  590. equal(result, expectedResult, result);
  591. };
  592. var testTimeAfterRelative = function (key, value, range, expectedResult, ticket) {
  593. setting = {
  594. "condition": {
  595. [key]: {
  596. "operator": "after (relative)",
  597. "value": value,
  598. "range": range
  599. },
  600. }
  601. };
  602. result = App.Ticket.selector(ticket, setting['condition']);
  603. equal(result, expectedResult, result);
  604. };
  605. var testTimeWithinNextRelative = function (key, value, range, expectedResult, ticket) {
  606. setting = {
  607. "condition": {
  608. [key]: {
  609. "operator": "within next (relative)",
  610. "value": value,
  611. "range": range
  612. },
  613. }
  614. };
  615. result = App.Ticket.selector(ticket, setting['condition']);
  616. equal(result, expectedResult, result);
  617. };
  618. var testTimeWithinLastRelative = function (key, value, range, expectedResult, ticket) {
  619. setting = {
  620. "condition": {
  621. [key]: {
  622. "operator": "within last (relative)",
  623. "value": value,
  624. "range": range
  625. },
  626. }
  627. };
  628. result = App.Ticket.selector(ticket, setting['condition']);
  629. equal(result, expectedResult, result);
  630. };
  631. /*
  632. * ------------------------------------------------------------------------
  633. * Field tests
  634. * ------------------------------------------------------------------------
  635. */
  636. test("ticket number", function() {
  637. ticket = new App.Ticket();
  638. ticket.load(ticketData);
  639. testContains('ticket.number', '72', ticket);
  640. });
  641. test("ticket title", function() {
  642. ticket = new App.Ticket();
  643. ticket.load(ticketData);
  644. testContains('ticket.title', 'asd', ticket);
  645. });
  646. test("ticket customer_id", function() {
  647. ticket = new App.Ticket();
  648. ticket.load(ticketData);
  649. App.Session.set(6);
  650. testPreConditionUser('ticket.customer_id', '6', ticket, sessionData);
  651. });
  652. test("ticket organization_id", function() {
  653. ticket = new App.Ticket();
  654. ticket.load(ticketData);
  655. testPreConditionUser('ticket.organization_id', '6', ticket, sessionData);
  656. });
  657. test("ticket group_id", function() {
  658. ticket = new App.Ticket();
  659. ticket.load(ticketData);
  660. testIs('ticket.group_id', ['1'], ticket, sessionData);
  661. });
  662. test("ticket owner_id", function() {
  663. ticket = new App.Ticket();
  664. ticket.load(ticketData);
  665. App.Session.set(6);
  666. testPreConditionUser('ticket.owner_id', '6', ticket, sessionData);
  667. });
  668. test("ticket state_id", function() {
  669. ticket = new App.Ticket();
  670. ticket.load(ticketData);
  671. testIs('ticket.state_id', ['4'], ticket, sessionData);
  672. });
  673. test("ticket pending_time", function() {
  674. ticket = new App.Ticket();
  675. ticket.load(ticketData);
  676. testTime('ticket.pending_time', ticket.pending_time, ticket);
  677. // -------------------------
  678. // BEFORE TIME
  679. // -------------------------
  680. // hour
  681. ticket.pending_time = new Date().toISOString();
  682. testTimeBeforeRelative('ticket.pending_time', 1, 'hour', false, ticket);
  683. compareDate = new Date();
  684. compareDate.setTime( compareDate.getTime() - 60 * 60 * 2 * 1000);
  685. ticket.pending_time = compareDate.toISOString();
  686. testTimeBeforeRelative('ticket.pending_time', 1, 'hour', true, ticket);
  687. // day
  688. ticket.pending_time = new Date().toISOString();
  689. testTimeBeforeRelative('ticket.pending_time', 1, 'day', false, ticket);
  690. compareDate = new Date();
  691. compareDate.setTime( compareDate.getTime() - 60 * 60 * 48 * 1000);
  692. ticket.pending_time = compareDate.toISOString();
  693. testTimeBeforeRelative('ticket.pending_time', 1, 'day', true, ticket);
  694. // year
  695. ticket.pending_time = new Date().toISOString();
  696. testTimeBeforeRelative('ticket.pending_time', 1, 'year', false, ticket);
  697. compareDate = new Date();
  698. compareDate.setTime( compareDate.getTime() - 60 * 60 * 365 * 2 * 1000);
  699. ticket.pending_time = compareDate.toISOString();
  700. testTimeBeforeRelative('ticket.pending_time', 1, 'year', true, ticket);
  701. // -------------------------
  702. // AFTER TIME
  703. // -------------------------
  704. // hour
  705. ticket.pending_time = new Date().toISOString();
  706. testTimeAfterRelative('ticket.pending_time', 1, 'hour', false, ticket);
  707. compareDate = new Date();
  708. compareDate.setTime( compareDate.getTime() + 60 * 60 * 2 * 1000);
  709. ticket.pending_time = compareDate.toISOString();
  710. testTimeAfterRelative('ticket.pending_time', 1, 'hour', true, ticket);
  711. // day
  712. ticket.pending_time = new Date().toISOString();
  713. testTimeAfterRelative('ticket.pending_time', 1, 'day', false, ticket);
  714. compareDate = new Date();
  715. compareDate.setTime( compareDate.getTime() + 60 * 60 * 48 * 1000);
  716. ticket.pending_time = compareDate.toISOString();
  717. testTimeAfterRelative('ticket.pending_time', 1, 'day', true, ticket);
  718. // year
  719. ticket.pending_time = new Date().toISOString();
  720. testTimeAfterRelative('ticket.pending_time', 1, 'year', false, ticket);
  721. compareDate = new Date();
  722. compareDate.setTime( compareDate.getTime() + 60 * 60 * 365 * 2 * 1000);
  723. ticket.pending_time = compareDate.toISOString();
  724. testTimeAfterRelative('ticket.pending_time', 1, 'year', true, ticket);
  725. // -------------------------
  726. // WITHIN LAST TIME
  727. // -------------------------
  728. // hour
  729. compareDate = new Date();
  730. compareDate.setTime( compareDate.getTime() - 60 * 60 * 0.5 * 1000);
  731. ticket.pending_time = compareDate.toISOString();
  732. testTimeWithinLastRelative('ticket.pending_time', 1, 'hour', true, ticket);
  733. compareDate = new Date();
  734. compareDate.setTime( compareDate.getTime() - 60 * 60 * 2 * 1000);
  735. ticket.pending_time = compareDate.toISOString();
  736. testTimeWithinLastRelative('ticket.pending_time', 1, 'hour', false, ticket);
  737. // -------------------------
  738. // WITHIN NEXT TIME
  739. // -------------------------
  740. // hour
  741. compareDate = new Date();
  742. compareDate.setTime( compareDate.getTime() + 60 * 60 * 0.5 * 1000);
  743. ticket.pending_time = compareDate.toISOString();
  744. testTimeWithinNextRelative('ticket.pending_time', 1, 'hour', true, ticket);
  745. compareDate = new Date();
  746. compareDate.setTime( compareDate.getTime() + 60 * 60 * 2 * 1000);
  747. ticket.pending_time = compareDate.toISOString();
  748. testTimeWithinNextRelative('ticket.pending_time', 1, 'hour', false, ticket);
  749. });
  750. test("ticket priority_id", function() {
  751. ticket = new App.Ticket();
  752. ticket.load(ticketData);
  753. testIs('ticket.priority_id', ['2'], ticket, sessionData);
  754. });
  755. test("ticket escalation_at", function() {
  756. ticket = new App.Ticket();
  757. ticket.load(ticketData);
  758. testTime('ticket.escalation_at', ticket.escalation_at, ticket);
  759. });
  760. test("ticket last_contact_agent_at", function() {
  761. ticket = new App.Ticket();
  762. ticket.load(ticketData);
  763. testTime('ticket.last_contact_agent_at', ticket.last_contact_agent_at, ticket);
  764. });
  765. test("ticket last_contact_at", function() {
  766. ticket = new App.Ticket();
  767. ticket.load(ticketData);
  768. testTime('ticket.last_contact_at', ticket.last_contact_at, ticket);
  769. });
  770. test("ticket last_contact_customer_at", function() {
  771. ticket = new App.Ticket();
  772. ticket.load(ticketData);
  773. testTime('ticket.last_contact_customer_at', ticket.last_contact_customer_at, ticket);
  774. });
  775. test("ticket first_response_at", function() {
  776. ticket = new App.Ticket();
  777. ticket.load(ticketData);
  778. testTime('ticket.first_response_at', ticket.first_response_at, ticket);
  779. });
  780. test("ticket close_at", function() {
  781. ticket = new App.Ticket();
  782. ticket.load(ticketData);
  783. testTime('ticket.close_at', ticket.close_at, ticket);
  784. });
  785. test("ticket created_by_id", function() {
  786. ticket = new App.Ticket();
  787. ticket.load(ticketData);
  788. App.Session.set(6);
  789. testPreConditionUser('ticket.created_by_id', '6', ticket, sessionData);
  790. });
  791. test("ticket created_at", function() {
  792. ticket = new App.Ticket();
  793. ticket.load(ticketData);
  794. testTime('ticket.created_at', ticket.created_at, ticket);
  795. });
  796. test("ticket updated_at", function() {
  797. ticket = new App.Ticket();
  798. ticket.load(ticketData);
  799. testTime('ticket.updated_at', ticket.updated_at, ticket);
  800. });
  801. test("ticket updated_by_id", function() {
  802. ticket = new App.Ticket();
  803. ticket.load(ticketData);
  804. App.Session.set(6);
  805. testPreConditionUser('ticket.updated_by_id', '6', ticket, sessionData);
  806. });
  807. test("ticket tags", function() {
  808. ticket = new App.Ticket();
  809. ticket.load(ticketData);
  810. testPreConditionTags('ticket.tags', ticket);
  811. });
  812. test("article from", function() {
  813. ticket = new App.Ticket();
  814. ticket.load(ticketData);
  815. testContains('article.from', 'Master', ticket);
  816. });
  817. test("article to", function() {
  818. ticket = new App.Ticket();
  819. ticket.load(ticketData);
  820. testContains('article.to', 'agent1', ticket);
  821. });
  822. test("article cc", function() {
  823. ticket = new App.Ticket();
  824. ticket.load(ticketData);
  825. testContains('article.cc', 'agent1+cc', ticket);
  826. });
  827. test("article subject", function() {
  828. ticket = new App.Ticket();
  829. ticket.load(ticketData);
  830. testContains('article.subject', 'asdf', ticket);
  831. });
  832. test("article type_id", function() {
  833. ticket = new App.Ticket();
  834. ticket.load(ticketData);
  835. testIs('article.type_id', ['1'], ticket);
  836. });
  837. test("article sender_id", function() {
  838. ticket = new App.Ticket();
  839. ticket.load(ticketData);
  840. testIs('article.sender_id', ['1'], ticket);
  841. });
  842. test("article internal", function() {
  843. ticket = new App.Ticket();
  844. ticket.load(ticketData);
  845. testIs('article.internal', ['false'], ticket);
  846. });
  847. test("article created_by_id", function() {
  848. ticket = new App.Ticket();
  849. ticket.load(ticketData);
  850. testPreConditionUser('article.created_by_id', '6', ticket, sessionData);
  851. });
  852. test("customer login", function() {
  853. ticket = new App.Ticket();
  854. ticket.load(ticketData);
  855. testContains('customer.login', 'hc', ticket);
  856. });
  857. test("customer firstname", function() {
  858. ticket = new App.Ticket();
  859. ticket.load(ticketData);
  860. testContains('customer.firstname', 'Harald', ticket);
  861. });
  862. test("customer lastname", function() {
  863. ticket = new App.Ticket();
  864. ticket.load(ticketData);
  865. testContains('customer.lastname', 'Customer', ticket);
  866. });
  867. test("customer email", function() {
  868. ticket = new App.Ticket();
  869. ticket.load(ticketData);
  870. testContains('customer.email', 'hc', ticket);
  871. });
  872. test("customer organization_id", function() {
  873. ticket = new App.Ticket();
  874. ticket.load(ticketData);
  875. testPreConditionOrganization('customer.organization_id', '6', ticket, sessionData);
  876. });
  877. test("customer created_by_id", function() {
  878. ticket = new App.Ticket();
  879. ticket.load(ticketData);
  880. testPreConditionUser('customer.created_by_id', '6', ticket, sessionData);
  881. });
  882. test("customer created_at", function() {
  883. ticket = new App.Ticket();
  884. ticket.load(ticketData);
  885. testTime('customer.created_at', ticket.customer.created_at, ticket);
  886. });
  887. test("customer updated_by_id", function() {
  888. ticket = new App.Ticket();
  889. ticket.load(ticketData);
  890. testPreConditionUser('customer.updated_by_id', '6', ticket, sessionData);
  891. });
  892. test("customer missing_field", function() {
  893. ticket = new App.Ticket();
  894. ticket.load(ticketData);
  895. testContains('customer.missing_field', '', ticket);
  896. });
  897. test("customer web", function() {
  898. ticket = new App.Ticket();
  899. ticket.load(ticketData);
  900. testContains('customer.web', 'cool', ticket);
  901. });
  902. test("organization name", function() {
  903. ticket = new App.Ticket();
  904. ticket.load(ticketData);
  905. testContains('organization.name', 'gmbh', ticket);
  906. });
  907. test("organization shared", function() {
  908. ticket = new App.Ticket();
  909. ticket.load(ticketData);
  910. testIs('organization.shared', true, ticket);
  911. });
  912. test("organization created_by_id", function() {
  913. ticket = new App.Ticket();
  914. ticket.load(ticketData);
  915. testPreConditionUser('organization.created_by_id', 6, ticket);
  916. });
  917. test("organization updated_by_id", function() {
  918. ticket = new App.Ticket();
  919. ticket.load(ticketData);
  920. testPreConditionUser('organization.updated_by_id', 6, ticket);
  921. });
  922. test("organization created_at", function() {
  923. ticket = new App.Ticket();
  924. ticket.load(ticketData);
  925. testTime('organization.created_at', ticket.organization.created_at, ticket);
  926. });
  927. test("organization updated_at", function() {
  928. ticket = new App.Ticket();
  929. ticket.load(ticketData);
  930. testTime('organization.updated_at', ticket.organization.updated_at, ticket);
  931. });
  932. test("organization domain_assignment", function() {
  933. ticket = new App.Ticket();
  934. ticket.load(ticketData);
  935. testIs('organization.domain_assignment', false, ticket);
  936. });
  937. test("organization domain", function() {
  938. ticket = new App.Ticket();
  939. ticket.load(ticketData);
  940. testContains('organization.domain', 'cool', ticket);
  941. });
  942. }