ticket_screen_options_test.rb 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. require 'test_helper'
  2. class TicketScreenOptionsTest < ActiveSupport::TestCase
  3. test 'base' do
  4. group1 = Group.create!(
  5. name: 'Group 1',
  6. active: true,
  7. email_address: EmailAddress.first,
  8. created_by_id: 1,
  9. updated_by_id: 1,
  10. )
  11. group2 = Group.create!(
  12. name: 'Group 2',
  13. active: true,
  14. created_by_id: 1,
  15. updated_by_id: 1,
  16. )
  17. group3 = Group.create!(
  18. name: 'Group 3',
  19. active: true,
  20. created_by_id: 1,
  21. updated_by_id: 1,
  22. )
  23. agent1 = User.create!(
  24. login: 'agent1@example.com',
  25. firstname: 'Role',
  26. lastname: 'Agent1',
  27. email: 'agent1@example.com',
  28. password: 'agentpw',
  29. active: true,
  30. roles: Role.where(name: %w[Admin Agent]),
  31. updated_by_id: 1,
  32. created_by_id: 1,
  33. )
  34. agent1.group_names_access_map = {
  35. group1.name => 'full',
  36. group2.name => %w[read change],
  37. group3.name => 'full',
  38. }
  39. agent2 = User.create!(
  40. login: 'agent2@example.com',
  41. firstname: 'Role',
  42. lastname: 'Agent2',
  43. email: 'agent2@example.com',
  44. password: 'agentpw',
  45. active: true,
  46. roles: Role.where(name: %w[Admin Agent]),
  47. updated_by_id: 1,
  48. created_by_id: 1,
  49. )
  50. agent2.group_names_access_map = {
  51. group1.name => 'full',
  52. group2.name => %w[read change],
  53. group3.name => ['create'],
  54. }
  55. agent3 = User.create!(
  56. login: 'agent3@example.com',
  57. firstname: 'Role',
  58. lastname: 'Agent3',
  59. email: 'agent3@example.com',
  60. password: 'agentpw',
  61. active: true,
  62. roles: Role.where(name: %w[Admin Agent]),
  63. updated_by_id: 1,
  64. created_by_id: 1,
  65. )
  66. agent3.group_names_access_map = {
  67. group1.name => 'full',
  68. group2.name => ['full'],
  69. }
  70. agent4 = User.create!(
  71. login: 'agent4@example.com',
  72. firstname: 'Role',
  73. lastname: 'Agent4',
  74. email: 'agent4@example.com',
  75. password: 'agentpw',
  76. active: true,
  77. roles: Role.where(name: %w[Admin Agent]),
  78. updated_by_id: 1,
  79. created_by_id: 1,
  80. )
  81. agent4.group_names_access_map = {
  82. group1.name => 'full',
  83. group2.name => %w[read overview change],
  84. }
  85. agent5 = User.create!(
  86. login: 'agent5@example.com',
  87. firstname: 'Role',
  88. lastname: 'Agent5',
  89. email: 'agent5@example.com',
  90. password: 'agentpw',
  91. active: true,
  92. roles: Role.where(name: %w[Admin Agent]),
  93. updated_by_id: 1,
  94. created_by_id: 1,
  95. )
  96. agent5.group_names_access_map = {
  97. group3.name => 'full',
  98. }
  99. agent6 = User.create!(
  100. login: 'agent6@example.com',
  101. firstname: 'Role',
  102. lastname: 'Agent6',
  103. email: 'agent6@example.com',
  104. password: 'agentpw',
  105. active: true,
  106. roles: Role.where(name: %w[Admin Agent]),
  107. updated_by_id: 1,
  108. created_by_id: 1,
  109. )
  110. result = Ticket::ScreenOptions.attributes_to_change(
  111. current_user: agent1,
  112. )
  113. assert(result[:form_meta])
  114. assert(result[:form_meta][:filter])
  115. assert(result[:form_meta][:filter][:state_id])
  116. assert_equal([
  117. Ticket::State.lookup(name: 'open').id,
  118. Ticket::State.lookup(name: 'pending reminder').id,
  119. Ticket::State.lookup(name: 'closed').id,
  120. Ticket::State.lookup(name: 'pending close').id,
  121. ], result[:form_meta][:filter][:state_id].sort)
  122. assert(result[:form_meta][:filter][:priority_id])
  123. assert_equal([
  124. Ticket::Priority.lookup(name: '1 low').id,
  125. Ticket::Priority.lookup(name: '2 normal').id,
  126. Ticket::Priority.lookup(name: '3 high').id,
  127. ], result[:form_meta][:filter][:priority_id].sort)
  128. assert(result[:form_meta][:filter][:type_id])
  129. assert_equal([], result[:form_meta][:filter][:type_id].sort)
  130. assert(result[:form_meta][:filter][:group_id])
  131. assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
  132. assert(result[:form_meta][:dependencies])
  133. assert(result[:form_meta][:dependencies][:group_id])
  134. assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
  135. assert(result[:form_meta][:dependencies][:group_id][''])
  136. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  137. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  138. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  139. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  140. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  141. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  142. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  143. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  144. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  145. assert(result[:form_meta][:dependencies][:group_id][group3.id])
  146. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
  147. assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
  148. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
  149. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
  150. result = Ticket::ScreenOptions.attributes_to_change(
  151. current_user: agent2,
  152. )
  153. assert(result[:form_meta])
  154. assert(result[:form_meta][:filter])
  155. assert(result[:form_meta][:filter][:state_id])
  156. assert_equal([
  157. Ticket::State.lookup(name: 'open').id,
  158. Ticket::State.lookup(name: 'pending reminder').id,
  159. Ticket::State.lookup(name: 'closed').id,
  160. Ticket::State.lookup(name: 'pending close').id,
  161. ], result[:form_meta][:filter][:state_id].sort)
  162. assert(result[:form_meta][:filter][:priority_id])
  163. assert_equal([
  164. Ticket::Priority.lookup(name: '1 low').id,
  165. Ticket::Priority.lookup(name: '2 normal').id,
  166. Ticket::Priority.lookup(name: '3 high').id,
  167. ], result[:form_meta][:filter][:priority_id].sort)
  168. assert(result[:form_meta][:filter][:type_id])
  169. assert_equal([], result[:form_meta][:filter][:type_id].sort)
  170. assert(result[:form_meta][:filter][:group_id])
  171. assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
  172. assert(result[:form_meta][:dependencies])
  173. assert(result[:form_meta][:dependencies][:group_id])
  174. assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
  175. assert(result[:form_meta][:dependencies][:group_id][''])
  176. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  177. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  178. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  179. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  180. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  181. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  182. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  183. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  184. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  185. assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
  186. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
  187. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
  188. result = Ticket::ScreenOptions.attributes_to_change(
  189. current_user: agent3,
  190. )
  191. assert(result[:form_meta])
  192. assert(result[:form_meta][:filter])
  193. assert(result[:form_meta][:filter][:state_id])
  194. assert_equal([
  195. Ticket::State.lookup(name: 'open').id,
  196. Ticket::State.lookup(name: 'pending reminder').id,
  197. Ticket::State.lookup(name: 'closed').id,
  198. Ticket::State.lookup(name: 'pending close').id,
  199. ], result[:form_meta][:filter][:state_id].sort)
  200. assert(result[:form_meta][:filter][:priority_id])
  201. assert_equal([
  202. Ticket::Priority.lookup(name: '1 low').id,
  203. Ticket::Priority.lookup(name: '2 normal').id,
  204. Ticket::Priority.lookup(name: '3 high').id,
  205. ], result[:form_meta][:filter][:priority_id].sort)
  206. assert(result[:form_meta][:filter][:type_id])
  207. assert_equal([], result[:form_meta][:filter][:type_id].sort)
  208. assert(result[:form_meta][:filter][:group_id])
  209. assert_equal([group1.id, group2.id], result[:form_meta][:filter][:group_id].sort)
  210. assert(result[:form_meta][:dependencies])
  211. assert(result[:form_meta][:dependencies][:group_id])
  212. assert_equal(3, result[:form_meta][:dependencies][:group_id].count)
  213. assert(result[:form_meta][:dependencies][:group_id][''])
  214. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  215. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  216. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  217. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  218. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  219. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  220. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  221. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  222. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  223. assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
  224. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
  225. ticket1 = Ticket.create!(
  226. title: 'some title 1',
  227. group: group1,
  228. customer_id: 2,
  229. state: Ticket::State.lookup(name: 'new'),
  230. priority: Ticket::Priority.lookup(name: '2 normal'),
  231. updated_by_id: 1,
  232. created_by_id: 1,
  233. )
  234. article1 = Ticket::Article.create!(
  235. ticket_id: ticket1.id,
  236. from: 'some_sender@example.com',
  237. to: 'some_recipient@example.com',
  238. subject: 'some subject',
  239. message_id: 'some@id',
  240. body: 'some message',
  241. internal: false,
  242. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  243. type: Ticket::Article::Type.find_by(name: 'email'),
  244. updated_by_id: 1,
  245. created_by_id: 1,
  246. )
  247. ticket2 = Ticket.create!(
  248. title: 'some title 2',
  249. group: group2,
  250. customer_id: 2,
  251. state: Ticket::State.lookup(name: 'new'),
  252. priority: Ticket::Priority.lookup(name: '2 normal'),
  253. updated_by_id: 1,
  254. created_by_id: 1,
  255. )
  256. article2 = Ticket::Article.create!(
  257. ticket_id: ticket2.id,
  258. from: 'some_sender@example.com',
  259. to: 'some_recipient@example.com',
  260. subject: 'some subject',
  261. message_id: 'some@id',
  262. body: 'some message',
  263. internal: false,
  264. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  265. type: Ticket::Article::Type.find_by(name: 'email'),
  266. updated_by_id: 1,
  267. created_by_id: 1,
  268. )
  269. result = Ticket::ScreenOptions.attributes_to_change(
  270. ticket_id: ticket1.id,
  271. current_user: agent1,
  272. )
  273. assert(result[:form_meta])
  274. assert(result[:form_meta][:filter])
  275. assert(result[:form_meta][:filter][:state_id])
  276. assert_equal([
  277. Ticket::State.lookup(name: 'new').id,
  278. Ticket::State.lookup(name: 'open').id,
  279. Ticket::State.lookup(name: 'pending reminder').id,
  280. Ticket::State.lookup(name: 'closed').id,
  281. Ticket::State.lookup(name: 'pending close').id,
  282. ], result[:form_meta][:filter][:state_id].sort)
  283. assert(result[:form_meta][:filter][:priority_id])
  284. assert_equal([
  285. Ticket::Priority.lookup(name: '1 low').id,
  286. Ticket::Priority.lookup(name: '2 normal').id,
  287. Ticket::Priority.lookup(name: '3 high').id,
  288. ], result[:form_meta][:filter][:priority_id].sort)
  289. assert(result[:form_meta][:filter][:type_id])
  290. assert_equal([
  291. Ticket::Article::Type.lookup(name: 'email').id,
  292. Ticket::Article::Type.lookup(name: 'phone').id,
  293. Ticket::Article::Type.lookup(name: 'note').id,
  294. ], result[:form_meta][:filter][:type_id].sort)
  295. assert(result[:form_meta][:filter][:group_id])
  296. assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
  297. assert(result[:form_meta][:dependencies])
  298. assert(result[:form_meta][:dependencies][:group_id])
  299. assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
  300. assert(result[:form_meta][:dependencies][:group_id][''])
  301. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  302. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  303. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  304. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  305. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  306. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  307. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  308. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  309. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  310. assert(result[:form_meta][:dependencies][:group_id][group2.id])
  311. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
  312. assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
  313. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
  314. assert(result[:form_meta][:dependencies][:group_id][group3.id])
  315. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
  316. assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
  317. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
  318. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
  319. result = Ticket::ScreenOptions.attributes_to_change(
  320. ticket_id: ticket2.id,
  321. current_user: agent1,
  322. )
  323. assert(result[:form_meta])
  324. assert(result[:form_meta][:filter])
  325. assert(result[:form_meta][:filter][:state_id])
  326. assert_equal([
  327. Ticket::State.lookup(name: 'new').id,
  328. Ticket::State.lookup(name: 'open').id,
  329. Ticket::State.lookup(name: 'pending reminder').id,
  330. Ticket::State.lookup(name: 'closed').id,
  331. Ticket::State.lookup(name: 'pending close').id,
  332. ], result[:form_meta][:filter][:state_id].sort)
  333. assert(result[:form_meta][:filter][:priority_id])
  334. assert_equal([
  335. Ticket::Priority.lookup(name: '1 low').id,
  336. Ticket::Priority.lookup(name: '2 normal').id,
  337. Ticket::Priority.lookup(name: '3 high').id,
  338. ], result[:form_meta][:filter][:priority_id].sort)
  339. assert(result[:form_meta][:filter][:type_id])
  340. assert_equal([
  341. Ticket::Article::Type.lookup(name: 'phone').id,
  342. Ticket::Article::Type.lookup(name: 'note').id,
  343. ], result[:form_meta][:filter][:type_id].sort)
  344. assert(result[:form_meta][:filter][:group_id])
  345. assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
  346. assert(result[:form_meta][:dependencies])
  347. assert(result[:form_meta][:dependencies][:group_id])
  348. assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
  349. assert(result[:form_meta][:dependencies][:group_id][''])
  350. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  351. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  352. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  353. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  354. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  355. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  356. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  357. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  358. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  359. assert(result[:form_meta][:dependencies][:group_id][group2.id])
  360. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
  361. assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
  362. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
  363. assert(result[:form_meta][:dependencies][:group_id][group3.id])
  364. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
  365. assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
  366. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
  367. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
  368. result = Ticket::ScreenOptions.attributes_to_change(
  369. ticket_id: ticket2.id,
  370. current_user: agent1,
  371. )
  372. assert(result[:form_meta])
  373. assert(result[:form_meta][:filter])
  374. assert(result[:form_meta][:filter][:state_id])
  375. assert_equal([
  376. Ticket::State.lookup(name: 'new').id,
  377. Ticket::State.lookup(name: 'open').id,
  378. Ticket::State.lookup(name: 'pending reminder').id,
  379. Ticket::State.lookup(name: 'closed').id,
  380. Ticket::State.lookup(name: 'pending close').id,
  381. ], result[:form_meta][:filter][:state_id].sort)
  382. assert(result[:form_meta][:filter][:priority_id])
  383. assert_equal([
  384. Ticket::Priority.lookup(name: '1 low').id,
  385. Ticket::Priority.lookup(name: '2 normal').id,
  386. Ticket::Priority.lookup(name: '3 high').id,
  387. ], result[:form_meta][:filter][:priority_id].sort)
  388. assert(result[:form_meta][:filter][:type_id])
  389. assert_equal([
  390. Ticket::Article::Type.lookup(name: 'phone').id,
  391. Ticket::Article::Type.lookup(name: 'note').id,
  392. ], result[:form_meta][:filter][:type_id].sort)
  393. assert(result[:form_meta][:filter][:group_id])
  394. assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
  395. assert(result[:form_meta][:dependencies])
  396. assert(result[:form_meta][:dependencies][:group_id])
  397. assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
  398. assert(result[:form_meta][:dependencies][:group_id][''])
  399. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  400. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  401. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  402. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  403. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  404. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  405. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  406. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  407. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  408. assert(result[:form_meta][:dependencies][:group_id][group2.id])
  409. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
  410. assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
  411. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
  412. assert(result[:form_meta][:dependencies][:group_id][group3.id])
  413. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
  414. assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
  415. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
  416. assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
  417. result = Ticket::ScreenOptions.attributes_to_change(
  418. ticket_id: ticket1.id,
  419. current_user: agent2,
  420. )
  421. assert(result[:form_meta])
  422. assert(result[:form_meta][:filter])
  423. assert(result[:form_meta][:filter][:state_id])
  424. assert_equal([
  425. Ticket::State.lookup(name: 'new').id,
  426. Ticket::State.lookup(name: 'open').id,
  427. Ticket::State.lookup(name: 'pending reminder').id,
  428. Ticket::State.lookup(name: 'closed').id,
  429. Ticket::State.lookup(name: 'pending close').id,
  430. ], result[:form_meta][:filter][:state_id].sort)
  431. assert(result[:form_meta][:filter][:priority_id])
  432. assert_equal([
  433. Ticket::Priority.lookup(name: '1 low').id,
  434. Ticket::Priority.lookup(name: '2 normal').id,
  435. Ticket::Priority.lookup(name: '3 high').id,
  436. ], result[:form_meta][:filter][:priority_id].sort)
  437. assert(result[:form_meta][:filter][:type_id])
  438. assert_equal([
  439. Ticket::Article::Type.lookup(name: 'email').id,
  440. Ticket::Article::Type.lookup(name: 'phone').id,
  441. Ticket::Article::Type.lookup(name: 'note').id,
  442. ], result[:form_meta][:filter][:type_id].sort)
  443. assert(result[:form_meta][:filter][:group_id])
  444. assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
  445. assert(result[:form_meta][:dependencies])
  446. assert(result[:form_meta][:dependencies][:group_id])
  447. assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
  448. assert(result[:form_meta][:dependencies][:group_id][''])
  449. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  450. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  451. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  452. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  453. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  454. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  455. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  456. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  457. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  458. assert(result[:form_meta][:dependencies][:group_id][group2.id])
  459. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
  460. assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
  461. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
  462. result = Ticket::ScreenOptions.attributes_to_change(
  463. ticket_id: ticket2.id,
  464. current_user: agent2,
  465. )
  466. assert(result[:form_meta])
  467. assert(result[:form_meta][:filter])
  468. assert(result[:form_meta][:filter][:state_id])
  469. assert_equal([
  470. Ticket::State.lookup(name: 'new').id,
  471. Ticket::State.lookup(name: 'open').id,
  472. Ticket::State.lookup(name: 'pending reminder').id,
  473. Ticket::State.lookup(name: 'closed').id,
  474. Ticket::State.lookup(name: 'pending close').id,
  475. ], result[:form_meta][:filter][:state_id].sort)
  476. assert(result[:form_meta][:filter][:priority_id])
  477. assert_equal([
  478. Ticket::Priority.lookup(name: '1 low').id,
  479. Ticket::Priority.lookup(name: '2 normal').id,
  480. Ticket::Priority.lookup(name: '3 high').id,
  481. ], result[:form_meta][:filter][:priority_id].sort)
  482. assert(result[:form_meta][:filter][:type_id])
  483. assert_equal([
  484. Ticket::Article::Type.lookup(name: 'phone').id,
  485. Ticket::Article::Type.lookup(name: 'note').id,
  486. ], result[:form_meta][:filter][:type_id].sort)
  487. assert(result[:form_meta][:filter][:group_id])
  488. assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
  489. assert(result[:form_meta][:dependencies])
  490. assert(result[:form_meta][:dependencies][:group_id])
  491. assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
  492. assert(result[:form_meta][:dependencies][:group_id][''])
  493. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  494. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  495. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  496. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  497. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  498. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  499. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  500. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  501. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  502. assert(result[:form_meta][:dependencies][:group_id][group2.id])
  503. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
  504. assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
  505. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
  506. result = Ticket::ScreenOptions.attributes_to_change(
  507. ticket_id: ticket1.id,
  508. current_user: agent3,
  509. )
  510. assert(result[:form_meta])
  511. assert(result[:form_meta][:filter])
  512. assert(result[:form_meta][:filter][:state_id])
  513. assert_equal([
  514. Ticket::State.lookup(name: 'new').id,
  515. Ticket::State.lookup(name: 'open').id,
  516. Ticket::State.lookup(name: 'pending reminder').id,
  517. Ticket::State.lookup(name: 'closed').id,
  518. Ticket::State.lookup(name: 'pending close').id,
  519. ], result[:form_meta][:filter][:state_id].sort)
  520. assert(result[:form_meta][:filter][:priority_id])
  521. assert_equal([
  522. Ticket::Priority.lookup(name: '1 low').id,
  523. Ticket::Priority.lookup(name: '2 normal').id,
  524. Ticket::Priority.lookup(name: '3 high').id,
  525. ], result[:form_meta][:filter][:priority_id].sort)
  526. assert(result[:form_meta][:filter][:type_id])
  527. assert_equal([
  528. Ticket::Article::Type.lookup(name: 'email').id,
  529. Ticket::Article::Type.lookup(name: 'phone').id,
  530. Ticket::Article::Type.lookup(name: 'note').id,
  531. ], result[:form_meta][:filter][:type_id].sort)
  532. assert(result[:form_meta][:filter][:group_id])
  533. assert_equal([group1.id, group2.id], result[:form_meta][:filter][:group_id].sort)
  534. assert(result[:form_meta][:dependencies])
  535. assert(result[:form_meta][:dependencies][:group_id])
  536. assert_equal(3, result[:form_meta][:dependencies][:group_id].count)
  537. assert(result[:form_meta][:dependencies][:group_id][''])
  538. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  539. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  540. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  541. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  542. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  543. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  544. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  545. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  546. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  547. assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
  548. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
  549. result = Ticket::ScreenOptions.attributes_to_change(
  550. ticket_id: ticket2.id,
  551. current_user: agent3,
  552. )
  553. assert(result[:form_meta])
  554. assert(result[:form_meta][:filter])
  555. assert(result[:form_meta][:filter][:state_id])
  556. assert_equal([
  557. Ticket::State.lookup(name: 'new').id,
  558. Ticket::State.lookup(name: 'open').id,
  559. Ticket::State.lookup(name: 'pending reminder').id,
  560. Ticket::State.lookup(name: 'closed').id,
  561. Ticket::State.lookup(name: 'pending close').id,
  562. ], result[:form_meta][:filter][:state_id].sort)
  563. assert(result[:form_meta][:filter][:priority_id])
  564. assert_equal([
  565. Ticket::Priority.lookup(name: '1 low').id,
  566. Ticket::Priority.lookup(name: '2 normal').id,
  567. Ticket::Priority.lookup(name: '3 high').id,
  568. ], result[:form_meta][:filter][:priority_id].sort)
  569. assert(result[:form_meta][:filter][:type_id])
  570. assert_equal([
  571. Ticket::Article::Type.lookup(name: 'phone').id,
  572. Ticket::Article::Type.lookup(name: 'note').id,
  573. ], result[:form_meta][:filter][:type_id].sort)
  574. assert(result[:form_meta][:filter][:group_id])
  575. assert_equal([group1.id, group2.id], result[:form_meta][:filter][:group_id].sort)
  576. assert(result[:form_meta][:dependencies])
  577. assert(result[:form_meta][:dependencies][:group_id])
  578. assert_equal(3, result[:form_meta][:dependencies][:group_id].count)
  579. assert(result[:form_meta][:dependencies][:group_id][''])
  580. assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
  581. assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
  582. assert(result[:form_meta][:dependencies][:group_id][group1.id])
  583. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
  584. assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
  585. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
  586. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
  587. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
  588. assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
  589. assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
  590. assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
  591. end
  592. end