diff --git a/lib/sequencer/unit/import/freshdesk/object_attribute/config.rb b/lib/sequencer/unit/import/freshdesk/object_attribute/config.rb index 920bca71e..74f50b65d 100644 --- a/lib/sequencer/unit/import/freshdesk/object_attribute/config.rb +++ b/lib/sequencer/unit/import/freshdesk/object_attribute/config.rb @@ -17,7 +17,7 @@ class Sequencer state.provide(:config) do { object: model_class.to_s, - name: sanitized_name, + name: DEFAULT_FIELD_NAME_MAP[resource['name']] || sanitized_name, display: resource['label'], data_type: data_type, data_option: data_option, @@ -43,6 +43,11 @@ class Sequencer 'custom_decimal' => 'input', # Don't use 'integer' as it would cut off the fractional part. 'custom_url' => 'input', 'custom_phone_number' => 'input', + 'default_ticket_type' => 'select', + }.freeze + + DEFAULT_FIELD_NAME_MAP = { + 'ticket_type' => 'type', }.freeze def data_type diff --git a/lib/sequencer/unit/import/freshdesk/object_attribute/sanitized_name.rb b/lib/sequencer/unit/import/freshdesk/object_attribute/sanitized_name.rb index 1f374e1e5..e95db5642 100644 --- a/lib/sequencer/unit/import/freshdesk/object_attribute/sanitized_name.rb +++ b/lib/sequencer/unit/import/freshdesk/object_attribute/sanitized_name.rb @@ -15,7 +15,6 @@ class Sequencer private def unsanitized_name - # active_customer resource['name'] end end diff --git a/lib/sequencer/unit/import/freshdesk/object_attribute/skip.rb b/lib/sequencer/unit/import/freshdesk/object_attribute/skip.rb index 9ae550959..852ac415c 100644 --- a/lib/sequencer/unit/import/freshdesk/object_attribute/skip.rb +++ b/lib/sequencer/unit/import/freshdesk/object_attribute/skip.rb @@ -11,10 +11,16 @@ class Sequencer provides :action def process - return if !resource['default'] + return if !resource['default'] || allowed_default_attributes.include?(resource['name']) state.provide(:action, :skipped) end + + private + + def allowed_default_attributes + @allowed_default_attributes ||= %w[ticket_type] + end end end end diff --git a/lib/sequencer/unit/import/freshdesk/ticket/mapping.rb b/lib/sequencer/unit/import/freshdesk/ticket/mapping.rb index e8bae858d..8eba0fed9 100644 --- a/lib/sequencer/unit/import/freshdesk/ticket/mapping.rb +++ b/lib/sequencer/unit/import/freshdesk/ticket/mapping.rb @@ -40,6 +40,7 @@ class Sequencer state_id: state_map[resource['status']], owner_id: owner_id, customer_id: customer_id, + type: resource['type'], created_at: resource['created_at'], updated_at: resource['updated_at'], } diff --git a/spec/lib/external_credential/google_spec.rb b/spec/lib/external_credential/google_spec.rb index 60f3e7fd8..4ca0b794a 100644 --- a/spec/lib/external_credential/google_spec.rb +++ b/spec/lib/external_credential/google_spec.rb @@ -115,38 +115,36 @@ RSpec.describe ExternalCredential::Google do channel = described_class.link_account(request_token, authorization_payload) - expect(channel.options).to match( - a_hash_including( - 'inbound' => a_hash_including( - 'options' => a_hash_including( - 'auth_type' => 'XOAUTH2', - 'host' => 'imap.gmail.com', - 'ssl' => 'ssl', - 'user' => primary_email, - ) - ), - 'outbound' => a_hash_including( - 'options' => a_hash_including( - 'authentication' => 'xoauth2', - 'host' => 'smtp.gmail.com', - 'port' => 465, - 'ssl' => true, - 'user' => primary_email, - ) - ), - 'auth' => a_hash_including( - 'access_token' => access_token, - 'expires_in' => token_ttl, - 'refresh_token' => refresh_token, - 'scope' => scope_stub, - 'token_type' => 'Bearer', - 'id_token' => id_token, - 'created_at' => Time.zone.now, - 'type' => 'XOAUTH2', - 'client_id' => client_id, - 'client_secret' => client_secret, - ), - ) + expect(channel.options).to include( + 'inbound' => include( + 'options' => include( + 'auth_type' => 'XOAUTH2', + 'host' => 'imap.gmail.com', + 'ssl' => 'ssl', + 'user' => primary_email, + ) + ), + 'outbound' => include( + 'options' => include( + 'authentication' => 'xoauth2', + 'host' => 'smtp.gmail.com', + 'port' => 465, + 'ssl' => true, + 'user' => primary_email, + ) + ), + 'auth' => include( + 'access_token' => access_token, + 'expires_in' => token_ttl, + 'refresh_token' => refresh_token, + 'scope' => scope_stub, + 'token_type' => 'Bearer', + 'id_token' => id_token, + 'created_at' => Time.zone.now, + 'type' => 'XOAUTH2', + 'client_id' => client_id, + 'client_secret' => client_secret, + ), ) end end @@ -267,7 +265,7 @@ RSpec.describe ExternalCredential::Google do it 'refreshes token' do expect do channel.refresh_xoauth2! - end.to change { channel.options['auth'] }.to a_hash_including( + end.to change { channel.options['auth'] }.to include( 'created_at' => Time.zone.now, 'access_token' => refreshed_access_token, ) diff --git a/spec/lib/external_credential/microsoft365_spec.rb b/spec/lib/external_credential/microsoft365_spec.rb index a88697a23..51aed3c31 100644 --- a/spec/lib/external_credential/microsoft365_spec.rb +++ b/spec/lib/external_credential/microsoft365_spec.rb @@ -81,37 +81,35 @@ RSpec.describe ExternalCredential::Microsoft365 do channel = described_class.link_account(request_token, authorization_payload) - expect(channel.options).to match( - a_hash_including( - 'inbound' => a_hash_including( - 'options' => a_hash_including( - 'auth_type' => 'XOAUTH2', - 'host' => 'outlook.office365.com', - 'ssl' => 'ssl', - 'user' => email_address, - ) - ), - 'outbound' => a_hash_including( - 'options' => a_hash_including( - 'authentication' => 'xoauth2', - 'host' => 'smtp.office365.com', - 'port' => 587, - 'user' => email_address, - ) - ), - 'auth' => a_hash_including( - 'access_token' => access_token, - 'expires_in' => token_ttl, - 'refresh_token' => refresh_token, - 'scope' => scope_stub, - 'token_type' => 'Bearer', - 'id_token' => id_token, - 'created_at' => Time.zone.now, - 'type' => 'XOAUTH2', - 'client_id' => client_id, - 'client_secret' => client_secret, - ), - ) + expect(channel.options).to include( + 'inbound' => include( + 'options' => include( + 'auth_type' => 'XOAUTH2', + 'host' => 'outlook.office365.com', + 'ssl' => 'ssl', + 'user' => email_address, + ) + ), + 'outbound' => include( + 'options' => include( + 'authentication' => 'xoauth2', + 'host' => 'smtp.office365.com', + 'port' => 587, + 'user' => email_address, + ) + ), + 'auth' => include( + 'access_token' => access_token, + 'expires_in' => token_ttl, + 'refresh_token' => refresh_token, + 'scope' => scope_stub, + 'token_type' => 'Bearer', + 'id_token' => id_token, + 'created_at' => Time.zone.now, + 'type' => 'XOAUTH2', + 'client_id' => client_id, + 'client_secret' => client_secret, + ), ) end end @@ -231,7 +229,7 @@ RSpec.describe ExternalCredential::Microsoft365 do it 'refreshes token' do expect do channel.refresh_xoauth2! - end.to change { channel.options['auth'] }.to a_hash_including( + end.to change { channel.options['auth'] }.to include( 'created_at' => Time.zone.now, 'access_token' => refreshed_access_token, ) diff --git a/spec/lib/sequencer/sequence/import/freshdesk/ticket_field_spec.rb b/spec/lib/sequencer/sequence/import/freshdesk/ticket_field_spec.rb index 16a5f0c36..bd74d51c1 100644 --- a/spec/lib/sequencer/sequence/import/freshdesk/ticket_field_spec.rb +++ b/spec/lib/sequencer/sequence/import/freshdesk/ticket_field_spec.rb @@ -194,5 +194,37 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::TicketField, sequencer: expect { process(process_payload) }.to raise_error(RuntimeError, "The custom field type 'custom_unknown' cannot be mapped to an internal field, aborting.") end end + + context 'when importing default fields' do + let(:resource) do + base_resource.merge( + { + 'name' => 'ticket_type', + 'label' => 'Type', + 'type' => 'default_ticket_type', + 'default' => true, + 'choices' => [ + 'Question', + 'Incident', + 'Problem', + 'Feature Request', + 'Refunds and Returns', + 'Bulk orders', + 'Refund', + 'Request', + ] + } + ) + end + + it "activate the already existing ticket 'type' field" do + expect { process(process_payload) }.to change { ObjectManager::Attribute.get(object: 'Ticket', name: 'type').active }.from(false).to(true) + end + + it "import the fixed option list for the ticket 'type' field" do + process(process_payload) + expect(ObjectManager::Attribute.get(object: 'Ticket', name: 'type').data_option[:options]).to include(resource['choices'].to_h { |choice| [choice, choice] }) + end + end end end diff --git a/spec/lib/sequencer/sequence/import/freshdesk/ticket_spec.rb b/spec/lib/sequencer/sequence/import/freshdesk/ticket_spec.rb index abed040ef..77df2bc28 100644 --- a/spec/lib/sequencer/sequence/import/freshdesk/ticket_spec.rb +++ b/spec/lib/sequencer/sequence/import/freshdesk/ticket_spec.rb @@ -29,7 +29,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Ticket, sequencer: :seq 'to_emails' => ['info@zammad.org'], 'product_id' => nil, 'id' => 13, - 'type' => nil, + 'type' => 'Incident', 'due_by' => '2021-05-17T12:29:27Z', 'fr_due_by' => '2021-05-15T12:29:27Z', 'is_escalated' => false, @@ -116,6 +116,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Ticket, sequencer: :seq priority_id: 1, owner_id: owner.id, customer_id: User.last.id, + type: 'Incident', cf_custom_dropdown: 'key_2', cf_custom_integer: 999, cf_test_checkbox: true, @@ -207,5 +208,23 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Ticket, sequencer: :seq expect(Ticket.last.tag_list).to eq(%w[example test]) end end + + context 'when importing without a type' do + let(:resource) do + super().merge( + 'type' => nil + ) + end + let(:imported_ticket) do + super().merge( + type: nil + ) + end + + it 'correct attributes for added ticket' do + process(process_payload) + expect(Ticket.last).to have_attributes(imported_ticket) + end + end end end diff --git a/spec/lib/sequencer/sequence/import/kayako/case_field_spec.rb b/spec/lib/sequencer/sequence/import/kayako/case_field_spec.rb index 2419bda78..70143b197 100644 --- a/spec/lib/sequencer/sequence/import/kayako/case_field_spec.rb +++ b/spec/lib/sequencer/sequence/import/kayako/case_field_spec.rb @@ -47,7 +47,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Kayako::CaseField, sequencer: :seq it "import the fixed option list for the ticket 'type' field" do process(process_payload) - expect(ObjectManager::Attribute.get(object: 'Ticket', name: 'type').data_option[:options]).to a_hash_including(imported_type_options) + expect(ObjectManager::Attribute.get(object: 'Ticket', name: 'type').data_option[:options]).to include(imported_type_options) end end end diff --git a/spec/models/channel/filter/auto_response_check_spec.rb b/spec/models/channel/filter/auto_response_check_spec.rb index 62864b60e..dbfb84599 100644 --- a/spec/models/channel/filter/auto_response_check_spec.rb +++ b/spec/models/channel/filter/auto_response_check_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Channel::Filter::AutoResponseCheck, type: :channel_filter do it 'check filter result' do filter(mail) - expect(mail).to match(a_hash_including(mail_auto_response)) + expect(mail).to include(mail_auto_response) end end