current_user_spec.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. gql.read_files('shared/graphql/queries/currentUser.graphql', 'shared/graphql/fragments/objectAttributeValues.graphql')
  9. end
  10. before do
  11. gql.execute(query)
  12. end
  13. context 'with authenticated session', authenticated_as: :agent do
  14. it 'has data' do
  15. expect(gql.result.data).to include('fullname' => agent.fullname)
  16. end
  17. it 'has objectAttributeValue data for User' do
  18. oas = gql.result.data['objectAttributeValues']
  19. expect(oas.find { |oa| oa['attribute']['name'].eql?('department') }['value']).to eq('TestDepartment')
  20. end
  21. it 'has data for Organization' do
  22. expect(gql.result.data['organization']).to include('name' => organization.name)
  23. end
  24. it 'has permission data' do
  25. expect(gql.result.data['permissions']['names']).to eq(agent.permissions_with_child_names)
  26. end
  27. end
  28. it_behaves_like 'graphql responds with error if unauthenticated'
  29. end
  30. end