calendar_subscriptions_tickets_test.rb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. require 'integration_test_helper'
  2. class CalendarSubscriptionsTicketsTest < ActiveSupport::TestCase
  3. user = User.create(
  4. firstname: 'CalendarSubscriptions',
  5. lastname: 'Testuser',
  6. email: 'calendar_subscriptions_testuser@example.com',
  7. updated_by_id: 1,
  8. created_by_id: 1,
  9. )
  10. user_not_assigned = User.find(1)
  11. sla = Sla.create(
  12. name: 'sla 1',
  13. condition: {},
  14. data: {
  15. 'Mon' => 'Mon', 'Tue' => 'Tue', 'Wed' => 'Wed', 'Thu' => 'Thu', 'Fri' => 'Fri', 'Sat' => 'Sat', 'Sun' => 'Sun',
  16. 'beginning_of_workday' => '9:00',
  17. 'end_of_workday' => '18:00',
  18. },
  19. timezone: 'Europe/Berlin',
  20. first_response_time: 10,
  21. update_time: 10,
  22. close_time: 10,
  23. active: true,
  24. updated_by_id: 1,
  25. created_by_id: 1,
  26. )
  27. tickets = [
  28. {
  29. owner: user,
  30. title: 'new 1',
  31. group: Group.lookup( name: 'Users'),
  32. customer_id: user.id,
  33. state: Ticket::State.lookup( name: 'new' ),
  34. priority: Ticket::Priority.lookup( name: '2 normal' ),
  35. updated_by_id: 1,
  36. created_by_id: 1,
  37. },
  38. {
  39. owner: user_not_assigned,
  40. title: 'new 2',
  41. group: Group.lookup( name: 'Users'),
  42. customer_id: user.id,
  43. state: Ticket::State.lookup( name: 'new' ),
  44. priority: Ticket::Priority.lookup( name: '2 normal' ),
  45. updated_by_id: 1,
  46. created_by_id: 1,
  47. },
  48. {
  49. owner: user,
  50. title: 'open 1',
  51. group: Group.lookup( name: 'Users'),
  52. customer_id: user.id,
  53. state: Ticket::State.lookup( name: 'open' ),
  54. priority: Ticket::Priority.lookup( name: '2 normal' ),
  55. updated_by_id: 1,
  56. created_by_id: 1,
  57. },
  58. {
  59. owner: user_not_assigned,
  60. title: 'open 2',
  61. group: Group.lookup( name: 'Users'),
  62. customer_id: user.id,
  63. state: Ticket::State.lookup( name: 'open' ),
  64. priority: Ticket::Priority.lookup( name: '2 normal' ),
  65. updated_by_id: 1,
  66. created_by_id: 1,
  67. },
  68. {
  69. owner: user,
  70. title: 'pending reminder 1',
  71. group: Group.lookup( name: 'Users'),
  72. customer_id: user.id,
  73. state: Ticket::State.lookup( name: 'pending reminder' ),
  74. pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
  75. priority: Ticket::Priority.lookup( name: '2 normal' ),
  76. updated_by_id: 1,
  77. created_by_id: 1,
  78. },
  79. {
  80. owner: user,
  81. title: 'pending reminder 2',
  82. group: Group.lookup( name: 'Users'),
  83. customer_id: user.id,
  84. state: Ticket::State.lookup( name: 'pending reminder' ),
  85. pending_time: DateTime.tomorrow,
  86. priority: Ticket::Priority.lookup( name: '2 normal' ),
  87. updated_by_id: 1,
  88. created_by_id: 1,
  89. },
  90. {
  91. owner: user_not_assigned,
  92. title: 'pending reminder 3',
  93. group: Group.lookup( name: 'Users'),
  94. customer_id: user.id,
  95. state: Ticket::State.lookup( name: 'pending reminder' ),
  96. pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
  97. priority: Ticket::Priority.lookup( name: '2 normal' ),
  98. updated_by_id: 1,
  99. created_by_id: 1,
  100. },
  101. {
  102. owner: user_not_assigned,
  103. title: 'pending reminder 4',
  104. group: Group.lookup( name: 'Users'),
  105. customer_id: user.id,
  106. state: Ticket::State.lookup( name: 'pending reminder' ),
  107. pending_time: DateTime.tomorrow,
  108. priority: Ticket::Priority.lookup( name: '2 normal' ),
  109. updated_by_id: 1,
  110. created_by_id: 1,
  111. },
  112. {
  113. owner: user,
  114. title: 'pending close 1',
  115. group: Group.lookup( name: 'Users'),
  116. customer_id: user.id,
  117. state: Ticket::State.lookup( name: 'pending close' ),
  118. pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
  119. priority: Ticket::Priority.lookup( name: '2 normal' ),
  120. updated_by_id: 1,
  121. created_by_id: 1,
  122. },
  123. {
  124. owner: user,
  125. title: 'pending close 2',
  126. group: Group.lookup( name: 'Users'),
  127. customer_id: user.id,
  128. state: Ticket::State.lookup( name: 'pending close' ),
  129. pending_time: DateTime.tomorrow,
  130. priority: Ticket::Priority.lookup( name: '2 normal' ),
  131. updated_by_id: 1,
  132. created_by_id: 1,
  133. },
  134. {
  135. owner: user_not_assigned,
  136. title: 'pending close 3',
  137. group: Group.lookup( name: 'Users'),
  138. customer_id: user.id,
  139. state: Ticket::State.lookup( name: 'pending close' ),
  140. pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
  141. priority: Ticket::Priority.lookup( name: '2 normal' ),
  142. updated_by_id: 1,
  143. created_by_id: 1,
  144. },
  145. {
  146. owner: user_not_assigned,
  147. title: 'pending close 4',
  148. group: Group.lookup( name: 'Users'),
  149. customer_id: user.id,
  150. state: Ticket::State.lookup( name: 'pending close' ),
  151. pending_time: DateTime.tomorrow,
  152. priority: Ticket::Priority.lookup( name: '2 normal' ),
  153. updated_by_id: 1,
  154. created_by_id: 1,
  155. },
  156. {
  157. owner: user,
  158. title: 'escalation 1',
  159. group: Group.lookup( name: 'Users'),
  160. customer_id: user.id,
  161. state: Ticket::State.lookup( name: 'open' ),
  162. priority: Ticket::Priority.lookup( name: '2 normal' ),
  163. created_at: '2013-03-21 09:30:00 UTC',
  164. updated_at: '2013-03-21 09:30:00 UTC',
  165. updated_by_id: 1,
  166. created_by_id: 1,
  167. },
  168. {
  169. owner: user_not_assigned,
  170. title: 'escalation 2',
  171. group: Group.lookup( name: 'Users'),
  172. customer_id: user.id,
  173. state: Ticket::State.lookup( name: 'open' ),
  174. priority: Ticket::Priority.lookup( name: '2 normal' ),
  175. created_at: '2013-03-21 09:30:00 UTC',
  176. updated_at: '2013-03-21 09:30:00 UTC',
  177. updated_by_id: 1,
  178. created_by_id: 1,
  179. },
  180. ]
  181. tickets.each do |ticket|
  182. Ticket.create( ticket )
  183. end
  184. defaults_disabled = {
  185. escalation: {
  186. own: false,
  187. not_assigned: false,
  188. },
  189. new_open: {
  190. own: false,
  191. not_assigned: false,
  192. },
  193. pending: {
  194. own: false,
  195. not_assigned: false,
  196. }
  197. }
  198. test 'new_open' do
  199. tests = [
  200. {
  201. count: 0,
  202. name: 'none',
  203. preferences: {
  204. new_open: {
  205. own: false,
  206. not_assigned: false,
  207. }
  208. },
  209. owner_ids: []
  210. },
  211. {
  212. count: 3,
  213. name: 'owner',
  214. preferences: {
  215. new_open: {
  216. own: true,
  217. not_assigned: false,
  218. }
  219. },
  220. owner_ids: [user.id]
  221. },
  222. {
  223. count: 3,
  224. name: 'not_assigned',
  225. preferences: {
  226. new_open: {
  227. own: false,
  228. not_assigned: true,
  229. }
  230. },
  231. owner_ids: [user_not_assigned.id]
  232. },
  233. {
  234. count: 6,
  235. name: 'owner+not_assigned',
  236. preferences: {
  237. new_open: {
  238. own: true,
  239. not_assigned: true,
  240. }
  241. },
  242. owner_ids: [user.id, user_not_assigned.id]
  243. },
  244. ]
  245. tests.each do |test_data|
  246. preferences = defaults_disabled.merge( test_data[:preferences] )
  247. user.preferences[:calendar_subscriptions] = {}
  248. user.preferences[:calendar_subscriptions][:tickets] = preferences
  249. calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
  250. event_data = calendar_subscriptions_ticket.new_open
  251. assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
  252. calendar_subscriptions = CalendarSubscriptions.new( user )
  253. ical = calendar_subscriptions.all
  254. event_data.each do |event|
  255. contained = false
  256. if ical.match?(/#{event[:summary]}/)
  257. contained = true
  258. end
  259. assert( contained, "#{test_data[:name]} new_open ical contains '#{event[:summary]}'" )
  260. end
  261. end
  262. end
  263. test 'pending' do
  264. tests = [
  265. {
  266. count: 0,
  267. name: 'none',
  268. preferences: {
  269. pending: {
  270. own: false,
  271. not_assigned: false,
  272. }
  273. },
  274. owner_ids: []
  275. },
  276. {
  277. count: 4,
  278. name: 'owner',
  279. preferences: {
  280. pending: {
  281. own: true,
  282. not_assigned: false,
  283. }
  284. },
  285. owner_ids: [user.id]
  286. },
  287. {
  288. count: 4,
  289. name: 'not_assigned',
  290. preferences: {
  291. pending: {
  292. own: false,
  293. not_assigned: true,
  294. }
  295. },
  296. owner_ids: [user_not_assigned.id]
  297. },
  298. {
  299. count: 8,
  300. name: 'owner+not_assigned',
  301. preferences: {
  302. pending: {
  303. own: true,
  304. not_assigned: true,
  305. }
  306. },
  307. owner_ids: [user.id, user_not_assigned.id]
  308. },
  309. ]
  310. tests.each do |test_data|
  311. preferences = defaults_disabled.merge( test_data[:preferences] )
  312. user.preferences[:calendar_subscriptions] = {}
  313. user.preferences[:calendar_subscriptions][:tickets] = preferences
  314. calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
  315. event_data = calendar_subscriptions_ticket.pending
  316. assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
  317. calendar_subscriptions = CalendarSubscriptions.new( user )
  318. ical = calendar_subscriptions.all
  319. event_data.each do |event|
  320. contained = false
  321. if ical.match?(/#{event[:summary]}/)
  322. contained = true
  323. end
  324. assert( contained, "#{test_data[:name]} pending ical contains '#{event[:summary]}'" )
  325. end
  326. end
  327. end
  328. test 'escalation' do
  329. tests = [
  330. {
  331. count: 0,
  332. name: 'none',
  333. preferences: {
  334. escalation: {
  335. own: false,
  336. not_assigned: false,
  337. }
  338. },
  339. owner_ids: []
  340. },
  341. {
  342. count: 7,
  343. name: 'owner',
  344. preferences: {
  345. escalation: {
  346. own: true,
  347. not_assigned: false,
  348. }
  349. },
  350. owner_ids: [user.id]
  351. },
  352. {
  353. count: 7,
  354. name: 'not_assigned',
  355. preferences: {
  356. escalation: {
  357. own: false,
  358. not_assigned: true,
  359. }
  360. },
  361. owner_ids: [user_not_assigned.id]
  362. },
  363. {
  364. count: 12,
  365. name: 'owner+not_assigned',
  366. preferences: {
  367. escalation: {
  368. own: true,
  369. not_assigned: true,
  370. }
  371. },
  372. owner_ids: [user.id, user_not_assigned.id]
  373. },
  374. ]
  375. tests.each do |test_data|
  376. preferences = defaults_disabled.merge( test_data[:preferences] )
  377. user.preferences[:calendar_subscriptions] = {}
  378. user.preferences[:calendar_subscriptions][:tickets] = preferences
  379. calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
  380. event_data = calendar_subscriptions_ticket.escalation
  381. assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
  382. calendar_subscriptions = CalendarSubscriptions.new( user )
  383. ical = calendar_subscriptions.all
  384. event_data.each do |event|
  385. contained = false
  386. if ical.match?(/#{event[:summary]}/)
  387. contained = true
  388. end
  389. assert( contained, "#{test_data[:name]} escalation ical contains '#{event[:summary]}'" )
  390. end
  391. end
  392. end
  393. end