calendar_subscriptions_tickets_test.rb 11 KB

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