ticket_state_test.rb 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. require 'test_helper'
  2. class TicketStateTest < ActiveSupport::TestCase
  3. test 'base' do
  4. # check current state
  5. assert_equal(1, Ticket::State.where(default_create: true).count)
  6. assert_equal(1, Ticket::State.where(default_follow_up: true).count)
  7. state_create = Ticket::State.find_by(default_create: true)
  8. state_follow_up = Ticket::State.find_by(default_follow_up: true)
  9. # add new state
  10. state_new2 = Ticket::State.create_if_not_exists(
  11. name: 'new 2',
  12. state_type_id: Ticket::StateType.find_by(name: 'new').id,
  13. updated_by_id: 1,
  14. created_by_id: 1,
  15. )
  16. state_follow_up2 = Ticket::State.create_if_not_exists(
  17. name: 'open 2',
  18. state_type_id: Ticket::StateType.find_by(name: 'open').id,
  19. updated_by_id: 1,
  20. created_by_id: 1,
  21. )
  22. # verify states
  23. assert_equal(1, Ticket::State.where(default_create: true).count)
  24. assert_equal(1, Ticket::State.where(default_follow_up: true).count)
  25. assert_equal(state_create.id, Ticket::State.find_by(default_create: true).id)
  26. assert_equal(state_follow_up.id, Ticket::State.find_by(default_follow_up: true).id)
  27. # cleanup
  28. state_new2.destroy
  29. state_follow_up2.destroy
  30. # verify states
  31. assert_equal(1, Ticket::State.where(default_create: true).count)
  32. assert_equal(1, Ticket::State.where(default_follow_up: true).count)
  33. assert_equal(state_create.id, Ticket::State.find_by(default_create: true).id)
  34. assert_equal(state_follow_up.id, Ticket::State.find_by(default_follow_up: true).id)
  35. # add new state
  36. state_new3 = Ticket::State.create_if_not_exists(
  37. name: 'new 3',
  38. state_type_id: Ticket::StateType.find_by(name: 'new').id,
  39. default_create: true,
  40. updated_by_id: 1,
  41. created_by_id: 1,
  42. )
  43. state_follow_up3 = Ticket::State.create_if_not_exists(
  44. name: 'open 3',
  45. state_type_id: Ticket::StateType.find_by(name: 'open').id,
  46. default_follow_up: true,
  47. updated_by_id: 1,
  48. created_by_id: 1,
  49. )
  50. # verify states
  51. assert_equal(1, Ticket::State.where(default_create: true).count)
  52. assert_equal(1, Ticket::State.where(default_follow_up: true).count)
  53. assert_not_equal(state_create.id, Ticket::State.find_by(default_create: true).id)
  54. assert_equal(state_new3.id, Ticket::State.find_by(default_create: true).id)
  55. assert_not_equal(state_follow_up.id, Ticket::State.find_by(default_follow_up: true).id)
  56. assert_equal(state_follow_up3.id, Ticket::State.find_by(default_follow_up: true).id)
  57. # cleanup
  58. state_new3.destroy
  59. state_follow_up3.destroy
  60. # verify states
  61. assert_equal(1, Ticket::State.where(default_create: true).count)
  62. assert_equal(1, Ticket::State.where(default_follow_up: true).count)
  63. assert_equal(state_create.id, Ticket::State.find_by(default_create: true).id)
  64. assert_not_equal(state_follow_up.id, Ticket::State.find_by(default_follow_up: true).id)
  65. # cleanup
  66. state_create.reload
  67. state_create.default_create = true
  68. state_create.save!
  69. state_follow_up.reload
  70. state_follow_up.default_follow_up = true
  71. state_follow_up.save!
  72. # verify states
  73. assert_equal(1, Ticket::State.where(default_create: true).count)
  74. assert_equal(1, Ticket::State.where(default_follow_up: true).count)
  75. assert_equal(state_create.id, Ticket::State.find_by(default_create: true).id)
  76. assert_equal(state_follow_up.id, Ticket::State.find_by(default_follow_up: true).id)
  77. end
  78. end