spec/omniauth/strategies/linkedin_spec.rb in omniauth-linkedin-oauth2-0.2.5 vs spec/omniauth/strategies/linkedin_spec.rb in omniauth-linkedin-oauth2-1.0.0

- old
+ new

@@ -2,24 +2,24 @@ require 'omniauth-linkedin-oauth2' describe OmniAuth::Strategies::LinkedIn do subject { OmniAuth::Strategies::LinkedIn.new(nil) } - it 'should add a camelization for itself' do + it 'adds camelization for itself' do expect(OmniAuth::Utils.camelize('linkedin')).to eq('LinkedIn') end describe '#client' do it 'has correct LinkedIn site' do expect(subject.client.site).to eq('https://api.linkedin.com') end - it 'has correct authorize url' do + it 'has correct `authorize_url`' do expect(subject.client.options[:authorize_url]).to eq('https://www.linkedin.com/oauth/v2/authorization?response_type=code') end - it 'has correct token url' do + it 'has correct `token_url`' do expect(subject.client.options[:token_url]).to eq('https://www.linkedin.com/oauth/v2/accessToken') end end describe '#callback_path' do @@ -28,94 +28,85 @@ end end describe '#uid' do before :each do - allow(subject).to receive(:raw_info) { { 'id' => 'uid' } } + allow(subject).to receive(:raw_info) { Hash['id' => 'uid'] } end it 'returns the id from raw_info' do expect(subject.uid).to eq('uid') end end - describe '#info' do + describe '#info / #raw_info' do + let(:access_token) { instance_double OAuth2::AccessToken } + + let(:parsed_response) { Hash[:foo => 'bar'] } + + let(:profile_endpoint) { '/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))' } + let(:email_address_endpoint) { '/v2/emailAddress?q=members&projection=(elements*(handle~))' } + + let(:email_address_response) { instance_double OAuth2::Response, parsed: parsed_response } + let(:profile_response) { instance_double OAuth2::Response, parsed: parsed_response } + before :each do - allow(subject).to receive(:raw_info) { {} } + allow(subject).to receive(:access_token).and_return access_token + + allow(access_token).to receive(:get) + .with(email_address_endpoint) + .and_return(email_address_response) + + allow(access_token).to receive(:get) + .with(profile_endpoint) + .and_return(profile_response) end - context 'and therefore has all the necessary fields' do - it { expect(subject.info).to have_key :name } - it { expect(subject.info).to have_key :email } - it { expect(subject.info).to have_key :nickname } - it { expect(subject.info).to have_key :first_name } - it { expect(subject.info).to have_key :last_name } - it { expect(subject.info).to have_key :location } - it { expect(subject.info).to have_key :description } - it { expect(subject.info).to have_key :image } - it { expect(subject.info).to have_key :urls } + it 'returns parsed responses using access token' do + expect(subject.info).to have_key :email + expect(subject.info).to have_key :first_name + expect(subject.info).to have_key :last_name + expect(subject.info).to have_key :picture_url + + expect(subject.raw_info).to eq({ :foo => 'bar' }) end end describe '#extra' do + let(:raw_info) { Hash[:foo => 'bar'] } + before :each do - allow(subject).to receive(:raw_info) { { :foo => 'bar' } } + allow(subject).to receive(:raw_info).and_return raw_info end - it { expect(subject.extra['raw_info']).to eq({ :foo => 'bar' }) } + specify { expect(subject.extra['raw_info']).to eq raw_info } end describe '#access_token' do - before :each do - allow(subject).to receive(:oauth2_access_token) { double('oauth2 access token', :expires_in => 3600, :expires_at => 946688400).as_null_object } + let(:expires_in) { 3600 } + let(:expires_at) { 946688400 } + let(:token) { 'token' } + let(:access_token) do + instance_double OAuth2::AccessToken, :expires_in => expires_in, + :expires_at => expires_at, :token => token end - it { expect(subject.access_token.expires_in).to eq(3600) } - it { expect(subject.access_token.expires_at).to eq(946688400) } - end - - describe '#raw_info' do before :each do - access_token = double('access token') - response = double('response', :parsed => { :foo => 'bar' }) - expect(access_token).to receive(:get).with("/v1/people/~:(baz,qux)?format=json").and_return(response) - - allow(subject).to receive(:option_fields) { ['baz', 'qux'] } - allow(subject).to receive(:access_token) { access_token } + allow(subject).to receive(:oauth2_access_token).and_return access_token end - it 'returns parsed response from access token' do - expect(subject.raw_info).to eq({ :foo => 'bar' }) - end + specify { expect(subject.access_token.expires_in).to eq expires_in } + specify { expect(subject.access_token.expires_at).to eq expires_at } end describe '#authorize_params' do describe 'scope' do before :each do - subject.stub(:session => {}) + allow(subject).to receive(:session).and_return({}) end it 'sets default scope' do - expect(subject.authorize_params['scope']).to eq('r_basicprofile r_emailaddress') + expect(subject.authorize_params['scope']).to eq('r_liteprofile r_emailaddress') end - end - end - - describe '#option_fields' do - it 'returns options fields' do - subject.stub(:options => double('options', :fields => ['foo', 'bar']).as_null_object) - expect(subject.send(:option_fields)).to eq(['foo', 'bar']) - end - - it 'http avatar image by default' do - subject.stub(:options => double('options', :fields => ['picture-url'])) - allow(subject.options).to receive(:[]).with(:secure_image_url).and_return(false) - expect(subject.send(:option_fields)).to eq(['picture-url']) - end - - it 'https avatar image if secure_image_url truthy' do - subject.stub(:options => double('options', :fields => ['picture-url'])) - allow(subject.options).to receive(:[]).with(:secure_image_url).and_return(true) - expect(subject.send(:option_fields)).to eq(['picture-url;secure=true']) end end end