|
4 | 4 | describe OmniAuth::Strategies::LinkedIn do
|
5 | 5 | subject { OmniAuth::Strategies::LinkedIn.new(nil) }
|
6 | 6 |
|
7 |
| - it 'should add a camelization for itself' do |
| 7 | + it 'adds camelization for itself' do |
8 | 8 | expect(OmniAuth::Utils.camelize('linkedin')).to eq('LinkedIn')
|
9 | 9 | end
|
10 | 10 |
|
|
13 | 13 | expect(subject.client.site).to eq('https://api.linkedin.com')
|
14 | 14 | end
|
15 | 15 |
|
16 |
| - it 'has correct authorize url' do |
| 16 | + it 'has correct `authorize_url`' do |
17 | 17 | expect(subject.client.options[:authorize_url]).to eq('https://www.linkedin.com/oauth/v2/authorization?response_type=code')
|
18 | 18 | end
|
19 | 19 |
|
20 |
| - it 'has correct token url' do |
| 20 | + it 'has correct `token_url`' do |
21 | 21 | expect(subject.client.options[:token_url]).to eq('https://www.linkedin.com/oauth/v2/accessToken')
|
22 | 22 | end
|
23 | 23 | end
|
|
30 | 30 |
|
31 | 31 | describe '#uid' do
|
32 | 32 | before :each do
|
33 |
| - allow(subject).to receive(:raw_info) { { 'id' => 'uid' } } |
| 33 | + allow(subject).to receive(:raw_info) { Hash['id' => 'uid'] } |
34 | 34 | end
|
35 | 35 |
|
36 | 36 | it 'returns the id from raw_info' do
|
|
44 | 44 | end
|
45 | 45 |
|
46 | 46 | context 'and therefore has all the necessary fields' do
|
47 |
| - it { expect(subject.info).to have_key :name } |
48 |
| - it { expect(subject.info).to have_key :email } |
49 |
| - it { expect(subject.info).to have_key :nickname } |
50 |
| - it { expect(subject.info).to have_key :first_name } |
51 |
| - it { expect(subject.info).to have_key :last_name } |
52 |
| - it { expect(subject.info).to have_key :location } |
53 |
| - it { expect(subject.info).to have_key :description } |
54 |
| - it { expect(subject.info).to have_key :image } |
55 |
| - it { expect(subject.info).to have_key :urls } |
| 47 | + specify { expect(subject.info).to have_key :email } |
| 48 | + specify { expect(subject.info).to have_key :first_name } |
| 49 | + specify { expect(subject.info).to have_key :last_name } |
| 50 | + specify { expect(subject.info).to have_key :picture_url } |
56 | 51 | end
|
57 | 52 | end
|
58 | 53 |
|
59 | 54 | describe '#extra' do
|
| 55 | + let(:raw_info) { Hash[:foo => 'bar'] } |
| 56 | + |
60 | 57 | before :each do
|
61 |
| - allow(subject).to receive(:raw_info) { { :foo => 'bar' } } |
| 58 | + allow(subject).to receive(:raw_info).and_return raw_info |
62 | 59 | end
|
63 | 60 |
|
64 |
| - it { expect(subject.extra['raw_info']).to eq({ :foo => 'bar' }) } |
| 61 | + specify { expect(subject.extra['raw_info']).to eq raw_info } |
65 | 62 | end
|
66 | 63 |
|
67 | 64 | describe '#access_token' do
|
| 65 | + let(:expires_in) { 3600 } |
| 66 | + let(:expires_at) { 946688400 } |
| 67 | + let(:token) { 'token' } |
| 68 | + let(:access_token) do |
| 69 | + instance_double OAuth2::AccessToken, :expires_in => expires_in, |
| 70 | + :expires_at => expires_at, :token => token |
| 71 | + end |
| 72 | + |
68 | 73 | before :each do
|
69 |
| - allow(subject).to receive(:oauth2_access_token) { double('oauth2 access token', :expires_in => 3600, :expires_at => 946688400).as_null_object } |
| 74 | + allow(subject).to receive(:oauth2_access_token).and_return access_token |
70 | 75 | end
|
71 | 76 |
|
72 |
| - it { expect(subject.access_token.expires_in).to eq(3600) } |
73 |
| - it { expect(subject.access_token.expires_at).to eq(946688400) } |
| 77 | + specify { expect(subject.access_token.expires_in).to eq expires_in } |
| 78 | + specify { expect(subject.access_token.expires_at).to eq expires_at } |
74 | 79 | end
|
75 | 80 |
|
76 | 81 | describe '#raw_info' do
|
| 82 | + let(:access_token) { instance_double OAuth2::AccessToken } |
| 83 | + let(:parsed_response) { Hash[:foo => 'bar'] } |
| 84 | + let(:response) { instance_double OAuth2::Response, parsed: parsed_response } |
| 85 | + let(:profile_endpoint) { '/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))' } |
| 86 | + |
77 | 87 | before :each do
|
78 |
| - access_token = double('access token') |
79 |
| - response = double('response', :parsed => { :foo => 'bar' }) |
| 88 | + allow(subject).to receive(:access_token).and_return access_token |
| 89 | + |
80 | 90 | expect(access_token).to receive(:get)
|
81 |
| - .with("/v1/people/~:(id,email-address,first-name,last-name,headline,location,industry,picture-url,public-profile-url)?format=json") |
| 91 | + .with(profile_endpoint) |
82 | 92 | .and_return(response)
|
83 |
| - |
84 |
| - allow(subject).to receive(:access_token) { access_token } |
85 | 93 | end
|
86 | 94 |
|
87 |
| - it 'returns parsed response from access token' do |
| 95 | + it 'returns parsed response from the access token' do |
88 | 96 | expect(subject.raw_info).to eq({ :foo => 'bar' })
|
89 | 97 | end
|
90 | 98 | end
|
|
96 | 104 | end
|
97 | 105 |
|
98 | 106 | it 'sets default scope' do
|
99 |
| - expect(subject.authorize_params['scope']).to eq('r_basicprofile r_emailaddress') |
| 107 | + expect(subject.authorize_params['scope']).to eq('r_liteprofile r_emailaddress') |
100 | 108 | end
|
101 | 109 | end
|
102 | 110 | end
|
|
0 commit comments