Sha256: 338535ccfc21b2478aedcb9ea9237104a6d4c8eb65a171edcf26caed6f045009

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require_relative '../../spec_helper'

describe Commands::User::OmniAuthenticate do
  is_required :application_id, :omniauth_response
  is_optional :user_id

  User = Models::User
  Authentication = Models::Authentication

  let(:response) { subject.class.run(params) }

  before do
    @authentication = create(:authentication)
  end

  context 'existing user' do
    let(:params) { {
      application_id: @authentication.application_id,
      omniauth_response: @authentication.omniauth,
      user_id: @authentication.user_id
    } }

    context 'existing authentication' do
      it 'returns the existing user' do
        response.success?.should == true
        response.result.should == Serializers::User.resource(@authentication.user)
      end
    end

    context 'new authentication' do
      before do
        @authentication.uid += '_OLD'
        @authentication.save!
      end

      it 'returns the existing user' do
        response.success?.should == true
        response.result.should == Serializers::User.resource(@authentication.user)
        @authentication.user.authentications.length.should == 2
      end
    end
  end

  context 'new user' do
    let(:params) {
      @authentication.omniauth['uid'] += '_new'
      return {
        application_id: @authentication.application_id,
        omniauth_response: @authentication.omniauth
      }
    }

    context 'new authentication' do
      it 'created a new user and authentication' do
        @existing_user_count = User.count
        @existing_auth_count = Authentication.count

        response.success?.should == true

        User.count.should == @existing_user_count + 1
        Authentication.count.should == @existing_auth_count + 1

        new_user = response.result[:users].first
        new_user[:email].should == @authentication.omniauth['info']['email']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restpack_user_service-0.0.4 spec/commands/user/omni_authenticate_spec.rb