current_user_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::CurrentUser, type: :graphql do
  4. context 'when fetching user information' do
  5. let(:organization) { create(:organization) }
  6. let(:agent) { create(:agent, department: 'TestDepartment', organization: organization) }
  7. let(:query) do
  8. <<~QUERY
  9. query currentUser {
  10. currentUser {
  11. id
  12. firstname
  13. lastname
  14. fullname
  15. objectAttributeValues {
  16. attribute {
  17. name
  18. }
  19. value
  20. }
  21. organization {
  22. name
  23. }
  24. permissions {
  25. names
  26. }
  27. }
  28. }
  29. QUERY
  30. end
  31. before do
  32. gql.execute(query)
  33. end
  34. context 'with authenticated session', authenticated_as: :agent do
  35. it 'has data' do
  36. expect(gql.result.data).to include('fullname' => agent.fullname)
  37. end
  38. it 'has objectAttributeValue data for User' do
  39. oas = gql.result.data['objectAttributeValues']
  40. expect(oas.find { |oa| oa['attribute']['name'].eql?('department') }['value']).to eq('TestDepartment')
  41. end
  42. it 'has data for Organization' do
  43. expect(gql.result.data['organization']).to include('name' => organization.name)
  44. end
  45. it 'has permission data' do
  46. expect(gql.result.data['permissions']['names']).to eq(agent.permissions_with_child_names)
  47. end
  48. end
  49. it_behaves_like 'graphql responds with error if unauthenticated'
  50. end
  51. end