ticket_selector_test.rb 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketSelectorTest < ActiveSupport::TestCase
  4. # create base
  5. group = Group.create_or_update(
  6. name: 'SelectorTest',
  7. updated_at: '2015-02-05 16:37:00',
  8. updated_by_id: 1,
  9. created_by_id: 1,
  10. )
  11. roles = Role.where(name: 'Agent')
  12. agent1 = User.create_or_update(
  13. login: 'ticket-selector-agent1@example.com',
  14. firstname: 'Notification',
  15. lastname: 'Agent1',
  16. email: 'ticket-selector-agent1@example.com',
  17. password: 'agentpw',
  18. active: true,
  19. roles: roles,
  20. groups: [group],
  21. updated_at: '2015-02-05 16:37:00',
  22. updated_by_id: 1,
  23. created_by_id: 1,
  24. )
  25. agent2 = User.create_or_update(
  26. login: 'ticket-selector-agent2@example.com',
  27. firstname: 'Notification',
  28. lastname: 'Agent2',
  29. email: 'ticket-selector-agent2@example.com',
  30. password: 'agentpw',
  31. active: true,
  32. roles: roles,
  33. #groups: groups,
  34. updated_at: '2015-02-05 16:38:00',
  35. updated_by_id: 1,
  36. created_by_id: 1,
  37. )
  38. roles = Role.where(name: 'Customer')
  39. organization1 = Organization.create_if_not_exists(
  40. name: 'Selector Org',
  41. updated_at: '2015-02-05 16:37:00',
  42. updated_by_id: 1,
  43. created_by_id: 1,
  44. )
  45. customer1 = User.create_or_update(
  46. login: 'ticket-selector-customer1@example.com',
  47. firstname: 'Notification',
  48. lastname: 'Customer1',
  49. email: 'ticket-selector-customer1@example.com',
  50. password: 'customerpw',
  51. active: true,
  52. organization_id: organization1.id,
  53. roles: roles,
  54. updated_at: '2015-02-05 16:37:00',
  55. updated_by_id: 1,
  56. created_by_id: 1,
  57. )
  58. customer2 = User.create_or_update(
  59. login: 'ticket-selector-customer2@example.com',
  60. firstname: 'Notification',
  61. lastname: 'Customer2',
  62. email: 'ticket-selector-customer2@example.com',
  63. password: 'customerpw',
  64. active: true,
  65. organization_id: nil,
  66. roles: roles,
  67. updated_at: '2015-02-05 16:37:00',
  68. updated_by_id: 1,
  69. created_by_id: 1,
  70. )
  71. Ticket.where(group_id: group.id).destroy_all
  72. test 'ticket create' do
  73. Ticket.destroy_all
  74. ticket1 = Ticket.create(
  75. title: 'some title1',
  76. group: group,
  77. customer_id: customer1.id,
  78. owner_id: agent1.id,
  79. state: Ticket::State.lookup(name: 'new'),
  80. priority: Ticket::Priority.lookup(name: '2 normal'),
  81. created_at: '2015-02-05 16:37:00',
  82. #updated_at: '2015-02-05 17:37:00',
  83. updated_by_id: 1,
  84. created_by_id: 1,
  85. )
  86. assert(ticket1, 'ticket created')
  87. assert_equal(ticket1.customer.id, customer1.id)
  88. assert_equal(ticket1.organization.id, organization1.id)
  89. sleep 1
  90. ticket2 = Ticket.create(
  91. title: 'some title2',
  92. group: group,
  93. customer_id: customer2.id,
  94. state: Ticket::State.lookup(name: 'new'),
  95. priority: Ticket::Priority.lookup(name: '2 normal'),
  96. created_at: '2015-02-05 16:37:00',
  97. #updated_at: '2015-02-05 17:37:00',
  98. updated_by_id: 1,
  99. created_by_id: 1,
  100. )
  101. assert(ticket2, 'ticket created')
  102. assert_equal(ticket2.customer.id, customer2.id)
  103. assert_equal(ticket2.organization_id, nil)
  104. sleep 1
  105. ticket3 = Ticket.create(
  106. title: 'some title3',
  107. group: group,
  108. customer_id: customer2.id,
  109. state: Ticket::State.lookup(name: 'open'),
  110. priority: Ticket::Priority.lookup(name: '2 normal'),
  111. escalation_time: '2015-02-06 10:00:00',
  112. created_at: '2015-02-05 16:37:00',
  113. #updated_at: '2015-02-05 17:37:00',
  114. updated_by_id: 1,
  115. created_by_id: 1,
  116. )
  117. assert(ticket3, 'ticket created')
  118. assert_equal(ticket3.customer.id, customer2.id)
  119. assert_equal(ticket3.organization_id, nil)
  120. sleep 1
  121. # search not matching
  122. condition = {
  123. 'ticket.state_id' => {
  124. operator: 'is',
  125. value: [99],
  126. },
  127. }
  128. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  129. assert_equal(ticket_count, 0)
  130. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  131. assert_equal(ticket_count, 0)
  132. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  133. assert_equal(ticket_count, 0)
  134. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  135. assert_equal(ticket_count, 0)
  136. # search matching with empty value / missing key
  137. condition = {
  138. 'ticket.group_id' => {
  139. operator: 'is',
  140. value: group.id,
  141. },
  142. 'ticket.state_id' => {
  143. operator: 'is',
  144. },
  145. }
  146. ticket_count, tickets = Ticket.selectors(condition, 10)
  147. assert_equal(ticket_count, nil)
  148. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  149. assert_equal(ticket_count, nil)
  150. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  151. assert_equal(ticket_count, nil)
  152. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  153. assert_equal(ticket_count, nil)
  154. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  155. assert_equal(ticket_count, nil)
  156. # search matching with empty value []
  157. condition = {
  158. 'ticket.group_id' => {
  159. operator: 'is',
  160. value: group.id,
  161. },
  162. 'ticket.state_id' => {
  163. operator: 'is',
  164. value: [],
  165. },
  166. }
  167. ticket_count, tickets = Ticket.selectors(condition, 10)
  168. assert_equal(ticket_count, nil)
  169. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  170. assert_equal(ticket_count, nil)
  171. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  172. assert_equal(ticket_count, nil)
  173. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  174. assert_equal(ticket_count, nil)
  175. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  176. assert_equal(ticket_count, nil)
  177. # search matching with empty value ''
  178. condition = {
  179. 'ticket.group_id' => {
  180. operator: 'is',
  181. value: group.id,
  182. },
  183. 'ticket.state_id' => {
  184. operator: 'is',
  185. value: '',
  186. },
  187. }
  188. ticket_count, tickets = Ticket.selectors(condition, 10)
  189. assert_equal(ticket_count, nil)
  190. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  191. assert_equal(ticket_count, nil)
  192. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  193. assert_equal(ticket_count, nil)
  194. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  195. assert_equal(ticket_count, nil)
  196. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  197. assert_equal(ticket_count, nil)
  198. # search matching
  199. condition = {
  200. 'ticket.group_id' => {
  201. operator: 'is',
  202. value: group.id,
  203. },
  204. 'ticket.state_id' => {
  205. operator: 'is',
  206. value: [Ticket::State.lookup(name: 'new').id],
  207. },
  208. }
  209. ticket_count, tickets = Ticket.selectors(condition, 10)
  210. assert_equal(ticket_count, 2)
  211. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  212. assert_equal(ticket_count, 2)
  213. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  214. assert_equal(ticket_count, 0)
  215. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  216. assert_equal(ticket_count, 1)
  217. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  218. assert_equal(ticket_count, 1)
  219. condition = {
  220. 'ticket.group_id' => {
  221. operator: 'is',
  222. value: group.id,
  223. },
  224. 'ticket.state_id' => {
  225. operator: 'is not',
  226. value: [Ticket::State.lookup(name: 'open').id],
  227. },
  228. }
  229. ticket_count, tickets = Ticket.selectors(condition, 10)
  230. assert_equal(ticket_count, 2)
  231. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  232. assert_equal(ticket_count, 2)
  233. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  234. assert_equal(ticket_count, 0)
  235. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  236. assert_equal(ticket_count, 1)
  237. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  238. assert_equal(ticket_count, 1)
  239. condition = {
  240. 'ticket.escalation_time' => {
  241. operator: 'is not',
  242. value: nil,
  243. }
  244. }
  245. ticket_count, tickets = Ticket.selectors(condition, 10)
  246. assert_equal(ticket_count, 1)
  247. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  248. assert_equal(ticket_count, 1)
  249. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  250. assert_equal(ticket_count, 0)
  251. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  252. assert_equal(ticket_count, 0)
  253. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  254. assert_equal(ticket_count, 1)
  255. # search - created_at
  256. condition = {
  257. 'ticket.group_id' => {
  258. operator: 'is',
  259. value: group.id,
  260. },
  261. 'ticket.created_at' => {
  262. operator: 'after (absolute)', # before (absolute)
  263. value: '2015-02-05T16:00:00.000Z',
  264. },
  265. }
  266. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  267. assert_equal(ticket_count, 3)
  268. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  269. assert_equal(ticket_count, 0)
  270. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  271. assert_equal(ticket_count, 1)
  272. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  273. assert_equal(ticket_count, 2)
  274. condition = {
  275. 'ticket.group_id' => {
  276. operator: 'is',
  277. value: group.id,
  278. },
  279. 'ticket.created_at' => {
  280. operator: 'after (absolute)', # before (absolute)
  281. value: '2015-02-05T18:00:00.000Z',
  282. },
  283. }
  284. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  285. assert_equal(ticket_count, 0)
  286. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  287. assert_equal(ticket_count, 0)
  288. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  289. assert_equal(ticket_count, 0)
  290. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  291. assert_equal(ticket_count, 0)
  292. condition = {
  293. 'ticket.group_id' => {
  294. operator: 'is',
  295. value: group.id,
  296. },
  297. 'ticket.created_at' => {
  298. operator: 'before (absolute)',
  299. value: '2015-02-05T18:00:00.000Z',
  300. },
  301. }
  302. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  303. assert_equal(ticket_count, 3)
  304. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  305. assert_equal(ticket_count, 0)
  306. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  307. assert_equal(ticket_count, 1)
  308. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  309. assert_equal(ticket_count, 2)
  310. condition = {
  311. 'ticket.group_id' => {
  312. operator: 'is',
  313. value: group.id,
  314. },
  315. 'ticket.created_at' => {
  316. operator: 'before (absolute)',
  317. value: '2015-02-05T16:00:00.000Z',
  318. },
  319. }
  320. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  321. assert_equal(ticket_count, 0)
  322. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  323. assert_equal(ticket_count, 0)
  324. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  325. assert_equal(ticket_count, 0)
  326. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  327. assert_equal(ticket_count, 0)
  328. condition = {
  329. 'ticket.group_id' => {
  330. operator: 'is',
  331. value: group.id,
  332. },
  333. 'ticket.created_at' => {
  334. operator: 'before (relative)',
  335. range: 'day', # minute|hour|day|month|
  336. value: '10',
  337. },
  338. }
  339. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  340. assert_equal(ticket_count, 3)
  341. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  342. assert_equal(ticket_count, 0)
  343. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  344. assert_equal(ticket_count, 1)
  345. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  346. assert_equal(ticket_count, 2)
  347. condition = {
  348. 'ticket.group_id' => {
  349. operator: 'is',
  350. value: group.id,
  351. },
  352. 'ticket.created_at' => {
  353. operator: 'within next (relative)',
  354. range: 'year', # minute|hour|day|month|
  355. value: '10',
  356. },
  357. }
  358. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  359. assert_equal(ticket_count, 3)
  360. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  361. assert_equal(ticket_count, 0)
  362. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  363. assert_equal(ticket_count, 1)
  364. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  365. assert_equal(ticket_count, 2)
  366. condition = {
  367. 'ticket.group_id' => {
  368. operator: 'is',
  369. value: group.id,
  370. },
  371. 'ticket.created_at' => {
  372. operator: 'within last (relative)',
  373. range: 'year', # minute|hour|day|month|
  374. value: '10',
  375. },
  376. }
  377. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  378. assert_equal(ticket_count, 3)
  379. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  380. assert_equal(ticket_count, 0)
  381. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  382. assert_equal(ticket_count, 1)
  383. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  384. assert_equal(ticket_count, 2)
  385. # search - updated_at
  386. condition = {
  387. 'ticket.group_id' => {
  388. operator: 'is',
  389. value: group.id,
  390. },
  391. 'ticket.updated_at' => {
  392. operator: 'before (absolute)',
  393. value: (Time.zone.now + 1.day).iso8601,
  394. },
  395. }
  396. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  397. assert_equal(ticket_count, 3)
  398. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  399. assert_equal(ticket_count, 0)
  400. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  401. assert_equal(ticket_count, 1)
  402. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  403. assert_equal(ticket_count, 2)
  404. condition = {
  405. 'ticket.group_id' => {
  406. operator: 'is',
  407. value: group.id,
  408. },
  409. 'ticket.updated_at' => {
  410. operator: 'before (absolute)',
  411. value: (Time.zone.now - 1.day).iso8601,
  412. },
  413. }
  414. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  415. assert_equal(ticket_count, 0)
  416. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  417. assert_equal(ticket_count, 0)
  418. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  419. assert_equal(ticket_count, 0)
  420. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  421. assert_equal(ticket_count, 0)
  422. condition = {
  423. 'ticket.group_id' => {
  424. operator: 'is',
  425. value: group.id,
  426. },
  427. 'ticket.updated_at' => {
  428. operator: 'after (absolute)',
  429. value: (Time.zone.now + 1.day).iso8601,
  430. },
  431. }
  432. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  433. assert_equal(ticket_count, 0)
  434. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  435. assert_equal(ticket_count, 0)
  436. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  437. assert_equal(ticket_count, 0)
  438. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  439. assert_equal(ticket_count, 0)
  440. condition = {
  441. 'ticket.group_id' => {
  442. operator: 'is',
  443. value: group.id,
  444. },
  445. 'ticket.updated_at' => {
  446. operator: 'after (absolute)',
  447. value: (Time.zone.now - 1.day).iso8601,
  448. },
  449. }
  450. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  451. assert_equal(ticket_count, 3)
  452. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  453. assert_equal(ticket_count, 0)
  454. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  455. assert_equal(ticket_count, 1)
  456. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  457. assert_equal(ticket_count, 2)
  458. condition = {
  459. 'ticket.group_id' => {
  460. operator: 'is',
  461. value: group.id,
  462. },
  463. 'ticket.updated_at' => {
  464. operator: 'before (relative)',
  465. range: 'day', # minute|hour|day|month|
  466. value: '10',
  467. },
  468. }
  469. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  470. assert_equal(ticket_count, 0)
  471. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  472. assert_equal(ticket_count, 0)
  473. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  474. assert_equal(ticket_count, 0)
  475. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  476. assert_equal(ticket_count, 0)
  477. condition = {
  478. 'ticket.group_id' => {
  479. operator: 'is',
  480. value: group.id,
  481. },
  482. 'ticket.updated_at' => {
  483. operator: 'within next (relative)',
  484. range: 'year', # minute|hour|day|month|
  485. value: '10',
  486. },
  487. }
  488. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  489. assert_equal(ticket_count, 3)
  490. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  491. assert_equal(ticket_count, 0)
  492. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  493. assert_equal(ticket_count, 1)
  494. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  495. assert_equal(ticket_count, 2)
  496. condition = {
  497. 'ticket.group_id' => {
  498. operator: 'is',
  499. value: group.id,
  500. },
  501. 'ticket.updated_at' => {
  502. operator: 'within last (relative)',
  503. range: 'year', # minute|hour|day|month|
  504. value: '10',
  505. },
  506. }
  507. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  508. assert_equal(ticket_count, 3)
  509. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  510. assert_equal(ticket_count, 0)
  511. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  512. assert_equal(ticket_count, 1)
  513. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  514. assert_equal(ticket_count, 2)
  515. # invalid conditions
  516. assert_raise RuntimeError do
  517. ticket_count, tickets = Ticket.selectors(nil, 10)
  518. end
  519. # search with customers
  520. condition = {
  521. 'ticket.group_id' => {
  522. operator: 'is',
  523. value: group.id,
  524. },
  525. 'customer.email' => {
  526. operator: 'contains',
  527. value: 'ticket-selector-customer1',
  528. },
  529. }
  530. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  531. assert_equal(ticket_count, 1)
  532. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  533. assert_equal(ticket_count, 0)
  534. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  535. assert_equal(ticket_count, 1)
  536. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  537. assert_equal(ticket_count, 0)
  538. condition = {
  539. 'ticket.group_id' => {
  540. operator: 'is',
  541. value: group.id,
  542. },
  543. 'customer.email' => {
  544. operator: 'contains not',
  545. value: 'ticket-selector-customer1-not_existing',
  546. },
  547. }
  548. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  549. assert_equal(ticket_count, 3)
  550. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  551. assert_equal(ticket_count, 0)
  552. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  553. assert_equal(ticket_count, 1)
  554. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  555. assert_equal(ticket_count, 2)
  556. # search with organizations
  557. condition = {
  558. 'ticket.group_id' => {
  559. operator: 'is',
  560. value: group.id,
  561. },
  562. 'organization.name' => {
  563. operator: 'contains',
  564. value: 'selector',
  565. },
  566. }
  567. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  568. assert_equal(ticket_count, 1)
  569. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  570. assert_equal(ticket_count, 0)
  571. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  572. assert_equal(ticket_count, 1)
  573. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  574. assert_equal(ticket_count, 0)
  575. # search with organizations
  576. condition = {
  577. 'ticket.group_id' => {
  578. operator: 'is',
  579. value: group.id,
  580. },
  581. 'organization.name' => {
  582. operator: 'contains',
  583. value: 'selector',
  584. },
  585. 'customer.email' => {
  586. operator: 'contains',
  587. value: 'ticket-selector-customer1',
  588. },
  589. }
  590. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  591. assert_equal(ticket_count, 1)
  592. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  593. assert_equal(ticket_count, 0)
  594. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  595. assert_equal(ticket_count, 1)
  596. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  597. assert_equal(ticket_count, 0)
  598. condition = {
  599. 'ticket.group_id' => {
  600. operator: 'is',
  601. value: group.id,
  602. },
  603. 'organization.name' => {
  604. operator: 'contains',
  605. value: 'selector',
  606. },
  607. 'customer.email' => {
  608. operator: 'contains not',
  609. value: 'ticket-selector-customer1',
  610. },
  611. }
  612. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  613. assert_equal(ticket_count, 0)
  614. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  615. assert_equal(ticket_count, 0)
  616. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  617. assert_equal(ticket_count, 0)
  618. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  619. assert_equal(ticket_count, 0)
  620. # with owner/customer/org
  621. condition = {
  622. 'ticket.group_id' => {
  623. operator: 'is',
  624. value: group.id,
  625. },
  626. 'ticket.owner_id' => {
  627. operator: 'is',
  628. pre_condition: 'specific',
  629. value: agent1.id,
  630. },
  631. }
  632. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  633. assert_equal(ticket_count, 1)
  634. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  635. assert_equal(ticket_count, 0)
  636. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  637. assert_equal(ticket_count, 1)
  638. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  639. assert_equal(ticket_count, 0)
  640. condition = {
  641. 'ticket.group_id' => {
  642. operator: 'is',
  643. value: group.id,
  644. },
  645. 'ticket.owner_id' => {
  646. operator: 'is',
  647. pre_condition: 'not_set',
  648. },
  649. }
  650. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  651. assert_equal(ticket_count, 2)
  652. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  653. assert_equal(ticket_count, 0)
  654. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  655. assert_equal(ticket_count, 0)
  656. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  657. assert_equal(ticket_count, 2)
  658. condition = {
  659. 'ticket.group_id' => {
  660. operator: 'is',
  661. value: group.id,
  662. },
  663. 'ticket.owner_id' => {
  664. operator: 'is not',
  665. pre_condition: 'not_set',
  666. },
  667. }
  668. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  669. assert_equal(ticket_count, 1)
  670. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  671. assert_equal(ticket_count, 0)
  672. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  673. assert_equal(ticket_count, 1)
  674. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  675. assert_equal(ticket_count, 0)
  676. UserInfo.current_user_id = agent1.id
  677. condition = {
  678. 'ticket.group_id' => {
  679. operator: 'is',
  680. value: group.id,
  681. },
  682. 'ticket.owner_id' => {
  683. operator: 'is',
  684. pre_condition: 'current_user.id',
  685. },
  686. }
  687. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  688. assert_equal(ticket_count, 1)
  689. ticket_count, tickets = Ticket.selectors(condition, 10)
  690. assert_equal(ticket_count, 1)
  691. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  692. assert_equal(ticket_count, 0)
  693. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  694. assert_equal(ticket_count, 0)
  695. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  696. assert_equal(ticket_count, 0)
  697. UserInfo.current_user_id = agent2.id
  698. condition = {
  699. 'ticket.group_id' => {
  700. operator: 'is',
  701. value: group.id,
  702. },
  703. 'ticket.owner_id' => {
  704. operator: 'is',
  705. pre_condition: 'current_user.id',
  706. },
  707. }
  708. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  709. assert_equal(ticket_count, 1)
  710. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  711. assert_equal(ticket_count, 0)
  712. ticket_count, tickets = Ticket.selectors(condition, 10)
  713. assert_equal(ticket_count, 0)
  714. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  715. assert_equal(ticket_count, 0)
  716. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  717. assert_equal(ticket_count, 0)
  718. UserInfo.current_user_id = customer1.id
  719. condition = {
  720. 'ticket.group_id' => {
  721. operator: 'is',
  722. value: group.id,
  723. },
  724. 'ticket.customer_id' => {
  725. operator: 'is',
  726. pre_condition: 'current_user.id',
  727. },
  728. }
  729. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  730. assert_equal(ticket_count, 0)
  731. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  732. assert_equal(ticket_count, 0)
  733. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  734. assert_equal(ticket_count, 1)
  735. ticket_count, tickets = Ticket.selectors(condition, 10)
  736. assert_equal(ticket_count, 1)
  737. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  738. assert_equal(ticket_count, 2)
  739. UserInfo.current_user_id = customer2.id
  740. condition = {
  741. 'ticket.group_id' => {
  742. operator: 'is',
  743. value: group.id,
  744. },
  745. 'ticket.customer_id' => {
  746. operator: 'is',
  747. pre_condition: 'current_user.id',
  748. },
  749. }
  750. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  751. assert_equal(ticket_count, 0)
  752. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  753. assert_equal(ticket_count, 0)
  754. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  755. assert_equal(ticket_count, 1)
  756. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  757. assert_equal(ticket_count, 2)
  758. ticket_count, tickets = Ticket.selectors(condition, 10)
  759. assert_equal(ticket_count, 2)
  760. UserInfo.current_user_id = customer1.id
  761. condition = {
  762. 'ticket.group_id' => {
  763. operator: 'is',
  764. value: group.id,
  765. },
  766. 'ticket.organization_id' => {
  767. operator: 'is',
  768. pre_condition: 'current_user.organization_id',
  769. },
  770. }
  771. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  772. assert_equal(ticket_count, 0)
  773. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  774. assert_equal(ticket_count, 0)
  775. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  776. assert_equal(ticket_count, 1)
  777. ticket_count, tickets = Ticket.selectors(condition, 10)
  778. assert_equal(ticket_count, 1)
  779. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  780. assert_equal(ticket_count, 0)
  781. UserInfo.current_user_id = customer2.id
  782. condition = {
  783. 'ticket.group_id' => {
  784. operator: 'is',
  785. value: group.id,
  786. },
  787. 'ticket.organization_id' => {
  788. operator: 'is',
  789. pre_condition: 'current_user.organization_id',
  790. },
  791. }
  792. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  793. assert_equal(ticket_count, 0)
  794. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  795. assert_equal(ticket_count, 0)
  796. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  797. assert_equal(ticket_count, 1)
  798. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  799. assert_equal(ticket_count, 0)
  800. ticket_count, tickets = Ticket.selectors(condition, 10)
  801. assert_equal(ticket_count, 0)
  802. end
  803. end