add_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Form::UploadCache::Add, type: :graphql do
  4. context 'when uploading files for a form', authenticated_as: :agent do
  5. let(:agent) { create(:agent) }
  6. let(:query) { read_graphql_file('shared/components/Form/fields/FieldFile/graphql/mutations/uploadCache/add.graphql') }
  7. let(:form_id) { 12_345 }
  8. let(:file_name) { 'my_testfile.pdf' }
  9. let(:file_type) { 'application/pdf' }
  10. let(:file_content) { 'some test content' }
  11. let(:variables) do
  12. {
  13. formId: form_id,
  14. files: [
  15. {
  16. name: file_name,
  17. type: file_type,
  18. content: Base64.strict_encode64(file_content),
  19. }
  20. ]
  21. }
  22. end
  23. let(:expected_response) do
  24. [{
  25. 'id' => Gql::ZammadSchema.id_from_object(UploadCache.new(form_id).attachments.first),
  26. 'name' => file_name,
  27. 'type' => file_type,
  28. }]
  29. end
  30. before do
  31. graphql_execute(query, variables: variables)
  32. end
  33. it 'creates Store entry' do
  34. expect(graphql_response['data']['formUploadCacheAdd']['uploadedFiles']).to eq(expected_response)
  35. end
  36. it_behaves_like 'graphql responds with error if unauthenticated'
  37. end
  38. end