@@ -31,7 +31,8 @@ describe('auth-service', () => {
31
31
const resp200 = new HttpResponse < Object > ( { body : { } , status : 200 } ) ;
32
32
33
33
const testToken = nbAuthCreateToken ( NbAuthSimpleToken , testTokenValue , ownerStrategyName ) ;
34
- const emptyToken = nbAuthCreateToken ( NbAuthSimpleToken , null , ownerStrategyName ) ;
34
+ const invalidToken = nbAuthCreateToken ( NbAuthSimpleToken , testTokenValue , ownerStrategyName ) ;
35
+ const emptyToken = nbAuthCreateToken ( NbAuthSimpleToken , null , null ) ;
35
36
36
37
const failResult = new NbAuthResult ( false ,
37
38
resp401 ,
@@ -162,13 +163,17 @@ describe('auth-service', () => {
162
163
163
164
it ( 'isAuthenticatedOrRefresh, token invalid, strategy refreshToken called, returns true' , ( done ) => {
164
165
166
+ spyOn ( invalidToken , 'isValid' )
167
+ . and
168
+ . returnValue ( false ) ;
169
+
165
170
const spy = spyOn ( dummyAuthStrategy , 'refreshToken' )
166
171
. and
167
172
. returnValue ( observableOf ( successResult ) ) ;
168
173
169
174
spyOn ( tokenService , 'get' )
170
175
. and
171
- . returnValues ( observableOf ( emptyToken ) , observableOf ( testToken ) ) ;
176
+ . returnValues ( observableOf ( invalidToken ) , observableOf ( testToken ) ) ;
172
177
173
178
authService . isAuthenticatedOrRefresh ( )
174
179
. pipe ( first ( ) )
@@ -181,13 +186,33 @@ describe('auth-service', () => {
181
186
) ;
182
187
183
188
it ( 'isAuthenticatedOrRefresh, token invalid, strategy refreshToken called, returns false' , ( done ) => {
189
+
190
+ spyOn ( invalidToken , 'isValid' )
191
+ . and
192
+ . returnValue ( false ) ;
193
+
184
194
const spy = spyOn ( dummyAuthStrategy , 'refreshToken' )
185
195
. and
186
196
. returnValue ( observableOf ( failResult ) ) ;
187
197
188
198
spyOn ( tokenService , 'get' )
189
199
. and
190
- . returnValues ( observableOf ( emptyToken ) , observableOf ( emptyToken ) ) ;
200
+ . returnValues ( observableOf ( invalidToken ) , observableOf ( invalidToken ) ) ;
201
+
202
+ authService . isAuthenticatedOrRefresh ( )
203
+ . pipe ( first ( ) )
204
+ . subscribe ( ( isAuth : boolean ) => {
205
+ expect ( spy ) . toHaveBeenCalled ( ) ;
206
+ expect ( isAuth ) . toBeFalsy ( ) ;
207
+ done ( ) ;
208
+ } ) ;
209
+ } ,
210
+ ) ;
211
+
212
+ it ( 'isAuthenticatedOrRefresh, token doesn\'t exist, strategy refreshToken called, returns false' , ( done ) => {
213
+ const spy = spyOn ( tokenService , 'get' )
214
+ . and
215
+ . returnValue ( observableOf ( emptyToken ) ) ;
191
216
192
217
authService . isAuthenticatedOrRefresh ( )
193
218
. pipe ( first ( ) )
0 commit comments