ticket_selector_test.rb 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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
  137. condition = {
  138. 'ticket.group_id' => {
  139. operator: 'is',
  140. value: group.id,
  141. },
  142. 'ticket.state_id' => {
  143. operator: 'is',
  144. value: [Ticket::State.lookup(name: 'new').id],
  145. },
  146. }
  147. ticket_count, tickets = Ticket.selectors(condition, 10)
  148. assert_equal(ticket_count, 2)
  149. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  150. assert_equal(ticket_count, 2)
  151. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  152. assert_equal(ticket_count, 0)
  153. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  154. assert_equal(ticket_count, 1)
  155. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  156. assert_equal(ticket_count, 1)
  157. condition = {
  158. 'ticket.group_id' => {
  159. operator: 'is',
  160. value: group.id,
  161. },
  162. 'ticket.state_id' => {
  163. operator: 'is not',
  164. value: [Ticket::State.lookup(name: 'open').id],
  165. },
  166. }
  167. ticket_count, tickets = Ticket.selectors(condition, 10)
  168. assert_equal(ticket_count, 2)
  169. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  170. assert_equal(ticket_count, 2)
  171. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  172. assert_equal(ticket_count, 0)
  173. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  174. assert_equal(ticket_count, 1)
  175. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  176. assert_equal(ticket_count, 1)
  177. condition = {
  178. 'ticket.escalation_time' => {
  179. operator: 'is not',
  180. value: nil,
  181. }
  182. }
  183. ticket_count, tickets = Ticket.selectors(condition, 10)
  184. assert_equal(ticket_count, 1)
  185. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  186. assert_equal(ticket_count, 1)
  187. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  188. assert_equal(ticket_count, 0)
  189. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  190. assert_equal(ticket_count, 0)
  191. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  192. assert_equal(ticket_count, 1)
  193. # search - created_at
  194. condition = {
  195. 'ticket.group_id' => {
  196. operator: 'is',
  197. value: group.id,
  198. },
  199. 'ticket.created_at' => {
  200. operator: 'after (absolute)', # before (absolute)
  201. value: '2015-02-05T16:00:00.000Z',
  202. },
  203. }
  204. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  205. assert_equal(ticket_count, 3)
  206. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  207. assert_equal(ticket_count, 0)
  208. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  209. assert_equal(ticket_count, 1)
  210. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  211. assert_equal(ticket_count, 2)
  212. condition = {
  213. 'ticket.group_id' => {
  214. operator: 'is',
  215. value: group.id,
  216. },
  217. 'ticket.created_at' => {
  218. operator: 'after (absolute)', # before (absolute)
  219. value: '2015-02-05T18:00:00.000Z',
  220. },
  221. }
  222. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  223. assert_equal(ticket_count, 0)
  224. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  225. assert_equal(ticket_count, 0)
  226. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  227. assert_equal(ticket_count, 0)
  228. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  229. assert_equal(ticket_count, 0)
  230. condition = {
  231. 'ticket.group_id' => {
  232. operator: 'is',
  233. value: group.id,
  234. },
  235. 'ticket.created_at' => {
  236. operator: 'before (absolute)',
  237. value: '2015-02-05T18:00:00.000Z',
  238. },
  239. }
  240. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  241. assert_equal(ticket_count, 3)
  242. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  243. assert_equal(ticket_count, 0)
  244. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  245. assert_equal(ticket_count, 1)
  246. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  247. assert_equal(ticket_count, 2)
  248. condition = {
  249. 'ticket.group_id' => {
  250. operator: 'is',
  251. value: group.id,
  252. },
  253. 'ticket.created_at' => {
  254. operator: 'before (absolute)',
  255. value: '2015-02-05T16:00:00.000Z',
  256. },
  257. }
  258. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  259. assert_equal(ticket_count, 0)
  260. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  261. assert_equal(ticket_count, 0)
  262. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  263. assert_equal(ticket_count, 0)
  264. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  265. assert_equal(ticket_count, 0)
  266. condition = {
  267. 'ticket.group_id' => {
  268. operator: 'is',
  269. value: group.id,
  270. },
  271. 'ticket.created_at' => {
  272. operator: 'before (relative)',
  273. range: 'day', # minute|hour|day|month|
  274. value: '10',
  275. },
  276. }
  277. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  278. assert_equal(ticket_count, 3)
  279. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  280. assert_equal(ticket_count, 0)
  281. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  282. assert_equal(ticket_count, 1)
  283. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  284. assert_equal(ticket_count, 2)
  285. condition = {
  286. 'ticket.group_id' => {
  287. operator: 'is',
  288. value: group.id,
  289. },
  290. 'ticket.created_at' => {
  291. operator: 'within next (relative)',
  292. range: 'year', # minute|hour|day|month|
  293. value: '10',
  294. },
  295. }
  296. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  297. assert_equal(ticket_count, 3)
  298. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  299. assert_equal(ticket_count, 0)
  300. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  301. assert_equal(ticket_count, 1)
  302. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  303. assert_equal(ticket_count, 2)
  304. condition = {
  305. 'ticket.group_id' => {
  306. operator: 'is',
  307. value: group.id,
  308. },
  309. 'ticket.created_at' => {
  310. operator: 'within last (relative)',
  311. range: 'year', # minute|hour|day|month|
  312. value: '10',
  313. },
  314. }
  315. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  316. assert_equal(ticket_count, 3)
  317. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  318. assert_equal(ticket_count, 0)
  319. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  320. assert_equal(ticket_count, 1)
  321. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  322. assert_equal(ticket_count, 2)
  323. # search - updated_at
  324. condition = {
  325. 'ticket.group_id' => {
  326. operator: 'is',
  327. value: group.id,
  328. },
  329. 'ticket.updated_at' => {
  330. operator: 'before (absolute)',
  331. value: (Time.zone.now + 1.day).iso8601,
  332. },
  333. }
  334. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  335. assert_equal(ticket_count, 3)
  336. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  337. assert_equal(ticket_count, 0)
  338. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  339. assert_equal(ticket_count, 1)
  340. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  341. assert_equal(ticket_count, 2)
  342. condition = {
  343. 'ticket.group_id' => {
  344. operator: 'is',
  345. value: group.id,
  346. },
  347. 'ticket.updated_at' => {
  348. operator: 'before (absolute)',
  349. value: (Time.zone.now - 1.day).iso8601,
  350. },
  351. }
  352. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  353. assert_equal(ticket_count, 0)
  354. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  355. assert_equal(ticket_count, 0)
  356. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  357. assert_equal(ticket_count, 0)
  358. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  359. assert_equal(ticket_count, 0)
  360. condition = {
  361. 'ticket.group_id' => {
  362. operator: 'is',
  363. value: group.id,
  364. },
  365. 'ticket.updated_at' => {
  366. operator: 'after (absolute)',
  367. value: (Time.zone.now + 1.day).iso8601,
  368. },
  369. }
  370. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  371. assert_equal(ticket_count, 0)
  372. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  373. assert_equal(ticket_count, 0)
  374. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  375. assert_equal(ticket_count, 0)
  376. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  377. assert_equal(ticket_count, 0)
  378. condition = {
  379. 'ticket.group_id' => {
  380. operator: 'is',
  381. value: group.id,
  382. },
  383. 'ticket.updated_at' => {
  384. operator: 'after (absolute)',
  385. value: (Time.zone.now - 1.day).iso8601,
  386. },
  387. }
  388. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  389. assert_equal(ticket_count, 3)
  390. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  391. assert_equal(ticket_count, 0)
  392. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  393. assert_equal(ticket_count, 1)
  394. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  395. assert_equal(ticket_count, 2)
  396. condition = {
  397. 'ticket.group_id' => {
  398. operator: 'is',
  399. value: group.id,
  400. },
  401. 'ticket.updated_at' => {
  402. operator: 'before (relative)',
  403. range: 'day', # minute|hour|day|month|
  404. value: '10',
  405. },
  406. }
  407. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  408. assert_equal(ticket_count, 0)
  409. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  410. assert_equal(ticket_count, 0)
  411. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  412. assert_equal(ticket_count, 0)
  413. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  414. assert_equal(ticket_count, 0)
  415. condition = {
  416. 'ticket.group_id' => {
  417. operator: 'is',
  418. value: group.id,
  419. },
  420. 'ticket.updated_at' => {
  421. operator: 'within next (relative)',
  422. range: 'year', # minute|hour|day|month|
  423. value: '10',
  424. },
  425. }
  426. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  427. assert_equal(ticket_count, 3)
  428. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  429. assert_equal(ticket_count, 0)
  430. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  431. assert_equal(ticket_count, 1)
  432. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  433. assert_equal(ticket_count, 2)
  434. condition = {
  435. 'ticket.group_id' => {
  436. operator: 'is',
  437. value: group.id,
  438. },
  439. 'ticket.updated_at' => {
  440. operator: 'within last (relative)',
  441. range: 'year', # minute|hour|day|month|
  442. value: '10',
  443. },
  444. }
  445. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  446. assert_equal(ticket_count, 3)
  447. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  448. assert_equal(ticket_count, 0)
  449. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  450. assert_equal(ticket_count, 1)
  451. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  452. assert_equal(ticket_count, 2)
  453. # invalid conditions
  454. assert_raise RuntimeError do
  455. ticket_count, tickets = Ticket.selectors(nil, 10)
  456. end
  457. # search with customers
  458. condition = {
  459. 'ticket.group_id' => {
  460. operator: 'is',
  461. value: group.id,
  462. },
  463. 'customer.email' => {
  464. operator: 'contains',
  465. value: 'ticket-selector-customer1',
  466. },
  467. }
  468. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  469. assert_equal(ticket_count, 1)
  470. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  471. assert_equal(ticket_count, 0)
  472. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  473. assert_equal(ticket_count, 1)
  474. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  475. assert_equal(ticket_count, 0)
  476. condition = {
  477. 'ticket.group_id' => {
  478. operator: 'is',
  479. value: group.id,
  480. },
  481. 'customer.email' => {
  482. operator: 'contains not',
  483. value: 'ticket-selector-customer1-not_existing',
  484. },
  485. }
  486. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  487. assert_equal(ticket_count, 3)
  488. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  489. assert_equal(ticket_count, 0)
  490. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  491. assert_equal(ticket_count, 1)
  492. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  493. assert_equal(ticket_count, 2)
  494. # search with organizations
  495. condition = {
  496. 'ticket.group_id' => {
  497. operator: 'is',
  498. value: group.id,
  499. },
  500. 'organization.name' => {
  501. operator: 'contains',
  502. value: 'selector',
  503. },
  504. }
  505. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  506. assert_equal(ticket_count, 1)
  507. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  508. assert_equal(ticket_count, 0)
  509. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  510. assert_equal(ticket_count, 1)
  511. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  512. assert_equal(ticket_count, 0)
  513. # search with organizations
  514. condition = {
  515. 'ticket.group_id' => {
  516. operator: 'is',
  517. value: group.id,
  518. },
  519. 'organization.name' => {
  520. operator: 'contains',
  521. value: 'selector',
  522. },
  523. 'customer.email' => {
  524. operator: 'contains',
  525. value: 'ticket-selector-customer1',
  526. },
  527. }
  528. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  529. assert_equal(ticket_count, 1)
  530. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  531. assert_equal(ticket_count, 0)
  532. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  533. assert_equal(ticket_count, 1)
  534. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  535. assert_equal(ticket_count, 0)
  536. condition = {
  537. 'ticket.group_id' => {
  538. operator: 'is',
  539. value: group.id,
  540. },
  541. 'organization.name' => {
  542. operator: 'contains',
  543. value: 'selector',
  544. },
  545. 'customer.email' => {
  546. operator: 'contains not',
  547. value: 'ticket-selector-customer1',
  548. },
  549. }
  550. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  551. assert_equal(ticket_count, 0)
  552. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  553. assert_equal(ticket_count, 0)
  554. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  555. assert_equal(ticket_count, 0)
  556. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  557. assert_equal(ticket_count, 0)
  558. # with owner/customer/org
  559. condition = {
  560. 'ticket.group_id' => {
  561. operator: 'is',
  562. value: group.id,
  563. },
  564. 'ticket.owner_id' => {
  565. operator: 'is',
  566. pre_condition: 'specific',
  567. value: agent1.id,
  568. },
  569. }
  570. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  571. assert_equal(ticket_count, 1)
  572. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  573. assert_equal(ticket_count, 0)
  574. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  575. assert_equal(ticket_count, 1)
  576. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  577. assert_equal(ticket_count, 0)
  578. condition = {
  579. 'ticket.group_id' => {
  580. operator: 'is',
  581. value: group.id,
  582. },
  583. 'ticket.owner_id' => {
  584. operator: 'is',
  585. pre_condition: 'set',
  586. },
  587. }
  588. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  589. assert_equal(ticket_count, 1)
  590. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  591. assert_equal(ticket_count, 0)
  592. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  593. assert_equal(ticket_count, 1)
  594. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  595. assert_equal(ticket_count, 0)
  596. condition = {
  597. 'ticket.group_id' => {
  598. operator: 'is',
  599. value: group.id,
  600. },
  601. 'ticket.owner_id' => {
  602. operator: 'is not',
  603. pre_condition: 'set',
  604. },
  605. }
  606. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  607. assert_equal(ticket_count, 2)
  608. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  609. assert_equal(ticket_count, 0)
  610. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  611. assert_equal(ticket_count, 0)
  612. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  613. assert_equal(ticket_count, 2)
  614. UserInfo.current_user_id = agent1.id
  615. condition = {
  616. 'ticket.group_id' => {
  617. operator: 'is',
  618. value: group.id,
  619. },
  620. 'ticket.owner_id' => {
  621. operator: 'is',
  622. pre_condition: 'current_user.id',
  623. },
  624. }
  625. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  626. assert_equal(ticket_count, 1)
  627. ticket_count, tickets = Ticket.selectors(condition, 10)
  628. assert_equal(ticket_count, 1)
  629. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  630. assert_equal(ticket_count, 0)
  631. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  632. assert_equal(ticket_count, 0)
  633. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  634. assert_equal(ticket_count, 0)
  635. UserInfo.current_user_id = agent2.id
  636. condition = {
  637. 'ticket.group_id' => {
  638. operator: 'is',
  639. value: group.id,
  640. },
  641. 'ticket.owner_id' => {
  642. operator: 'is',
  643. pre_condition: 'current_user.id',
  644. },
  645. }
  646. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  647. assert_equal(ticket_count, 1)
  648. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  649. assert_equal(ticket_count, 0)
  650. ticket_count, tickets = Ticket.selectors(condition, 10)
  651. assert_equal(ticket_count, 0)
  652. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  653. assert_equal(ticket_count, 0)
  654. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  655. assert_equal(ticket_count, 0)
  656. UserInfo.current_user_id = customer1.id
  657. condition = {
  658. 'ticket.group_id' => {
  659. operator: 'is',
  660. value: group.id,
  661. },
  662. 'ticket.customer_id' => {
  663. operator: 'is',
  664. pre_condition: 'current_user.id',
  665. },
  666. }
  667. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  668. assert_equal(ticket_count, 0)
  669. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  670. assert_equal(ticket_count, 0)
  671. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  672. assert_equal(ticket_count, 1)
  673. ticket_count, tickets = Ticket.selectors(condition, 10)
  674. assert_equal(ticket_count, 1)
  675. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  676. assert_equal(ticket_count, 2)
  677. UserInfo.current_user_id = customer2.id
  678. condition = {
  679. 'ticket.group_id' => {
  680. operator: 'is',
  681. value: group.id,
  682. },
  683. 'ticket.customer_id' => {
  684. operator: 'is',
  685. pre_condition: 'current_user.id',
  686. },
  687. }
  688. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  689. assert_equal(ticket_count, 0)
  690. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  691. assert_equal(ticket_count, 0)
  692. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  693. assert_equal(ticket_count, 1)
  694. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  695. assert_equal(ticket_count, 2)
  696. ticket_count, tickets = Ticket.selectors(condition, 10)
  697. assert_equal(ticket_count, 2)
  698. UserInfo.current_user_id = customer1.id
  699. condition = {
  700. 'ticket.group_id' => {
  701. operator: 'is',
  702. value: group.id,
  703. },
  704. 'ticket.organization_id' => {
  705. operator: 'is',
  706. pre_condition: 'current_user.organization_id',
  707. },
  708. }
  709. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  710. assert_equal(ticket_count, 0)
  711. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  712. assert_equal(ticket_count, 0)
  713. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  714. assert_equal(ticket_count, 1)
  715. ticket_count, tickets = Ticket.selectors(condition, 10)
  716. assert_equal(ticket_count, 1)
  717. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  718. assert_equal(ticket_count, 0)
  719. UserInfo.current_user_id = customer2.id
  720. condition = {
  721. 'ticket.group_id' => {
  722. operator: 'is',
  723. value: group.id,
  724. },
  725. 'ticket.organization_id' => {
  726. operator: 'is',
  727. pre_condition: 'current_user.organization_id',
  728. },
  729. }
  730. ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
  731. assert_equal(ticket_count, 0)
  732. ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
  733. assert_equal(ticket_count, 0)
  734. ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
  735. assert_equal(ticket_count, 1)
  736. ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
  737. assert_equal(ticket_count, 0)
  738. ticket_count, tickets = Ticket.selectors(condition, 10)
  739. assert_equal(ticket_count, 0)
  740. end
  741. end