Sha256: 82aae79642719ff48ff2e0727cbac6c530d01bb322e1bdadfdf13bd5071ce1c7

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require_relative '../../spec_helper'

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

  UserSerializer = RestPack::User::Service::Serializers::UserSerializer
  User = RestPack::User::Service::Models::User
  Authentication = RestPack::User::Service::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 == UserSerializer.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 == UserSerializer.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.3 spec/commands/user/omni_authenticate_spec.rb