session_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::Session, type: :graphql do
  4. context 'when checking the Session' do
  5. let(:agent) { create(:agent) }
  6. let(:query) do
  7. <<~QUERY
  8. query session {
  9. session {
  10. id
  11. afterAuth {
  12. type
  13. data
  14. }
  15. }
  16. }
  17. QUERY
  18. end
  19. before do
  20. allow_any_instance_of(Auth::AfterAuth::TwoFactorConfiguration).to receive(:check).and_return(true)
  21. gql.execute(query, context: { controller: instance_double(GraphqlController, session: { authentication_type: 'password' }) })
  22. end
  23. context 'with authenticated session', authenticated_as: :agent do
  24. it 'returns session id' do
  25. expect(gql.result.data['id']).to be_present
  26. end
  27. it 'returns after_auth data' do
  28. expect(gql.result.data['afterAuth']).to eq({ 'type' => 'TwoFactorConfiguration', 'data' => {} })
  29. end
  30. end
  31. it_behaves_like 'graphql responds with error if unauthenticated'
  32. end
  33. end