# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ require 'rails_helper' require 'lib/sequencer/sequence/import/kayako/examples/object_custom_field_values_examples' RSpec.describe ::Sequencer::Sequence::Import::Kayako::Case, sequencer: :sequence, db_strategy: :reset do context 'when importing cases from Kayako' do let(:group) { create :group } let(:owner) { create :agent, group_ids: [group.id] } let(:organization) { create :organization } let(:customer) { create :customer, organization: organization } let(:resource) do { 'id' => 9999, 'legacy_id' => nil, 'subject' => 'Getting comfortable with Kayako: a sample conversation', 'portal' => 'SETUP', 'source_channel' => { 'uuid' => 'e955e374-8324-4637-97a5-763cd4010997', 'type' => 'MAIL', 'character_limit' => nil, 'resource_type' => 'channel' }, 'requester' => { 'id' => 80_014_400_777, 'organization' => { 'id' => 80_014_400_111, 'resource_type' => 'organization' }, 'resource_type' => 'user', }, 'creator' => { 'id' => 80_014_400_777, 'resource_type' => 'user', }, 'identity' => { 'id' => 80_014_400_777, 'resource_type' => 'identity_email' }, 'assigned_agent' => { 'id' => 80_014_400_475, 'resource_type' => 'user', }, 'assigned_team' => { 'id' => 80_000_374_718, 'resource_type' => 'team' }, 'status' => { 'id' => 2, 'label' => 'Open', 'type' => 'OPEN', 'sort_order' => 2, 'is_sla_active' => true, 'is_deleted' => false, 'created_at' => '2021-08-12T11:48:51+00:00', 'updated_at' => '2021-08-12T11:48:51+00:00', 'resource_type' => 'case_status', }, 'priority' => { 'id' => 1, 'label' => 'Low', 'level' => 1, 'created_at' => '2021-08-12T11:48:51+00:00', 'updated_at' => '2021-08-12T11:48:51+00:00', 'resource_type' => 'case_priority', }, 'type' => { 'id' => 1, 'label' => 'Question', 'type' => 'QUESTION', 'created_at' => '2021-08-12T11:48:51+00:00', 'updated_at' => '2021-08-12T11:48:51+00:00', }, 'last_updated_by' => { 'id' => 80_000_374_718, 'resource_type' => 'user', }, 'state' => 'ACTIVE', 'tags' => [ { 'id' => 1, 'name' => 'example', 'resource_type' => 'tag' }, { 'id' => 2, 'name' => 'test', 'resource_type' => 'tag' } ], 'created_at' => '2018-08-18T12:00:00+00:00', 'updated_at' => '2021-08-24T06:30:00+00:00', 'resource_type' => 'case', } end let(:id_map) do { 'Organization' => { 80_014_400_111 => organization.id, }, 'User' => { 80_014_400_475 => owner.id, 80_014_400_777 => customer.id, }, 'Group' => { 80_000_374_718 => group.id, }, } end let(:process_payload) do { import_job: build_stubbed(:import_job, name: 'Import::Kayako', payload: {}), dry_run: false, resource: resource, field_map: {}, id_map: id_map, default_language: 'en-us', } end let(:posts_response_payload) do { 'data' => [ { 'id' => 99_999, 'uuid' => '179a033a-7582-4def-ae57-b8f077eaee5b', 'client_id' => '', 'subject' => 'Getting comfortable with Kayako: a sample conversation', 'contents' => 'Some text conent\n', 'creator' => { 'id' => 80_014_400_777, 'resource_type' => 'user' }, 'identity' => { 'id' => 80_014_400_777, 'email' => customer.email, 'resource_type' => 'identity_email', }, 'source_channel' => { 'uuid' => 'e955e374-8324-4637-97a5-763cd4010997', 'type' => 'MAIL', 'character_limit' => nil, 'account' => { 'id' => 1, 'resource_type' => 'mailbox' }, 'resource_type' => 'channel' }, 'attachments' => [], 'original' => { 'id' => 4, 'uuid' => '179a033a-7582-4def-ae57-b8f077eaee5b', 'subject' => 'Getting comfortable with Kayako: a sample conversation', 'body_text' => 'Some text conent\n', 'body_html' => '