Skip to content

Commit

Permalink
Maintenance: Improved and fixed problems with Freshdesk migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikklein committed Nov 28, 2023
1 parent 96ac5a6 commit 5a81e62
Show file tree
Hide file tree
Showing 19 changed files with 5,083 additions and 1,476 deletions.
2 changes: 1 addition & 1 deletion lib/import/otrs/state_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def update_ticket_attributes
def update_ticket_state
agent_new = fetch_ticket_states(%w[merged removed])
agent_edit = fetch_ticket_states(%w[new merged removed])
customer_new = fetch_ticket_states(%w[ew closed])
customer_new = fetch_ticket_states(%w[new closed])
customer_edit = fetch_ticket_states(%w[open closed])

ticket_state_id = ::ObjectManager::Attribute.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/sequencer/unit/import/freshdesk/conversation/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class Sequencer::Unit::Import::Freshdesk::Conversation::User < Sequencer::Unit::

skip_action :skipped, :failed

uses :dry_run, :import_job, :resource, :field_map, :id_map
uses :dry_run, :import_job, :resource, :field_map, :id_map, :skip_initial_contacts

def process
return if user_exists? || resource['user_id'].blank?
return if !skip_initial_contacts || user_exists? || resource['user_id'].blank?

::Sequencer.process('Import::Freshdesk::Contact',
parameters: {
Expand Down
2 changes: 2 additions & 0 deletions lib/sequencer/unit/import/freshdesk/mapping/custom_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Sequencer::Unit::Import::Freshdesk::Mapping::CustomFields < Sequencer::Uni
uses :resource, :field_map, :model_class

def process
return if !resource['custom_fields']

provide_mapped do
custom_fields
end
Expand Down
15 changes: 8 additions & 7 deletions lib/sequencer/unit/import/freshdesk/perform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ class Sequencer::Unit::Import::Freshdesk::Perform < Sequencer::Unit::Base

skip_action :skipped, :failed

uses :resources, :object, :import_job, :dry_run, :field_map, :id_map, :time_entry_available
uses :resources, :object, :import_job, :dry_run, :field_map, :id_map, :time_entry_available, :skip_initial_contacts

def process
resources.each do |resource|
::Sequencer.process("Import::Freshdesk::#{object}",
parameters: {
import_job: import_job,
dry_run: dry_run,
resource: resource,
field_map: field_map,
id_map: id_map,
time_entry_available: time_entry_available,
import_job: import_job,
dry_run: dry_run,
resource: resource,
field_map: field_map,
id_map: id_map,
time_entry_available: time_entry_available,
skip_initial_contacts: skip_initial_contacts,
})
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sequencer/unit/import/freshdesk/requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def request(api_path:, params: nil)
params: params,
)

return response if response.is_a? Net::HTTPOK
return response if response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPNotFound)

handle_error response, iteration
rescue e
Expand Down
19 changes: 10 additions & 9 deletions lib/sequencer/unit/import/freshdesk/sub_sequence/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Sequencer::Unit::Import::Freshdesk::SubSequence::Generic < Sequencer::Unit::Base

uses :dry_run, :import_job, :field_map, :id_map, :time_entry_available
uses :dry_run, :import_job, :field_map, :id_map, :time_entry_available, :skip_initial_contacts

attr_accessor :iteration, :result

Expand All @@ -13,14 +13,15 @@ def process
@iteration = iteration
@result = ::Sequencer.process(sequence_name,
parameters: {
request_params: request_params,
import_job: import_job,
dry_run: dry_run,
object: object,
field_map: field_map,
id_map: id_map,
skipped_resource_id: skipped_resource_id,
time_entry_available: time_entry_available,
request_params: request_params,
import_job: import_job,
dry_run: dry_run,
object: object,
field_map: field_map,
id_map: id_map,
skipped_resource_id: skipped_resource_id,
skip_initial_contacts: skip_initial_contacts,
time_entry_available: time_entry_available,
},
expecting: self.class.const_get(:EXPECTING))
break if iteration_should_stop?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class Sequencer::Unit::Import::Freshdesk::Ticket::RequesterContact < Sequencer::

skip_action :skipped, :failed

uses :dry_run, :import_job, :resource, :field_map, :id_map
uses :dry_run, :import_job, :resource, :field_map, :id_map, :skip_initial_contacts

def process
return if contact_exists? || resource['requester_id'].blank?
return if !skip_initial_contacts || contact_exists? || resource['requester_id'].blank?

