select_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::Avatar::Select, type: :graphql do
  4. context 'when selecting an avatar for the logged-in user', authenticated_as: :agent do
  5. let(:agent) { create(:agent) }
  6. let(:variables) { { id: gql.id(avatar) } }
  7. let(:execute_query) { true }
  8. let(:avatar) { create(:avatar, o_id: agent.id) }
  9. let(:query) do
  10. <<~QUERY
  11. mutation userCurrentAvatarSelect($id: ID!) {
  12. userCurrentAvatarSelect(id: $id) {
  13. success
  14. errors {
  15. message
  16. field
  17. }
  18. }
  19. }
  20. QUERY
  21. end
  22. before do
  23. next if !execute_query
  24. gql.execute(query, variables: variables)
  25. end
  26. it 'returns success' do
  27. expect(gql.result.data['success']).to be true
  28. end
  29. context 'when trying to use an avatar of another user' do
  30. let(:avatar) { create(:avatar, o_id: 1) }
  31. it 'fails with error message' do
  32. expect(gql.result.error_message).to eq('Avatar could not be found.')
  33. end
  34. end
  35. context 'with not existing avatar' do
  36. let(:variables) { { id: 123_456_789 } }
  37. it 'fails with error message' do
  38. expect(gql.result.error_message).to eq("Could not find Avatar #{variables[:id]}")
  39. end
  40. it 'fails with error type' do
  41. expect(gql.result.error_type).to eq(ActiveRecord::RecordNotFound)
  42. end
  43. end
  44. it_behaves_like 'graphql responds with error if unauthenticated'
  45. end
  46. end