2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
require 'rails_helper'
|
2017-03-27 09:25:45 +00:00
|
|
|
require 'lib/import/transaction_factory_examples'
|
2016-11-25 16:10:37 +00:00
|
|
|
|
|
|
|
RSpec.describe Import::OTRS::StateFactory do
|
|
|
|
it_behaves_like 'Import::TransactionFactory'
|
|
|
|
|
|
|
|
it 'creates a state backup in the pre_import_hook' do
|
|
|
|
expect(described_class).to receive(:backup)
|
|
|
|
described_class.pre_import_hook([])
|
|
|
|
end
|
2017-02-14 08:59:41 +00:00
|
|
|
|
|
|
|
def load_state_json(file)
|
|
|
|
json_fixture("import/otrs/state/#{file}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates ObjectManager Ticket state_id and pending_time filter' do
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
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]
|
2017-02-14 08:59:41 +00:00
|
|
|
|
|
|
|
state_backend_param = []
|
|
|
|
states.each do |state|
|
|
|
|
state_backend_param.push(load_state_json(state))
|
|
|
|
end
|
|
|
|
|
|
|
|
ticket_state_id = ::ObjectManager::Attribute.get(
|
|
|
|
object: 'Ticket',
|
|
|
|
name: 'state_id',
|
|
|
|
)
|
|
|
|
ticket_pending_time = ::ObjectManager::Attribute.get(
|
|
|
|
object: 'Ticket',
|
|
|
|
name: 'pending_time',
|
|
|
|
)
|
|
|
|
|
2017-10-01 12:25:52 +00:00
|
|
|
expect do
|
2017-02-14 08:59:41 +00:00
|
|
|
described_class.import(state_backend_param)
|
|
|
|
|
|
|
|
# sync changes
|
|
|
|
ticket_state_id.reload
|
|
|
|
ticket_pending_time.reload
|
2017-10-01 12:25:52 +00:00
|
|
|
end.to change {
|
2017-02-14 08:59:41 +00:00
|
|
|
ticket_state_id.data_option
|
|
|
|
}.and change {
|
|
|
|
ticket_state_id.screens
|
|
|
|
}
|
|
|
|
end
|
2017-02-14 17:44:14 +00:00
|
|
|
|
|
|
|
it "doesn't update ObjectManager Ticket state_id and pending_time filter in diff import" do
|
|
|
|
|
|
|
|
ticket_state_id = ::ObjectManager::Attribute.get(
|
|
|
|
object: 'Ticket',
|
|
|
|
name: 'state_id',
|
|
|
|
)
|
|
|
|
ticket_pending_time = ::ObjectManager::Attribute.get(
|
|
|
|
object: 'Ticket',
|
|
|
|
name: 'pending_time',
|
|
|
|
)
|
|
|
|
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(Import::OTRS).to receive(:diff?).and_return(true)
|
2017-02-14 17:44:14 +00:00
|
|
|
|
2017-10-01 12:25:52 +00:00
|
|
|
expect do
|
2017-02-14 17:44:14 +00:00
|
|
|
described_class.update_attribute_settings
|
|
|
|
|
|
|
|
# sync changes
|
|
|
|
ticket_state_id.reload
|
|
|
|
ticket_pending_time.reload
|
2017-10-01 12:25:52 +00:00
|
|
|
end.to not_change {
|
2017-02-14 17:44:14 +00:00
|
|
|
ticket_state_id.data_option
|
|
|
|
}.and not_change {
|
|
|
|
ticket_state_id.screens
|
|
|
|
}.and not_change {
|
|
|
|
ticket_pending_time.data_option
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets default create and update State' do
|
|
|
|
state = ::Ticket::State.first
|
|
|
|
state.default_create = false
|
|
|
|
state.default_follow_up = false
|
|
|
|
state.callback_loop = true
|
|
|
|
state.save
|
|
|
|
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_create).and_return(state.name)
|
|
|
|
allow(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_follow_up).and_return(state.name)
|
2017-02-14 17:44:14 +00:00
|
|
|
|
|
|
|
described_class.update_attribute
|
|
|
|
state.reload
|
|
|
|
|
|
|
|
expect(state.default_create).to be true
|
|
|
|
expect(state.default_follow_up).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't set default create and update State in diff import" do
|
|
|
|
state = ::Ticket::State.first
|
|
|
|
state.default_create = false
|
|
|
|
state.default_follow_up = false
|
|
|
|
state.callback_loop = true
|
|
|
|
state.save
|
|
|
|
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(Import::OTRS).to receive(:diff?).and_return(true)
|
2017-02-14 17:44:14 +00:00
|
|
|
|
|
|
|
described_class.update_attribute_settings
|
|
|
|
state.reload
|
|
|
|
|
|
|
|
expect(state.default_create).to be false
|
|
|
|
expect(state.default_follow_up).to be false
|
|
|
|
end
|
2017-05-16 16:11:36 +00:00
|
|
|
|
|
|
|
context 'changing Ticket::State IDs' do
|
|
|
|
|
2017-10-01 12:25:52 +00:00
|
|
|
let(:state_backend_param) do
|
2017-11-23 08:09:44 +00:00
|
|
|
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]
|
2017-05-16 16:11:36 +00:00
|
|
|
|
|
|
|
state_backend_param = []
|
|
|
|
states.each do |state|
|
|
|
|
state_backend_param.push(load_state_json(state))
|
|
|
|
end
|
|
|
|
state_backend_param
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-05-16 16:11:36 +00:00
|
|
|
|
|
|
|
it 'updates Overviews' do
|
|
|
|
name = 'My pending reached Tickets'
|
|
|
|
overview = Overview.find_by(name: name)
|
|
|
|
expect do
|
|
|
|
described_class.import(state_backend_param)
|
|
|
|
overview = Overview.find_by(name: name)
|
|
|
|
end.to change {
|
|
|
|
overview.id
|
|
|
|
}.and change {
|
|
|
|
overview.condition['ticket.state_id'][:value]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates Macros' do
|
|
|
|
name = 'Close & Tag as Spam'
|
|
|
|
macro = Macro.find_by(name: name)
|
|
|
|
expect do
|
|
|
|
described_class.import(state_backend_param)
|
|
|
|
macro = Macro.find_by(name: name)
|
|
|
|
end.to change {
|
|
|
|
macro.id
|
|
|
|
}.and change {
|
|
|
|
macro.perform['ticket.state_id'][:value]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates Triggers' do
|
|
|
|
name = 'auto reply (on new tickets)'
|
|
|
|
trigger = Trigger.find_by(name: name)
|
|
|
|
expect do
|
|
|
|
described_class.import(state_backend_param)
|
|
|
|
trigger = Trigger.find_by(name: name)
|
|
|
|
end.to change {
|
|
|
|
trigger.id
|
|
|
|
}.and change {
|
|
|
|
trigger.condition['ticket.state_id'][:value]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|