active_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::User::Current::Avatar::Active, type: :graphql do
  4. context 'when fetching avatar' do
  5. let(:query) do
  6. <<~QUERY
  7. query userCurrentAvatarActive {
  8. userCurrentAvatarActive {
  9. id
  10. }
  11. }
  12. QUERY
  13. end
  14. context 'when authorized', authenticated_as: :agent do
  15. let(:agent) { create(:agent) }
  16. let!(:avatar) { nil }
  17. before do
  18. gql.execute(query)
  19. end
  20. context 'when no avatar is available' do
  21. it 'returns nil' do
  22. expect(gql.result.data).to be_nil
  23. end
  24. end
  25. context 'when avatar is available' do
  26. let(:base64_img) { Base64.decode64('iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==') }
  27. let!(:avatar) do
  28. avatar = Avatar.add(
  29. object: 'User',
  30. o_id: agent.id,
  31. full: {
  32. content: base64_img,
  33. mime_type: 'image/png',
  34. },
  35. resize: {
  36. content: base64_img,
  37. mime_type: 'image/png',
  38. },
  39. source: "upload #{Time.zone.now}",
  40. deletable: true,
  41. created_by_id: agent.id,
  42. updated_by_id: agent.id,
  43. )
  44. agent.update!(image: avatar.store_hash)
  45. avatar
  46. end
  47. it 'returns data' do
  48. expect(gql.result.data['id']).to eq(gql.id(avatar))
  49. end
  50. end
  51. end
  52. context 'when unauthenticated' do
  53. before do
  54. gql.execute(query)
  55. end
  56. it_behaves_like 'graphql responds with error if unauthenticated'
  57. end
  58. end
  59. end