disabled
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ä483_‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ ã    ‹      µ”ßo›0€ßûWÜü°·pIÊ6©5L-DZÔ4‰R¦mš¦ÈÁXŒìKÓô¯”LÍ¦d?¤í	cÜÝwÆæ/âY”|š�à]r;�ùûëÉ8ÖCüp!ÆIÜ-ø^€8š2`9Q}�¸Ýn½í¹gl†És*Y�’'I²ðŒ·sáð\	Ù<�“¦B…ãJª0k@³!§¥êñQ”¥�(ê×ÖT¤*‰.VILMY'V…r¸qêFíVFX9ºW]o.—¤¹å’c¿Éˆû”|eä®­dð³6ÁŸäZ¸5CrÊá^:«F¦f!×eÎ¦C�šÊáªÕW/Ók¢ €}G³/‡”·_‡\@nÕ:`o£`z9®X8¥â(Ž3·3Ž 4R¯µ’'á»¾Ó�§Æ+—Z]“6Õ3Š�â¡jj
W‹ÆõUc�ÛCªCäïº!Òš1¿ZŒ¦I<^t-‘mˆçêþÍ²pÞpA¬­JÉØÝ^°Ëö²Z¹úòû+ìË·:Ë‰… =8Jþ…3©:tN>&Gm�Ôî¹Z¥9þbñÐæ§ò‡ýáë^ßïßÀ áû §@Ï¿9íù‡ îÏÇ§óÈ±»¾œ»(u|    E   ˆl–Ãa¾”ªi?u8 ¸Û71hß�þ]#N,ã�f1�­´R�ùÇ„d/¯Æ_�uÐb&=LyZËcõÅÄ ?÷     # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe 'Ticket Article API endpoints', type: :request do

  let(:admin) do
    create(:admin, groups: Group.all)
  end
  let!(:group) { create(:group) }

  let(:agent) do
    create(:agent, groups: Group.all)
  end
  let(:customer) do
    create(:customer)
  end

  describe 'request handling' do

    context 'when an agent adds articles to a ticket' do
      let(:ticket) { create(:ticket, group: Group.lookup(name: 'Users'), customer:) }

      before { authenticated_as(agent) }

      def create_article(**params)
        post '/api/v1/ticket_articles', params: { ticket_id: ticket.id, type: 'note' }.merge(params), as: :json
        expect(response).to have_http_status(:created)
        Ticket::Article.find(json_response['id'])
      end

      it 'creates a plain text note' do
        article = create_article(content_type: 'text/plain', body: 'some body')

        expect(article).to have_attributes(
          subject: nil, body: 'some body', content_type: 'text/plain',
          created_by_id: agent.id, updated_by_id: agent.id, attachments: be_empty
        )
      end

      it 'stores an inline image as an attachment', :aggregate_failures do
        article = create_article(content_type: 'text/html', body: 'some body <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />')

        expect(json_response['body']).to match(%r{some body <img src="/api/v1/ticket_attachment/.+?" alt="Red dot"})
        expect(article.attachments.sole).to have_attributes(
          filename:    'image1.png',
          size:        '21',
          preferences: include('Mime-Type' => 'image/png', 'Content-Disposition' => 'inline', 'Content-ID' => match(%r{@zammad.example.com}))
        )
      end

      it 'stores given attachments', :aggregate_failures do
        article = create_article(content_type: 'text/html', body: 'some body', attachments: [{ 'filename' => 'some_file.txt', 'data' => 'dGVzdCAxMjM=', 'mime-type' => 'text/plain' }])

        get "/api/v1/ticket_articles/#{article.id}?expand=true", params: {}, as: :json
        expect(json_response['attachments'].sole).to include(
          'id' => article.attachments.sole.id, 'filename' => 'some_file.txt', 'size' => '8', 'preferences' => include('Mime-Type' => 'text/plain')
        )
      end

      it 'stores given preferences' do
        article = create_article(content_type: 'text/plain', body: 'some body', internal: false, preferences: { some_key1: 123, highlight: '123' })

        expect(article.preferences).to include('some_key1' => 123, 'highlight' => '123')
      end

      it 'updates only the internal flag and the highlight on an existing article' do
        article = create_article(content_type: 'text/plain', body: 'some body', internal: false, preferences: { some_key1: 123, highlight: '123' })

        put "/api/v1/ticket_articles/#{article.id}", params: { body: 'some body 2', internal: true, preferences: { some_key2: 'abc', highlight: '234' } }, as: :json

        expect(article.reload).to have_attributes(
          body:        'some body',
          internal:    true,
          preferences: include('some_key1' => 123, 'highlight' => '234').and(not_include('some_key2'))
        )
      end
    end

    it 'does ticket create 