@@ -14,6 +14,9 @@ function OAuth2(clientId, clientSecret, baseSite, authorizeUrl, accessTokenUrl)
14
14
this . _accessTokenUrl = accessTokenUrl ;
15
15
}
16
16
17
+ // Add dummy method
18
+ OAuth2 . prototype . getOAuthAccessToken = new Function ( ) ;
19
+
17
20
// Makes it easy to invocate in the specs
18
21
var newOAuth2 = function ( accessTokenUrl ) {
19
22
return new OAuth2 ( null , null , null , null , accessTokenUrl ) ;
@@ -118,6 +121,29 @@ describe('Auth token refresh', function() {
118
121
119
122
expect ( fn ) . to . throw ( Error , 'Cannot register: not an OAuth2 strategy' ) ;
120
123
} ) ;
124
+
125
+ it ( 'should use the default getOAuthAccessToken function if not overwritten by strategy' , function ( ) {
126
+ var strategy = {
127
+ name : 'test_strategy' ,
128
+ _oauth2 : newOAuth2 ( 'accessTokenUrl' )
129
+ } ;
130
+
131
+ AuthTokenRefresh . use ( strategy ) ;
132
+ expect ( AuthTokenRefresh . _strategies . test_strategy . refreshOAuth2 . getOAuthAccessToken ) . to . equal ( OAuth2 . prototype . getOAuthAccessToken ) ;
133
+ } ) ;
134
+
135
+ it ( 'should use the overwritten getOAuthAccessToken function if overwritten by strategy' , function ( ) {
136
+ var strategy = {
137
+ name : 'test_strategy' ,
138
+ _oauth2 : newOAuth2 ( 'accessTokenUrl' )
139
+ } ;
140
+
141
+ strategy . _oauth2 . getOAuthAccessToken = new Function ( ) ;
142
+
143
+ AuthTokenRefresh . use ( strategy ) ;
144
+ expect ( AuthTokenRefresh . _strategies . test_strategy . refreshOAuth2 . getOAuthAccessToken ) . to . equal ( strategy . _oauth2 . getOAuthAccessToken ) ;
145
+ expect ( AuthTokenRefresh . _strategies . test_strategy . refreshOAuth2 . getOAuthAccessToken ) . not . equal ( OAuth2 . prototype . getOAuthAccessToken ) ;
146
+ } ) ;
121
147
} ) ;
122
148
123
149
describe ( 'has' , function ( ) {
0 commit comments