ticket_overview_test.rb 32 KB

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