ticket_overview_test.rb 37 KB

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