Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Oct 18, 2015
1 parent a372d18 commit e5a7c72
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 12 deletions.
60 changes: 55 additions & 5 deletions test/test_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def test_set_token

def test_authorize_url_default
rcsdk = RingCentralSdk::Sdk.new(
"my_app_key",
"my_app_secret",
'my_app_key',
'my_app_secret',
RingCentralSdk::Sdk::RC_SERVER_PRODUCTION,
{:redirect_uri => 'http://localhost:4567/oauth'}
)
Expand Down Expand Up @@ -80,7 +80,57 @@ def test_request
end
end

def test_get_oauth2_password_get_token
def test_authorize_code
rcsdk = new_rcsdk()
rcsdk.platform.set_oauth2_client()

stub_token_hash = data_auth_token
stub_token = OAuth2::AccessToken::from_hash(rcsdk.platform.oauth2client, stub_token_hash)

rcsdk.platform.oauth2client.auth_code.stubs(:get_token).returns(stub_token)

token = rcsdk.platform.authorize_code('my_test_auth_code')
assert_equal 'OAuth2::AccessToken', token.class.name
assert_equal 'OAuth2::AccessToken', rcsdk.platform.token.class.name

rcsdk = new_rcsdk({:redirect_uri => 'http://localhost:4567/oauth'})
rcsdk.platform.set_oauth2_client()

stub_token_hash = data_auth_token
stub_token = OAuth2::AccessToken::from_hash(rcsdk.platform.oauth2client, stub_token_hash)

rcsdk.platform.oauth2client.auth_code.stubs(:get_token).returns(stub_token)

token = rcsdk.platform.authorize_code('my_test_auth_code')
assert_equal 'OAuth2::AccessToken', token.class.name
assert_equal 'OAuth2::AccessToken', rcsdk.platform.token.class.name

rcsdk = new_rcsdk()
rcsdk.platform.set_oauth2_client()

stub_token_hash = data_auth_token
stub_token = OAuth2::AccessToken::from_hash(rcsdk.platform.oauth2client, stub_token_hash)

rcsdk.platform.oauth2client.auth_code.stubs(:get_token).returns(stub_token)

token = rcsdk.platform.authorize_code('my_test_auth_code')
assert_equal 'OAuth2::AccessToken', token.class.name
assert_equal 'OAuth2::AccessToken', rcsdk.platform.token.class.name

rcsdk = new_rcsdk()
rcsdk.platform.set_oauth2_client()

stub_token_hash = data_auth_token
stub_token = OAuth2::AccessToken::from_hash(rcsdk.platform.oauth2client, stub_token_hash)

rcsdk.platform.oauth2client.auth_code.stubs(:get_token).returns(stub_token)

token = rcsdk.platform.authorize_code('my_test_auth_code', {:redirect_uri => 'http://localhost:4567/oauth'})
assert_equal 'OAuth2::AccessToken', token.class.name
assert_equal 'OAuth2::AccessToken', rcsdk.platform.token.class.name
end

def test_authorize_password
rcsdk = new_rcsdk()
rcsdk.platform.set_oauth2_client()

Expand All @@ -96,8 +146,8 @@ def test_get_oauth2_password_get_token

def new_rcsdk(opts={})
return RingCentralSdk::Sdk.new(
"my_app_key",
"my_app_secret",
'my_app_key',
'my_app_secret',
RingCentralSdk::Sdk::RC_SERVER_PRODUCTION,
opts
)
Expand Down
43 changes: 36 additions & 7 deletions test/test_setup.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
require './test/test_helper.rb'

class RingCentralSdkTest < Test::Unit::TestCase
def testSetup
def setup

rcsdk = RingCentralSdk::Sdk.new(
"myAppKey",
"myAppSecret",
@rcsdk = RingCentralSdk::Sdk.new(
'my_app_key',
'my_app_secret',
RingCentralSdk::Sdk::RC_SERVER_SANDBOX
)

assert_equal "RingCentralSdk::Sdk", rcsdk.class.name
assert_equal "RingCentralSdk::Platform", rcsdk.platform.class.name
end

def test_main
assert_equal 'RingCentralSdk::Sdk', @rcsdk.class.name
assert_equal 'RingCentralSdk::Platform', @rcsdk.platform.class.name

assert_raise do
rcsdk.request(nil)
@rcsdk.request(nil)
end
end

def test_login
stub_token_hash = data_auth_token
stub_token = OAuth2::AccessToken::from_hash(@rcsdk.platform.oauth2client, stub_token_hash)

OAuth2::Strategy::Password.any_instance.stubs(:get_token).returns(stub_token)
rcsdk = RingCentralSdk::Sdk.new(
'my_app_key',
'my_app_secret',
RingCentralSdk::Sdk::RC_SERVER_SANDBOX,
{:username => 'my_username', :password => 'my_password'}
)
end

def data_auth_token
json = '{
"access_token": "my_test_access_token",
"token_type": "bearer",
"expires_in": 3599,
"refresh_token": "my_test_refresh_token",
"refresh_token_expires_in": 604799,
"scope": "ReadCallLog DirectRingOut EditCallLog ReadAccounts Contacts EditExtensions ReadContacts SMS EditPresence RingOut EditCustomData ReadPresence EditPaymentInfo Interoperability Accounts NumberLookup InternalMessages ReadCallRecording EditAccounts Faxes EditReportingSettings ReadClientInfo EditMessages VoipCalling ReadMessages",
"owner_id": "1234567890"
}'
data = JSON.parse(json, :symbolize_names=>true)
return data
end
end

0 comments on commit e5a7c72

Please sign in to comment.