ticket_overview_test.rb 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketOverviewTest < ActiveSupport::TestCase
  4. # create base
  5. group = Group.create_or_update(
  6. name: 'OverviewTest',
  7. updated_at: '2015-02-05 16:37:00',
  8. updated_by_id: 1,
  9. created_by_id: 1,
  10. )
  11. roles = Role.where(name: 'Agent')
  12. agent1 = User.create_or_update(
  13. login: 'ticket-overview-agent1@example.com',
  14. firstname: 'Overview',
  15. lastname: 'Agent1',
  16. email: 'ticket-overview-agent1@example.com',
  17. password: 'agentpw',
  18. active: true,
  19. roles: roles,
  20. groups: [group],
  21. updated_at: '2015-02-05 16:37:00',
  22. updated_by_id: 1,
  23. created_by_id: 1,
  24. )
  25. agent2 = User.create_or_update(
  26. login: 'ticket-overview-agent2@example.com',
  27. firstname: 'Overview',
  28. lastname: 'Agent2',
  29. email: 'ticket-overview-agent2@example.com',
  30. password: 'agentpw',
  31. active: true,
  32. roles: roles,
  33. #groups: groups,
  34. updated_at: '2015-02-05 16:38:00',
  35. updated_by_id: 1,
  36. created_by_id: 1,
  37. )
  38. roles = Role.where(name: 'Customer')
  39. organization1 = Organization.create_or_update(
  40. name: 'Overview Org',
  41. updated_at: '2015-02-05 16:37:00',
  42. updated_by_id: 1,
  43. created_by_id: 1,
  44. )
  45. customer1 = User.create_or_update(
  46. login: 'ticket-overview-customer1@example.com',
  47. firstname: 'Overview',
  48. lastname: 'Customer1',
  49. email: 'ticket-overview-customer1@example.com',
  50. password: 'customerpw',
  51. active: true,
  52. organization_id: organization1.id,
  53. roles: roles,
  54. updated_at: '2015-02-05 16:37:00',
  55. updated_by_id: 1,
  56. created_by_id: 1,
  57. )
  58. customer2 = User.create_or_update(
  59. login: 'ticket-overview-customer2@example.com',
  60. firstname: 'Overview',
  61. lastname: 'Customer2',
  62. email: 'ticket-overview-customer2@example.com',
  63. password: 'customerpw',
  64. active: true,
  65. organization_id: organization1.id,
  66. roles: roles,
  67. updated_at: '2015-02-05 16:37:00',
  68. updated_by_id: 1,
  69. created_by_id: 1,
  70. )
  71. customer3 = User.create_or_update(
  72. login: 'ticket-overview-customer3@example.com',
  73. firstname: 'Overview',
  74. lastname: 'Customer3',
  75. email: 'ticket-overview-customer3@example.com',
  76. password: 'customerpw',
  77. active: true,
  78. organization_id: nil,
  79. roles: roles,
  80. updated_at: '2015-02-05 16:37:00',
  81. updated_by_id: 1,
  82. created_by_id: 1,
  83. )
  84. Overview.destroy_all
  85. UserInfo.current_user_id = 1
  86. overview_role = Role.find_by(name: 'Agent')
  87. Overview.create_or_update(
  88. name: 'My assigned Tickets',
  89. link: 'my_assigned',
  90. prio: 1000,
  91. role_id: overview_role.id,
  92. condition: {
  93. 'ticket.state_id' => {
  94. operator: 'is',
  95. value: [ 1, 2, 3, 7 ],
  96. },
  97. 'ticket.owner_id' => {
  98. operator: 'is',
  99. pre_condition: 'current_user.id',
  100. },
  101. },
  102. order: {
  103. by: 'created_at',
  104. direction: 'ASC',
  105. },
  106. view: {
  107. d: %w(title customer group created_at),
  108. s: %w(title customer group created_at),
  109. m: %w(number title customer group created_at),
  110. view_mode_default: 's',
  111. },
  112. )
  113. Overview.create_or_update(
  114. name: 'Unassigned & Open',
  115. link: 'all_unassigned',
  116. prio: 1010,
  117. role_id: overview_role.id,
  118. condition: {
  119. 'ticket.state_id' => {
  120. operator: 'is',
  121. value: [1, 2, 3],
  122. },
  123. 'ticket.owner_id' => {
  124. operator: 'is',
  125. value: 1,
  126. },
  127. },
  128. order: {
  129. by: 'created_at',
  130. direction: 'ASC',
  131. },
  132. view: {
  133. d: %w(title customer group created_at),
  134. s: %w(title customer group created_at),
  135. m: %w(number title customer group created_at),
  136. view_mode_default: 's',
  137. },
  138. )
  139. Overview.create_or_update(
  140. name: 'My Tickets 2',
  141. link: 'my_tickets_2',
  142. prio: 1020,
  143. role_id: overview_role.id,
  144. user_ids: [agent2.id],
  145. condition: {
  146. 'ticket.state_id' => {
  147. operator: 'is',
  148. value: [ 1, 2, 3, 7 ],
  149. },
  150. 'ticket.owner_id' => {
  151. operator: 'is',
  152. pre_condition: 'current_user.id',
  153. },
  154. },
  155. order: {
  156. by: 'created_at',
  157. direction: 'ASC',
  158. },
  159. view: {
  160. d: %w(title customer group created_at),
  161. s: %w(title customer group created_at),
  162. m: %w(number title customer group created_at),
  163. view_mode_default: 's',
  164. },
  165. )
  166. overview_role = Role.find_by(name: 'Customer')
  167. Overview.create_or_update(
  168. name: 'My Tickets',
  169. link: 'my_tickets',
  170. prio: 1100,
  171. role_id: overview_role.id,
  172. condition: {
  173. 'ticket.state_id' => {
  174. operator: 'is',
  175. value: [ 1, 2, 3, 4, 6, 7 ],
  176. },
  177. 'ticket.customer_id' => {
  178. operator: 'is',
  179. pre_condition: 'current_user.id',
  180. },
  181. },
  182. order: {
  183. by: 'created_at',
  184. direction: 'DESC',
  185. },
  186. view: {
  187. d: %w(title customer state created_at),
  188. s: %w(number title state created_at),
  189. m: %w(number title state created_at),
  190. view_mode_default: 's',
  191. },
  192. )
  193. Overview.create_or_update(
  194. name: 'My Organization Tickets',
  195. link: 'my_organization_tickets',
  196. prio: 1200,
  197. role_id: overview_role.id,
  198. organization_shared: true,
  199. condition: {
  200. 'ticket.state_id' => {
  201. operator: 'is',
  202. value: [ 1, 2, 3, 4, 6, 7 ],
  203. },
  204. 'ticket.organization_id' => {
  205. operator: 'is',
  206. pre_condition: 'current_user.organization_id',
  207. },
  208. },
  209. order: {
  210. by: 'created_at',
  211. direction: 'DESC',
  212. },
  213. view: {
  214. d: %w(title customer state created_at),
  215. s: %w(number title customer state created_at),
  216. m: %w(number title customer state created_at),
  217. view_mode_default: 's',
  218. },
  219. )
  220. Overview.create_or_update(
  221. name: 'My Organization Tickets (open)',
  222. link: 'my_organization_tickets_open',
  223. prio: 1200,
  224. role_id: overview_role.id,
  225. user_ids: [customer2.id],
  226. organization_shared: true,
  227. condition: {
  228. 'ticket.state_id' => {
  229. operator: 'is',
  230. value: [ 1, 2, 3 ],
  231. },
  232. 'ticket.organization_id' => {
  233. operator: 'is',
  234. pre_condition: 'current_user.organization_id',
  235. },
  236. },
  237. order: {
  238. by: 'created_at',
  239. direction: 'DESC',
  240. },
  241. view: {
  242. d: %w(title customer state created_at),
  243. s: %w(number title customer state created_at),
  244. m: %w(number title customer state created_at),
  245. view_mode_default: 's',
  246. },
  247. )
  248. overview_role = Role.find_by(name: 'Admin')
  249. Overview.create_or_update(
  250. name: 'Not Shown Admin',
  251. link: 'not_shown_admin',
  252. prio: 9900,
  253. role_id: overview_role.id,
  254. condition: {
  255. 'ticket.state_id' => {
  256. operator: 'is',
  257. value: [ 1, 2, 3 ],
  258. },
  259. },
  260. order: {
  261. by: 'created_at',
  262. direction: 'DESC',
  263. },
  264. view: {
  265. d: %w(title customer state created_at),
  266. s: %w(number title customer state created_at),
  267. m: %w(number title customer state created_at),
  268. view_mode_default: 's',
  269. },
  270. )
  271. test 'ticket create' do
  272. result = Ticket::Overviews.all(
  273. current_user: agent1,
  274. )
  275. assert_equal(2, result.count)
  276. assert_equal('My assigned Tickets', result[0].name)
  277. assert_equal('Unassigned & Open', result[1].name)
  278. result = Ticket::Overviews.all(
  279. current_user: agent2,
  280. )
  281. assert_equal(3, result.count)
  282. assert_equal('My assigned Tickets', result[0].name)
  283. assert_equal('Unassigned & Open', result[1].name)
  284. assert_equal('My Tickets 2', result[2].name)
  285. result = Ticket::Overviews.all(
  286. current_user: customer1,
  287. )
  288. assert_equal(2, result.count)
  289. assert_equal('My Tickets', result[0].name)
  290. assert_equal('My Organization Tickets', result[1].name)
  291. result = Ticket::Overviews.all(
  292. current_user: customer2,
  293. )
  294. assert_equal(3, result.count)
  295. assert_equal('My Tickets', result[0].name)
  296. assert_equal('My Organization Tickets', result[1].name)
  297. assert_equal('My Organization Tickets (open)', result[2].name)
  298. result = Ticket::Overviews.all(
  299. current_user: customer3,
  300. )
  301. assert_equal(1, result.count)
  302. assert_equal('My Tickets', result[0].name)
  303. end
  304. end