add_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2024 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) do
  7. <<~QUERY
  8. mutation formUploadCacheAdd($formId: FormId!, $files: [UploadFileInput!]!) {
  9. formUploadCacheAdd(formId: $formId, files: $files) {
  10. uploadedFiles {
  11. id
  12. name
  13. type
  14. }
  15. }
  16. }
  17. QUERY
  18. end
  19. let(:form_id) { SecureRandom.uuid }
  20. let(:file_name) { 'my_testfile.pdf' }
  21. let(:file_type) { 'application/pdf' }
  22. let(:file_content) { 'some test content' }
  23. let(:variables) do
  24. {
  25. formId: form_id,
  26. files: [
  27. {
  28. name: file_name,
  29. type: file_type,
  30. content: Base64.strict_encode64(file_content),
  31. }
  32. ]
  33. }
  34. end
  35. let(:expected_response) do
  36. [{
  37. 'id' => gql.id(UploadCache.new(form_id).attachments.first),
  38. 'name' => file_name,
  39. 'type' => file_type,
  40. }]
  41. end
  42. before do
  43. gql.execute(query, variables: variables)
  44. end
  45. it 'creates Store entry' do
  46. expect(gql.result.data['uploadedFiles']).to eq(expected_response)
  47. end
  48. it_behaves_like 'graphql responds with error if unauthenticated'
  49. end
  50. end