session_id_spec.rb 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::SessionId, type: :request do
  4. context 'when checking the SessionID' do
  5. let(:agent) { create(:agent) }
  6. let(:query) { File.read(Rails.root.join('app/frontend/common/graphql/queries/sessionId.graphql')) }
  7. let(:graphql_response) do
  8. post '/graphql', params: { query: query }, as: :json
  9. json_response
  10. end
  11. context 'with authenticated session', authenticated_as: :agent do
  12. it 'has data' do
  13. expect(graphql_response['data']['sessionId']).to be_present
  14. end
  15. end
  16. context 'without authenticated session', authenticated_as: false do
  17. it 'fails with error message' do
  18. expect(graphql_response['errors'][0]['message']).to eq('Authentication required by Gql::Queries::SessionId')
  19. end
  20. it 'fails with error type' do
  21. expect(graphql_response['errors'][0]['extensions']).to include({ 'type' => 'Exceptions::NotAuthorized' })
  22. end
  23. end
  24. end
  25. end