@@ -31,7 +31,8 @@ describe('auth-service', () => {
3131 const resp200 = new HttpResponse < Object > ( { body : { } , status : 200 } ) ;
3232
3333 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 ) ;
3536
3637 const failResult = new NbAuthResult ( false ,
3738 resp401 ,
@@ -162,13 +163,17 @@ describe('auth-service', () => {
162163
163164 it ( 'isAuthenticatedOrRefresh, token invalid, strategy refreshToken called, returns true' , ( done ) => {
164165
166+ spyOn ( invalidToken , 'isValid' )
167+ . and
168+ . returnValue ( false ) ;
169+
165170 const spy = spyOn ( dummyAuthStrategy , 'refreshToken' )
166171 . and
167172 . returnValue ( observableOf ( successResult ) ) ;
168173
169174 spyOn ( tokenService , 'get' )
170175 . and
171- . returnValues ( observableOf ( emptyToken ) , observableOf ( testToken ) ) ;
176+ . returnValues ( observableOf ( invalidToken ) , observableOf ( testToken ) ) ;
172177
173178 authService . isAuthenticatedOrRefresh ( )
174179 . pipe ( first ( ) )
@@ -181,13 +186,33 @@ describe('auth-service', () => {
181186 ) ;
182187
183188 it ( 'isAuthenticatedOrRefresh, token invalid, strategy refreshToken called, returns false' , ( done ) => {
189+
190+ spyOn ( invalidToken , 'isValid' )
191+ . and
192+ . returnValue ( false ) ;
193+
184194 const spy = spyOn ( dummyAuthStrategy , 'refreshToken' )
185195 . and
186196 . returnValue ( observableOf ( failResult ) ) ;
187197
188198 spyOn ( tokenService , 'get' )
189199 . 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 ) ) ;
191216
192217 authService . isAuthenticatedOrRefresh ( )
193218 . pipe ( first ( ) )
0 commit comments