state_factory_spec.rb 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. require 'rails_helper'
  2. require 'lib/import/transaction_factory_examples'
  3. RSpec.describe Import::OTRS::StateFactory do
  4. it_behaves_like 'Import::TransactionFactory'
  5. it 'creates a state backup in the pre_import_hook' do
  6. expect(described_class).to receive(:backup)
  7. described_class.pre_import_hook([])
  8. end
  9. def load_state_json(file)
  10. json_fixture("import/otrs/state/#{file}")
  11. end
  12. it 'updates ObjectManager Ticket state_id and pending_time filter' do
  13. states = %w[new open merged pending_reminder pending_auto_close_p pending_auto_close_n pending_auto_close_p closed_successful closed_unsuccessful closed_successful removed]
  14. state_backend_param = []
  15. states.each do |state|
  16. state_backend_param.push(load_state_json(state))
  17. end
  18. ticket_state_id = ::ObjectManager::Attribute.get(
  19. object: 'Ticket',
  20. name: 'state_id',
  21. )
  22. ticket_pending_time = ::ObjectManager::Attribute.get(
  23. object: 'Ticket',
  24. name: 'pending_time',
  25. )
  26. expect do
  27. described_class.import(state_backend_param)
  28. # sync changes
  29. ticket_state_id.reload
  30. ticket_pending_time.reload
  31. end.to change {
  32. ticket_state_id.data_option
  33. }.and change {
  34. ticket_state_id.screens
  35. }.and change {
  36. ticket_pending_time.data_option
  37. }
  38. end
  39. it "doesn't update ObjectManager Ticket state_id and pending_time filter in diff import" do
  40. ticket_state_id = ::ObjectManager::Attribute.get(
  41. object: 'Ticket',
  42. name: 'state_id',
  43. )
  44. ticket_pending_time = ::ObjectManager::Attribute.get(
  45. object: 'Ticket',
  46. name: 'pending_time',
  47. )
  48. expect(Import::OTRS).to receive(:diff?).and_return(true)
  49. expect do
  50. described_class.update_attribute_settings
  51. # sync changes
  52. ticket_state_id.reload
  53. ticket_pending_time.reload
  54. end.to not_change {
  55. ticket_state_id.data_option
  56. }.and not_change {
  57. ticket_state_id.screens
  58. }.and not_change {
  59. ticket_pending_time.data_option
  60. }
  61. end
  62. it 'sets default create and update State' do
  63. state = ::Ticket::State.first
  64. state.default_create = false
  65. state.default_follow_up = false
  66. state.callback_loop = true
  67. state.save
  68. expect(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_create).and_return(state.name)
  69. expect(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_follow_up).and_return(state.name)
  70. described_class.update_attribute
  71. state.reload
  72. expect(state.default_create).to be true
  73. expect(state.default_follow_up).to be true
  74. end
  75. it "doesn't set default create and update State in diff import" do
  76. state = ::Ticket::State.first
  77. state.default_create = false
  78. state.default_follow_up = false
  79. state.callback_loop = true
  80. state.save
  81. expect(Import::OTRS).to receive(:diff?).and_return(true)
  82. described_class.update_attribute_settings
  83. state.reload
  84. expect(state.default_create).to be false
  85. expect(state.default_follow_up).to be false
  86. end
  87. context 'changing Ticket::State IDs' do
  88. let(:state_backend_param) do
  89. states = %w[new open merged pending_reminder pending_auto_close_p pending_auto_close_n pending_auto_close_p closed_successful closed_unsuccessful closed_successful removed]
  90. state_backend_param = []
  91. states.each do |state|
  92. state_backend_param.push(load_state_json(state))
  93. end
  94. state_backend_param
  95. end
  96. it 'updates Overviews' do
  97. name = 'My pending reached Tickets'
  98. overview = Overview.find_by(name: name)
  99. expect do
  100. described_class.import(state_backend_param)
  101. overview = Overview.find_by(name: name)
  102. end.to change {
  103. overview.id
  104. }.and change {
  105. overview.condition['ticket.state_id'][:value]
  106. }
  107. end
  108. it 'updates Macros' do
  109. name = 'Close & Tag as Spam'
  110. macro = Macro.find_by(name: name)
  111. expect do
  112. described_class.import(state_backend_param)
  113. macro = Macro.find_by(name: name)
  114. end.to change {
  115. macro.id
  116. }.and change {
  117. macro.perform['ticket.state_id'][:value]
  118. }
  119. end
  120. it 'updates Triggers' do
  121. name = 'auto reply (on new tickets)'
  122. trigger = Trigger.find_by(name: name)
  123. expect do
  124. described_class.import(state_backend_param)
  125. trigger = Trigger.find_by(name: name)
  126. end.to change {
  127. trigger.id
  128. }.and change {
  129. trigger.condition['ticket.state_id'][:value]
  130. }
  131. end
  132. it 'updates ObjectManager::Attributes' do
  133. attribute = ObjectManager::Attribute.get(
  134. object: 'Ticket',
  135. name: 'pending_time',
  136. )
  137. expect do
  138. described_class.import(state_backend_param)
  139. attribute = ObjectManager::Attribute.get(
  140. object: 'Ticket',
  141. name: 'pending_time',
  142. )
  143. end.to change {
  144. attribute.data_option[:required_if][:state_id]
  145. }
  146. end
  147. end
  148. end