@@ -18,6 +18,17 @@ RequestWrapper.mockImplementation(() => {
18
18
} ;
19
19
} ) ;
20
20
21
+ const ACCESS_TOKEN = '9012' ;
22
+ const IAM_RESPONSE = {
23
+ result : {
24
+ access_token : ACCESS_TOKEN ,
25
+ refresh_token : '3456' ,
26
+ token_type : 'Bearer' ,
27
+ expires_in : 3600 ,
28
+ expiration : Math . floor ( Date . now ( ) / 1000 ) + 3600 ,
29
+ } ,
30
+ } ;
31
+
21
32
const CLIENT_ID_SECRET_WARNING =
22
33
'Warning: Client ID and Secret must BOTH be given, or the header will not be included.' ;
23
34
@@ -37,21 +48,12 @@ describe('iam_token_manager_v1', function() {
37
48
it ( 'should turn an iam apikey into an access token' , function ( done ) {
38
49
const instance = new IamTokenManager ( { apikey : 'abcd-1234' } ) ;
39
50
40
- const accessToken = '9012' ;
41
- const iamResponse = {
42
- access_token : accessToken ,
43
- refresh_token : '3456' ,
44
- token_type : 'Bearer' ,
45
- expires_in : 3600 ,
46
- expiration : Math . floor ( Date . now ( ) / 1000 ) + 3600 ,
47
- } ;
48
-
49
51
mockSendRequest . mockImplementation ( ( parameters , _callback ) => {
50
- _callback ( null , iamResponse ) ;
52
+ _callback ( null , IAM_RESPONSE ) ;
51
53
} ) ;
52
54
53
55
instance . getToken ( function ( err , token ) {
54
- expect ( token ) . toBe ( accessToken ) ;
56
+ expect ( token ) . toBe ( ACCESS_TOKEN ) ;
55
57
done ( ) ;
56
58
} ) ;
57
59
} ) ;
@@ -70,21 +72,12 @@ describe('iam_token_manager_v1', function() {
70
72
71
73
instance . tokenInfo = currentTokenInfo ;
72
74
73
- const accessToken = '9012' ;
74
- const iamResponse = {
75
- access_token : accessToken ,
76
- refresh_token : '3456' ,
77
- token_type : 'Bearer' ,
78
- expires_in : 3600 ,
79
- expiration : Math . floor ( Date . now ( ) / 1000 ) + 3600 ,
80
- } ;
81
-
82
75
mockSendRequest . mockImplementation ( ( parameters , _callback ) => {
83
- _callback ( null , iamResponse ) ;
76
+ _callback ( null , IAM_RESPONSE ) ;
84
77
} ) ;
85
78
86
79
instance . getToken ( function ( err , token ) {
87
- expect ( token ) . toBe ( accessToken ) ;
80
+ expect ( token ) . toBe ( ACCESS_TOKEN ) ;
88
81
expect ( requestMock ) . toHaveBeenCalled ( ) ;
89
82
done ( ) ;
90
83
} ) ;
@@ -94,9 +87,8 @@ describe('iam_token_manager_v1', function() {
94
87
const instance = new IamTokenManager ( { apikey : 'abcd-1234' } ) ;
95
88
const requestMock = jest . spyOn ( instance , 'requestToken' ) ;
96
89
97
- const accessToken = '1234' ;
98
90
const currentTokenInfo = {
99
- access_token : accessToken ,
91
+ access_token : ACCESS_TOKEN ,
100
92
refresh_token : '5678' ,
101
93
token_type : 'Bearer' ,
102
94
expires_in : 3600 ,
@@ -108,7 +100,7 @@ describe('iam_token_manager_v1', function() {
108
100
instance . expireTime = currentTokenInfo . expiration ;
109
101
110
102
instance . getToken ( function ( err , token ) {
111
- expect ( token ) . toBe ( accessToken ) ;
103
+ expect ( token ) . toBe ( ACCESS_TOKEN ) ;
112
104
expect ( requestMock ) . not . toHaveBeenCalled ( ) ;
113
105
done ( ) ;
114
106
} ) ;
@@ -127,21 +119,12 @@ describe('iam_token_manager_v1', function() {
127
119
128
120
instance . tokenInfo = currentTokenInfo ;
129
121
130
- const accessToken = '9012' ;
131
- const iamResponse = {
132
- access_token : accessToken ,
133
- refresh_token : '3456' ,
134
- token_type : 'Bearer' ,
135
- expires_in : 3600 ,
136
- expiration : Math . floor ( Date . now ( ) / 1000 ) + 3600 ,
137
- } ;
138
-
139
122
mockSendRequest . mockImplementation ( ( parameters , _callback ) => {
140
- _callback ( null , iamResponse ) ;
123
+ _callback ( null , IAM_RESPONSE ) ;
141
124
} ) ;
142
125
143
126
instance . getToken ( function ( err , token ) {
144
- expect ( token ) . toBe ( accessToken ) ;
127
+ expect ( token ) . toBe ( ACCESS_TOKEN ) ;
145
128
expect ( requestMock ) . toHaveBeenCalled ( ) ;
146
129
done ( ) ;
147
130
} ) ;
@@ -158,21 +141,12 @@ describe('iam_token_manager_v1', function() {
158
141
159
142
instance . tokenInfo = currentTokenInfo ;
160
143
161
- const accessToken = '9012' ;
162
- const iamResponse = {
163
- access_token : accessToken ,
164
- refresh_token : '3456' ,
165
- token_type : 'Bearer' ,
166
- expires_in : 3600 ,
167
- expiration : Math . floor ( Date . now ( ) / 1000 ) + 3600 ,
168
- } ;
169
-
170
144
mockSendRequest . mockImplementation ( ( parameters , _callback ) => {
171
- _callback ( null , iamResponse ) ;
145
+ _callback ( null , IAM_RESPONSE ) ;
172
146
} ) ;
173
147
174
148
instance . getToken ( function ( err , token ) {
175
- expect ( token ) . toBe ( accessToken ) ;
149
+ expect ( token ) . toBe ( ACCESS_TOKEN ) ;
176
150
done ( ) ;
177
151
} ) ;
178
152
} ) ;
0 commit comments