::Sequencer.process('Import::Freshdesk::Contact',
parameters: {
Expand Down
2 changes: 1 addition & 1 deletion lib/sequencer/unit/import/kayako/requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def request(api_path:, params: nil)
end

handle_error response, iteration
rescue Net::HTTPClientError, OpenSSL::SSL::SSLError => e
rescue e
handle_exception e, iteration
end

Expand Down
6 changes: 3 additions & 3 deletions spec/integration/freshdesk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
},
'Users' => {
'skipped' => 0,
'created' => 19,
'created' => 18,
'updated' => 0,
'unchanged' => 0,
'failed' => 0,
'deactivated' => 0,
'sum' => 19,
'total' => 19,
'sum' => 18,
'total' => 18,
},
'Organizations' => {
'skipped' => 0,
Expand Down
18 changes: 9 additions & 9 deletions spec/integration/kayako_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@
},
'Users' => {
'skipped' => 0,
'created' => 7,
'created' => 8,
'updated' => 0,
'unchanged' => 0,
'failed' => 0,
'deactivated' => 0,
'sum' => 7,
'total' => 7,
'sum' => 8,
'total' => 8,
},
'Organizations' => {
'skipped' => 0,
'created' => 2,
'created' => 3,
'updated' => 1,
'unchanged' => 0,
'failed' => 0,
'deactivated' => 0,
'sum' => 3,
'total' => 3,
'sum' => 4,
'total' => 4,
},
'Tickets' => {
'skipped' => 0,
'created' => 4,
'created' => 5,
'updated' => 1,
'unchanged' => 0,
'failed' => 0,
'deactivated' => 0,
'sum' => 5,
'total' => 5,
'sum' => 6,
'total' => 6,
},
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@
end
let(:process_payload) do
{
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
resource: resource,
field_map: {},
id_map: id_map,
time_entry_available: false,
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
resource: resource,
field_map: {},
id_map: id_map,
time_entry_available: false,
skip_initial_contacts: false,
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@

let(:process_payload) do
{
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
object: 'Group',
request_params: {},
field_map: {},
id_map: {},
skipped_resource_id: nil,
time_entry_available: true,
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
object: 'Group',
request_params: {},
field_map: {},
id_map: {},
skipped_resource_id: nil,
time_entry_available: true,
skip_initial_contacts: false,
}
end

Expand Down
13 changes: 7 additions & 6 deletions spec/lib/sequencer/sequence/import/freshdesk/ticket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@
end
let(:process_payload) do
{
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
resource: resource,
field_map: field_map,
id_map: id_map,
time_entry_available: true,
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
resource: resource,
field_map: field_map,
id_map: id_map,
time_entry_available: true,
skip_initial_contacts: false,
}
end
let(:owner) { create(:agent, group_ids: [group.id]) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@

let(:process_payload) do
{
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
object: 'TimeEntry',
request_params: {
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
object: 'TimeEntry',
request_params: {
ticket: {
'id' => 1001,
},
},
field_map: {},
id_map: {
field_map: {},
id_map: {
'Ticket' => {
1001 => ticket.id,
},
'User' => {
80_014_400_475 => 1,
}
},
skipped_resource_id: nil,
time_entry_available: time_entry_available,
skipped_resource_id: nil,
time_entry_available: time_entry_available,
skip_initial_contacts: false,
}
end

Expand Down
11 changes: 6 additions & 5 deletions spec/lib/sequencer/sequence/import/freshdesk/time_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
end
let(:process_payload) do
{
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
resource: resource,
field_map: {},
id_map: id_map,
import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
dry_run: false,
resource: resource,
field_map: {},
id_map: id_map,
skip_initial_contacts: false,
}
end

Expand Down
1 change: 1 addition & 0 deletions spec/lib/sequencer/unit/import/freshdesk/tickets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
id_map: id_map,
time_entry_available: true,
tickets_updated_since: nil,
skip_initial_contacts: false,
}
end

Expand Down
3 changes: 3 additions & 0 deletions spec/support/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def self.inject_advisory(example)
RSpec.configure do |config|
config.around(:each, use_vcr: true) do |example|

# S3 does not play well with time freezing (Aws::S3::Errors::RequestTimeTooSkewed).
Setting.set('storage_provider', 'DB') if Setting.get('storage_provider') == 'S3'

# Perform live integration tests without using VCR cassettes if CI_IGNORE_CASSETTES is set.
if example.metadata[:integration] && %w[1 true].include?(ENV['CI_IGNORE_CASSETTES'])
next VCR.turned_off(ignore_cassettes: true) do
Expand Down
Loading

0 comments on commit 5a81e62

Please sign in to comment.