usb-0000:07:00.0-1/input0
  6   ˆl–Ðz¾”ªC]Šq@=q¦®41hß�þDéq°9 €&]}–ŸÌ636ËÊÀÈ |    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

module ApplicationController::HasResponseExtentions
  extend ActiveSupport::Concern

  private

  def response_expand?
    ActiveModel::Type::Boolean.new.cast params[:expand]
  end

  def response_full?
    ActiveModel::Type::Boolean.new.cast params[:full]
  end

  def response_all?
    ActiveModel::Type::Boolean.new.cast params[:all]
  end

  def response_only_total_count?
    ActiveModel::Type::Boolean.new.cast params[:only_total_count]
  end

  def response_with_total_count?
    ActiveModel::Type::Boolean.new.cast params[:with_total_count]
  end
end
  7   ˆl–ßi~” T¾R( 	ÅÝÁ
ãn©‹Fÿ‘äÇò 8à_h/”@–0ÿ?Íƒh¹ÌÁÉ      0
      ˆ¾‘äÇò 8à_h/”@–0ÿ?Íƒh¹ÌÁÉ      0
     ˆÀ�þB gÁi·žóÍƒh¹ÌÁÉ      isa0060/serio0/input0
  6   ˆl–Ãa¾”*i?u8 …p/Üiå1hß�þBÈH³Ž RÈËÎ�'óÎƒiçÅÍÌÂÊ     # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

# Behavior is covered by spec/services/service/upload_cache/add_spec.rb.
RSpec.describe Gql::Mutations::Form::UploadCache::Add, type: :graphql do

  context 'when uploading files for a form', authenticated_as: :agent do
    let(:agent) { create(:agent) }
    let(:query) do
      <<~QUERY
        mutation formUploadCacheAdd($formId: FormId!, $files: [UploadCacheFileInput!]!) {
          formUploadCacheAdd(formId: $formId, files: $files) {
            uploadedFiles {
              id
              name
              type
            }
          }
        }
      QUERY
    end
    let(:form_id)      { SecureRandom.uuid }
    let(:file_name)    { 'my_testfile.pdf' }
    let(:file_type)    { 'application/pdf' }
    let(:file_content) { 'some test content' }
    let(:variables) do
      {
        formId: form_id,
        files:  [
          {
            name:    file_name,
            type:    file_type,
            content: Base64.strict_encode64(file_content),
          }
        ]
      }
    end

    let(:expected_response) do
      [{
        'id'   => gql.id(UploadCache.new(form_id).attachments.first),
        'name' => file_name,
        'type' => file_type,
      }]
    end

    before do
      gql.execute(query, variables: variables)
    end

    it 'creates Store entry' do
      expect(gql.result.data[:uploadedFiles]).to eq(expected_response)
    end

    it_behaves_like 'graphql responds with error if unauthenticated'
  end

  context 'when adding to another users populated cache', authenticated_as: :agent do
    let(:agent)         { create(:agent) }
    let(:other_agent)   { create(:agent) }
    let(:form_id)       { SecureRandom.uuid }
    let(:file_name)     { 'intruder.txt' }
    let(:file_type)     { 'text/plain' }
    let(:file_content)  { 'Intruder content' }
    let(:query) do
      <<~QUERY
        mutation formUploadCacheAdd($formId: FormId!, $files: [UploadCacheFileInput!]!) {
          formUploadCacheAdd(formId: $formId, files: $files) {
            uploadedFiles {
              id
              name
              type
            }
          }
        }
      QUERY
    end
    let(:variables) do
      {
        formId: form_id,
        files:  [{
          name:    file_name,
          type:    file_type,
          content: Base64.strict_encode64(file_content),
        }]
      }
    end

    before do
      UploadCache.new(form_id).add(
        filename:      'other_agent.txt',
        data:          'Other agent data',
        preferences:   { 'Content-Type' => 'text/plain' },
        created_by_id: other_agent.id,
      )
      gql.execute(query, variables: variables)
    end

    it 'forbids adding to another users cache' do
      expect(gql.result.error_type).to eq(Exceptions::Forbidden)
    end
  end

  context 'when copying an attachment', authenticated_as: :agent do
    let(:agent)      { create(:agent, groups: [article.ticket.group]) }
    let(:article)    { create(:ticket_article, :inbound_email) }
    let(:a