current_user_spec.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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(:secondary_orgs) { create_list(:organization, 2) }
  7. let(:agent) { create(:agent, department: 'TestDepartment', organization: organization, organizations: secondary_orgs) }
  8. let(:query) do
  9. <<~QUERY
  10. query currentUser {
  11. currentUser {
  12. id
  13. firstname
  14. lastname
  15. fullname
  16. objectAttributeValues {
  17. attribute {
  18. name
  19. }
  20. value
  21. }
  22. organization {
  23. name
  24. }
  25. secondaryOrganizations {
  26. edges {
  27. node {
  28. name
  29. }
  30. }
  31. }
  32. permissions {
  33. names
  34. }
  35. }
  36. }
  37. QUERY
  38. end
  39. before do
  40. gql.execute(query)
  41. end
  42. context 'with authenticated session', authenticated_as: :agent do
  43. it 'has data' do
  44. expect(gql.result.data).to include('fullname' => agent.fullname)
  45. end
  46. it 'has objectAttributeValue data for User' do
  47. oas = gql.result.data['objectAttributeValues']
  48. expect(oas.find { |oa| oa['attribute']['name'].eql?('department') }['value']).to eq('TestDepartment')
  49. end
  50. it 'has data for primary and secondary organizations', :aggregate_failures do
  51. expect(gql.result.data['organization']).to include('name' => organization.name)
  52. expect(gql.result.nodes('secondaryOrganizations')).to eq(secondary_orgs.map { |o| { 'name' => o.name } })
  53. end
  54. it 'has permission data' do
  55. expect(gql.result.data['permissions']['names']).to eq(agent.permissions_with_child_names)
  56. end
  57. end
  58. it_behaves_like 'graphql responds with error if unauthenticated'
  59. end
  60. end