ticket_escalation_test.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. require 'test_helper'
  2. class TicketEscalationTest < ActiveSupport::TestCase
  3. test 'ticket create' do
  4. ticket = Ticket.new(
  5. title: 'some value 123',
  6. group: Group.lookup(name: 'Users'),
  7. customer_id: 2,
  8. updated_by_id: 1,
  9. created_by_id: 1,
  10. )
  11. ticket.save!
  12. assert(ticket, 'ticket created')
  13. assert_not(ticket.escalation_at)
  14. assert_not(ticket.has_changes_to_save?)
  15. article = Ticket::Article.create!(
  16. ticket_id: ticket.id,
  17. type_id: Ticket::Article::Type.find_by(name: 'note').id,
  18. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  19. body: 'some body',
  20. internal: false,
  21. updated_by_id: 1,
  22. created_by_id: 1,
  23. )
  24. assert_not(article.has_changes_to_save?)
  25. assert_not(ticket.has_changes_to_save?)
  26. calendar = Calendar.create_or_update(
  27. name: 'Escalation Test',
  28. timezone: 'Europe/Berlin',
  29. business_hours: {
  30. mon: {
  31. active: true,
  32. timeframes: [ ['00:00', '23:59'] ]
  33. },
  34. tue: {
  35. active: true,
  36. timeframes: [ ['00:00', '23:59'] ]
  37. },
  38. wed: {
  39. active: true,
  40. timeframes: [ ['00:00', '23:59'] ]
  41. },
  42. thu: {
  43. active: true,
  44. timeframes: [ ['00:00', '23:59'] ]
  45. },
  46. fri: {
  47. active: true,
  48. timeframes: [ ['00:00', '23:59'] ]
  49. },
  50. sat: {
  51. active: true,
  52. timeframes: [ ['00:00', '23:59'] ]
  53. },
  54. sun: {
  55. active: true,
  56. timeframes: [ ['00:00', '23:59'] ]
  57. },
  58. },
  59. default: true,
  60. ical_url: nil,
  61. updated_by_id: 1,
  62. created_by_id: 1,
  63. )
  64. sla = Sla.create_or_update(
  65. name: 'test sla 1',
  66. condition: {
  67. 'ticket.title' => {
  68. operator: 'contains',
  69. value: 'some value 123',
  70. },
  71. },
  72. first_response_time: 60,
  73. update_time: 180,
  74. solution_time: 240,
  75. calendar_id: calendar.id,
  76. updated_by_id: 1,
  77. created_by_id: 1,
  78. )
  79. ticket = Ticket.new(
  80. title: 'some value 123',
  81. group: Group.lookup(name: 'Users'),
  82. customer_id: 2,
  83. updated_by_id: 1,
  84. created_by_id: 1,
  85. )
  86. ticket.save!
  87. assert(ticket, 'ticket created')
  88. ticket_escalation_at = ticket.escalation_at
  89. assert(ticket.escalation_at)
  90. assert_not(ticket.has_changes_to_save?)
  91. article = Ticket::Article.create!(
  92. ticket_id: ticket.id,
  93. type_id: Ticket::Article::Type.find_by(name: 'note').id,
  94. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  95. body: 'some body',
  96. internal: false,
  97. updated_by_id: 1,
  98. created_by_id: 1,
  99. )
  100. assert_not(article.has_changes_to_save?)
  101. assert_not(ticket.has_changes_to_save?)
  102. travel 1.second
  103. sla.first_response_time = 30
  104. sla.save!
  105. ticket.save!
  106. assert_not(ticket.has_changes_to_save?)
  107. assert(ticket.escalation_at)
  108. assert_equal(ticket_escalation_at.to_s, ticket.escalation_at.to_s)
  109. ticket.title = 'some value 123-1'
  110. ticket.save!
  111. assert_not(ticket.has_changes_to_save?)
  112. assert(ticket.escalation_at)
  113. assert_not_equal(ticket_escalation_at.to_s, ticket.escalation_at.to_s)
  114. sla.destroy!
  115. calendar.destroy!
  116. ticket.save!
  117. assert_not(ticket.has_changes_to_save?)
  118. assert(ticket.escalation_at)
  119. ticket.title = 'some value 123-2'
  120. ticket.save!
  121. assert_not(ticket.has_changes_to_save?)
  122. assert_not(ticket.escalation_at)
  123. end
  124. end