123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- require 'zendesk_api'
- RSpec.describe Sequencer::Sequence::Import::Zendesk::TicketField, sequencer: :sequence do
- context 'when trying to import ticket fields from Zendesk', db_strategy: :reset do
- let(:process_payload) do
- {
- import_job: build_stubbed(:import_job, name: 'Import::Zendesk', payload: {}),
- dry_run: false,
- resource: resource,
- field_map: {},
- }
- end
- let(:base_resource) do
- {
- 'id' => 24_656_189,
- 'raw_title' => 'Custom Decimal',
- 'description' => 'A custom Decimal field',
- 'raw_description' => 'A custom Decimal field',
- 'position' => 7,
- 'active' => true,
- 'required' => true,
- 'collapsed_for_agents' => false,
- 'regexp_for_validation' => '\\A[-+]?[0-9]*[.,]?[0-9]+\\z',
- 'title_in_portal' => 'Custom Decimal',
- 'raw_title_in_portal' => 'Custom Decimal',
- 'visible_in_portal' => true,
- 'editable_in_portal' => true,
- 'required_in_portal' => true,
- 'tag' => nil,
- 'created_at' => '2015-12-15 12:08:26 UTC',
- 'updated_at' => '2015-12-15 12:22:30 UTC',
- 'removable' => true,
- 'agent_description' => nil
- }
- end
- context 'when field is a decimal' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Custom Decimal',
- 'type' => 'decimal',
- }
- )
- )
- end
- it 'adds a custom field' do
- expect { process(process_payload) }.to change(Ticket, :column_names).by(['custom_decimal'])
- end
- end
- context 'when field is a checkbox' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Custom Checkbox',
- 'type' => 'checkbox',
- }
- )
- )
- end
- it 'adds a custom field' do
- expect { process(process_payload) }.to change(Ticket, :column_names).by(['custom_checkbox'])
- end
- end
- context 'when field is a date' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Custom Date',
- 'type' => 'date',
- }
- )
- )
- end
- it 'adds a custom field' do
- expect { process(process_payload) }.to change(Ticket, :column_names).by(['custom_date'])
- end
- end
- context 'when field is an integer' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Custom Integer',
- 'type' => 'integer',
- }
- )
- )
- end
- it 'adds a custom field' do
- expect { process(process_payload) }.to change(Ticket, :column_names).by(['custom_integer'])
- end
- end
- context 'when field is a regex' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Custom Regex',
- 'type' => 'regexp',
- }
- )
- )
- end
- it 'adds a custom field' do
- expect { process(process_payload) }.to change(Ticket, :column_names).by(['custom_regex'])
- end
- end
- context 'when field is a dropdown' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Custom Dropdown',
- 'type' => 'dropdown',
- 'custom_field_options' => [
- {
- 'id' => 28_353_445,
- 'name' => 'Another Value',
- 'raw_name' => 'Another Value',
- 'value' => 'anotherkey',
- 'default' => false
- },
- {
- 'id' => 28_353_425,
- 'name' => 'Value 1',
- 'raw_name' => 'Value 1',
- 'value' => 'key1',
- 'default' => false
- },
- {
- 'id' => 28_353_435,
- 'name' => 'Value 2',
- 'raw_name' => 'Value 2',
- 'value' => 'key2',
- 'default' => false
- }
- ]
- }
- )
- )
- end
- it 'adds a custom field' do
- expect { process(process_payload) }.to change(Ticket, :column_names).by(['custom_dropdown'])
- end
- end
- context 'when field is a multiselect' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Custom Multiselect',
- 'type' => 'multiselect',
- 'custom_field_options' => [
- {
- 'id' => 28_353_445,
- 'name' => 'Another Value',
- 'raw_name' => 'Another Value',
- 'value' => 'anotherkey',
- 'default' => false
- },
- {
- 'id' => 28_353_425,
- 'name' => 'Value 1',
- 'raw_name' => 'Value 1',
- 'value' => 'key1',
- 'default' => false
- },
- {
- 'id' => 28_353_435,
- 'name' => 'Value 2',
- 'raw_name' => 'Value 2',
- 'value' => 'key2',
- 'default' => false
- }
- ]
- }
- )
- )
- end
- it 'adds a custom field' do
- expect { process(process_payload) }.to change(Ticket, :column_names).by(['custom_multiselect'])
- end
- end
- context 'when field is the ticket type' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Type',
- 'type' => 'tickettype',
- 'system_field_options' => [
- {
- 'name' => 'Question',
- 'value' => 'question'
- },
- {
- 'name' => 'Incident',
- 'value' => 'incident'
- },
- {
- 'name' => 'Problem',
- 'value' => 'problem'
- },
- {
- 'name' => 'Task',
- 'value' => 'task'
- }
- ]
- }
- )
- )
- 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['system_field_options'].to_h { |choice| [choice['value'], choice['name']] })
- end
- end
- context 'when field is unknown' do
- let(:resource) do
- ZendeskAPI::TicketField.new(
- nil,
- base_resource.merge(
- {
- 'title' => 'Custom Unknown',
- 'type' => 'unknown',
- }
- )
- )
- end
- it 'does not add a custom field' do
- expect { process(process_payload) }.not_to change(Ticket, :column_names)
- end
- end
- end
- end
|