Sha256: 314fd902cdc492c4cc39eb106f19e219983295865d2e7750c835e38709b94ffd

Contents?: true

Size: 2 KB

Versions: 29

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true
# typed: false

describe WorkOS::Passwordless do
  it_behaves_like 'client'

  describe '.create_session' do
    context 'with valid options payload' do
      let(:valid_options) do
        {
          email: 'demo@workos-okta.com',
          type: 'MagicLink',
          redirect_uri: 'foo.com/auth/callback',
        }
      end

      it 'creates a session' do
        VCR.use_cassette('passwordless/create_session') do
          response = described_class.create_session(valid_options)

          expect(response.email).to eq 'demo@workos-okta.com'
        end
      end
    end

    context 'with invalid event payload' do
      let(:invalid_options) do
        {}
      end

      it 'raises an error' do
        VCR.use_cassette('passwordless/create_session_invalid') do
          expect do
            described_class.create_session(invalid_options)
          end.to raise_error(
            WorkOS::InvalidRequestError,
            /Status 422, Validation failed \(email: email must be a string; type: type must be a valid enum value\)/,
          )
        end
      end
    end
  end

  describe '.send_session' do
    context 'with valid session id' do
      let(:valid_options) do
        {
          email: 'demo@workos-okta.com',
          type: 'MagicLink',
        }
      end

      it 'send a session' do
        VCR.use_cassette('passwordless/send_session') do
          response = described_class.send_session(
            'passwordless_session_01EJC0F4KH42T11Y2DHPEB09BM',
          )

          expect(response['success']).to eq true
        end
      end
    end

    context 'with invalid session id' do
      it 'raises an error' do
        VCR.use_cassette('passwordless/send_session_invalid') do
          expect do
            described_class.send_session('session_123')
          end.to raise_error(
            WorkOS::InvalidRequestError,
            /Status 422, The passwordless session 'session_123' has expired or is invalid./,
          )
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
workos-4.1.0 spec/lib/workos/passwordless_spec.rb
workos-4.0.0 spec/lib/workos/passwordless_spec.rb
workos-3.1.0 spec/lib/workos/passwordless_spec.rb
workos-3.0.0 spec/lib/workos/passwordless_spec.rb
workos-2.17.0 spec/lib/workos/passwordless_spec.rb
workos-2.16.0 spec/lib/workos/passwordless_spec.rb
workos-2.15.0 spec/lib/workos/passwordless_spec.rb
workos-2.14.0 spec/lib/workos/passwordless_spec.rb
workos-2.13.0 spec/lib/workos/passwordless_spec.rb
workos-2.12.1 spec/lib/workos/passwordless_spec.rb
workos-2.12.0 spec/lib/workos/passwordless_spec.rb
workos-2.11.0 spec/lib/workos/passwordless_spec.rb
workos-2.10.0 spec/lib/workos/passwordless_spec.rb
workos-2.9.0 spec/lib/workos/passwordless_spec.rb
workos-2.8.0 spec/lib/workos/passwordless_spec.rb
workos-2.7.0 spec/lib/workos/passwordless_spec.rb
workos-2.6.0 spec/lib/workos/passwordless_spec.rb
workos-2.5.1 spec/lib/workos/passwordless_spec.rb
workos-2.5.0 spec/lib/workos/passwordless_spec.rb
workos-2.4.0 spec/lib/workos/passwordless_spec.rb