diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-10-05 18:17:21 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-10-05 18:17:21 +0900 |
commit | 31c89258821b680da18fc02439b1be4471846571 (patch) | |
tree | e52e22c8e7ae9848c00d3bef201e9de1a560f304 /spec/lib/google_api/auth_spec.rb | |
parent | 6b07aa5ec863706e58f781ee77ad54b54702c88a (diff) | |
download | gitlab-ce-31c89258821b680da18fc02439b1be4471846571.tar.gz |
spec/lib/google_api/auth_spec. spec/lib/google_api/cloud_platform/client_spec
Diffstat (limited to 'spec/lib/google_api/auth_spec.rb')
-rw-r--r-- | spec/lib/google_api/auth_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/lib/google_api/auth_spec.rb b/spec/lib/google_api/auth_spec.rb new file mode 100644 index 00000000000..87a3f43274f --- /dev/null +++ b/spec/lib/google_api/auth_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe GoogleApi::Auth do + let(:redirect_uri) { 'http://localhost:3000/google_api/authorizations/callback' } + let(:redirect_to) { 'http://localhost:3000/namaspace/project/clusters' } + + let(:client) do + GoogleApi::CloudPlatform::Client + .new(nil, redirect_uri, state: redirect_to) + end + + describe '#authorize_url' do + subject { client.authorize_url } + + it 'returns authorize_url' do + is_expected.to start_with('https://accounts.google.com/o/oauth2') + is_expected.to include(URI.encode(redirect_uri, URI::PATTERN::RESERVED)) + is_expected.to include(URI.encode(redirect_to, URI::PATTERN::RESERVED)) + end + end + + describe '#get_token' do + let(:token) do + double.tap do |dbl| + allow(dbl).to receive(:token).and_return('token') + allow(dbl).to receive(:expires_at).and_return('expires_at') + end + end + + before do + allow_any_instance_of(OAuth2::Strategy::AuthCode) + .to receive(:get_token).and_return(token) + end + + it 'returns token and expires_at' do + token, expires_at = client.get_token('xxx') + expect(token).to eq('token') + expect(expires_at).to eq('expires_at') + end + end +end |