# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ require 'rails_helper' require 'zendesk_api' RSpec.describe Sequencer::Sequence::Import::Zendesk::Ticket::Comment, db_strategy: :reset, required_envs: %w[IMPORT_ZENDESK_ENDPOINT], sequencer: :sequence do let(:hostname) { URI.parse(ENV['IMPORT_ZENDESK_ENDPOINT']).hostname } context 'when importing ticket comments from Zendesk' do let(:customer) { create(:customer) } let(:ticket) { create(:ticket) } let(:inline_image_url) { "https://#{hostname}/attachments/token/khRQTQjm8ODhA0FjbS39i4xOb/?name=1a3496b9-53d9-494d-bbb0-e1d2e22074f8.jpeg" } let(:resource) do ZendeskAPI::Ticket::Comment.new( nil, { 'id' => 31_964_468_581, 'type' => 'Comment', 'author_id' => 1_150_734_731, 'html_body' => "
\n", created_at: Time.zone.parse('2018-09-28T12:00:00Z'), updated_at: Time.zone.parse('2018-09-28T12:00:00Z'), } end before do stub_request(:get, "https://#{hostname}/attachments/token/khRQTQjm8ODhA0FjbS39i4xOb/?name=1a3496b9-53d9-494d-bbb0-e1d2e22074f8.jpeg").to_return(status: 200, body: '123', headers: {}) end context 'with an email article' do it 'imports article correctly' do expect { process(process_payload) }.to change(Ticket::Article, :count).by(1) end it 'imports ticket data correctly' do process(process_payload) attachment_list = Store.list( object: 'Ticket::Article', o_id: Ticket::Article.last.id, ) expect(Ticket::Article.last).to have_attributes(imported_article(attachment_list.first[:preferences]['Content-ID'])) end it 'adds correct number of attachments' do process(process_payload) expect(Ticket::Article.last.attachments.size).to eq 2 end it 'adds attachment content' do process(process_payload) expect(Ticket::Article.last.attachments.last).to have_attributes(imported_attachment) end end context 'when attachment request has an error' do before do allow_any_instance_of(Sequencer::Unit::Import::Zendesk::Ticket::Comment::Attachment::Request).to receive(:sleep) stub_request(:get, "https://#{hostname}/attachments/token/khRQTQjm8ODhA0FjbS39i4xOb/?name=1a3496b9-53d9-494d-bbb0-e1d2e22074f8.jpeg").to_return(status: 503, headers: {}).then.to_return(status: 200, body: '123', headers: {}) end it 'adds attachment content after one request error' do process(process_payload) expect(Ticket::Article.last.attachments.last).to have_attributes(imported_attachment) end end end end
This is the latest comment for this ticket. You also changed the ticket status to Pending.