ticket_state_change_test.rb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. require 'test_helper'
  2. class TicketStateChangeTest < ActiveSupport::TestCase
  3. test 'check if after reply ticket is open' do
  4. ticket1 = Ticket.create!(
  5. title: 'com test 1',
  6. group: Group.lookup(name: 'Users'),
  7. customer_id: 2,
  8. state: Ticket::State.lookup(name: 'new'),
  9. priority: Ticket::Priority.lookup(name: '2 normal'),
  10. updated_by_id: 1,
  11. created_by_id: 1,
  12. )
  13. assert(ticket1, 'ticket created')
  14. article1 = Ticket::Article.create!(
  15. ticket_id: ticket1.id,
  16. from: 'some_customer_com-1@example.com',
  17. to: 'some_zammad_com-1@example.com',
  18. subject: 'com test 1',
  19. message_id: 'some@id_com_1',
  20. body: 'some message 123',
  21. internal: false,
  22. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  23. type: Ticket::Article::Type.find_by(name: 'email'),
  24. updated_by_id: 1,
  25. created_by_id: 1,
  26. )
  27. Observer::Transaction.commit
  28. Scheduler.worker(true)
  29. ticket1.reload
  30. assert_equal('new', ticket1.state.name)
  31. ticket1.with_lock do
  32. ticket1.update!(state_id: Ticket::State.find_by(name: 'new').id)
  33. article2 = Ticket::Article.create!(
  34. ticket_id: ticket1.id,
  35. from: 'some_zammad_com-1@example.com',
  36. to: 'some_customer_com-1@example.com',
  37. subject: 'com test 1',
  38. message_id: 'some@id_com_2',
  39. body: 'some message 123',
  40. internal: false,
  41. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  42. type: Ticket::Article::Type.find_by(name: 'email'),
  43. updated_by_id: 1,
  44. created_by_id: 1,
  45. )
  46. end
  47. Observer::Transaction.commit
  48. Scheduler.worker(true)
  49. ticket1.reload
  50. assert_equal('open', ticket1.state.name)
  51. end
  52. test 'check if after reply ticket is closed' do
  53. ticket1 = Ticket.create!(
  54. title: 'com test 1',
  55. group: Group.lookup(name: 'Users'),
  56. customer_id: 2,
  57. state: Ticket::State.lookup(name: 'new'),
  58. priority: Ticket::Priority.lookup(name: '2 normal'),
  59. updated_by_id: 1,
  60. created_by_id: 1,
  61. )
  62. assert(ticket1, 'ticket created')
  63. article1 = Ticket::Article.create!(
  64. ticket_id: ticket1.id,
  65. from: 'some_customer_com-1@example.com',
  66. to: 'some_zammad_com-1@example.com',
  67. subject: 'com test 1',
  68. message_id: 'some@id_com_1',
  69. body: 'some message 123',
  70. internal: false,
  71. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  72. type: Ticket::Article::Type.find_by(name: 'email'),
  73. updated_by_id: 1,
  74. created_by_id: 1,
  75. )
  76. Observer::Transaction.commit
  77. Scheduler.worker(true)
  78. ticket1.reload
  79. assert_equal('new', ticket1.state.name)
  80. ticket1.with_lock do
  81. ticket1.update!(state_id: Ticket::State.find_by(name: 'closed').id)
  82. article2 = Ticket::Article.create!(
  83. ticket_id: ticket1.id,
  84. from: 'some_zammad_com-1@example.com',
  85. to: 'some_customer_com-1@example.com',
  86. subject: 'com test 1',
  87. message_id: 'some@id_com_2',
  88. body: 'some message 123',
  89. internal: false,
  90. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  91. type: Ticket::Article::Type.find_by(name: 'email'),
  92. updated_by_id: 1,
  93. created_by_id: 1,
  94. )
  95. end
  96. Observer::Transaction.commit
  97. Scheduler.worker(true)
  98. ticket1.reload
  99. assert_equal('closed', ticket1.state.name)
  100. end
  101. end