@@ -56,6 +56,7 @@ describe(`AutoLoginGuard`, () => {
5656 it (
5757 'should call checkAuth() if not authenticated already' ,
5858 waitForAsync ( ( ) => {
59+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
5960 const checkAuthServiceSpy = spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
6061
6162 autoLoginGuard . canActivate ( null , { url : 'some-url1' } as RouterStateSnapshot ) . subscribe ( ( ) => {
@@ -67,8 +68,8 @@ describe(`AutoLoginGuard`, () => {
6768 it (
6869 'should NOT call checkAuth() if authenticated already' ,
6970 waitForAsync ( ( ) => {
71+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( true ) ;
7072 const checkAuthServiceSpy = spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
71- spyOnProperty ( authStateService , 'authorized$' , 'get' ) . and . returnValue ( of ( true ) ) ;
7273
7374 autoLoginGuard . canActivate ( null , { url : 'some-url2' } as RouterStateSnapshot ) . subscribe ( ( ) => {
7475 expect ( checkAuthServiceSpy ) . not . toHaveBeenCalled ( ) ;
@@ -79,6 +80,7 @@ describe(`AutoLoginGuard`, () => {
7980 it (
8081 'should call loginService.login() when not authorized' ,
8182 waitForAsync ( ( ) => {
83+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
8284 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
8385 const loginSpy = spyOn ( loginService , 'login' ) ;
8486
@@ -91,6 +93,7 @@ describe(`AutoLoginGuard`, () => {
9193 it (
9294 'should return false when not authorized' ,
9395 waitForAsync ( ( ) => {
96+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
9497 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
9598
9699 autoLoginGuard . canActivate ( null , { url : 'some-url4' } as RouterStateSnapshot ) . subscribe ( ( result ) => {
@@ -102,6 +105,7 @@ describe(`AutoLoginGuard`, () => {
102105 it (
103106 'if no route is stored, setItem on localStorage is called' ,
104107 waitForAsync ( ( ) => {
108+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
105109 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
106110 const localStorageSpy = spyOn ( localStorage , 'setItem' ) ;
107111
@@ -127,6 +131,7 @@ describe(`AutoLoginGuard`, () => {
127131 it (
128132 'if authorized and stored route exists: remove item, navigate to route and return true' ,
129133 waitForAsync ( ( ) => {
134+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
130135 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( true ) ) ;
131136 spyOn ( localStorage , 'getItem' ) . and . returnValue ( 'stored-route' ) ;
132137 const localStorageSpy = spyOn ( localStorage , 'removeItem' ) ;
@@ -147,6 +152,7 @@ describe(`AutoLoginGuard`, () => {
147152 it (
148153 'should call checkAuth() if not authenticated already' ,
149154 waitForAsync ( ( ) => {
155+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
150156 const checkAuthServiceSpy = spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
151157
152158 autoLoginGuard . canLoad ( null , [ ] ) . subscribe ( ( ) => {
@@ -159,7 +165,7 @@ describe(`AutoLoginGuard`, () => {
159165 'should NOT call checkAuth() if authenticated already' ,
160166 waitForAsync ( ( ) => {
161167 const checkAuthServiceSpy = spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
162- spyOnProperty ( authStateService , 'authorized$' , 'get' ) . and . returnValue ( of ( true ) ) ;
168+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( true ) ;
163169
164170 autoLoginGuard . canLoad ( null , [ ] ) . subscribe ( ( ) => {
165171 expect ( checkAuthServiceSpy ) . not . toHaveBeenCalled ( ) ;
@@ -170,6 +176,7 @@ describe(`AutoLoginGuard`, () => {
170176 it (
171177 'should call loginService.login() when not authorized' ,
172178 waitForAsync ( ( ) => {
179+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
173180 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
174181 const loginSpy = spyOn ( loginService , 'login' ) ;
175182
@@ -182,6 +189,7 @@ describe(`AutoLoginGuard`, () => {
182189 it (
183190 'should return false when not authorized' ,
184191 waitForAsync ( ( ) => {
192+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
185193 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
186194
187195 autoLoginGuard . canLoad ( null , [ ] ) . subscribe ( ( result ) => {
@@ -193,6 +201,7 @@ describe(`AutoLoginGuard`, () => {
193201 it (
194202 'if no route is stored, setItem on localStorage is called' ,
195203 waitForAsync ( ( ) => {
204+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
196205 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
197206 const localStorageSpy = spyOn ( localStorage , 'setItem' ) ;
198207
@@ -205,6 +214,7 @@ describe(`AutoLoginGuard`, () => {
205214 it (
206215 'if no route is stored, setItem on localStorage is called, multiple params' ,
207216 waitForAsync ( ( ) => {
217+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
208218 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( null ) ) ;
209219 const localStorageSpy = spyOn ( localStorage , 'setItem' ) ;
210220
@@ -232,6 +242,7 @@ describe(`AutoLoginGuard`, () => {
232242 it (
233243 'if authorized and stored route exists: remove item, navigate to route and return true' ,
234244 waitForAsync ( ( ) => {
245+ spyOn ( authStateService , 'areAuthStorageTokensValid' ) . and . returnValue ( false ) ;
235246 spyOn ( checkAuthService , 'checkAuth' ) . and . returnValue ( of ( true ) ) ;
236247 spyOn ( localStorage , 'getItem' ) . and . returnValue ( 'stored-route' ) ;
237248 const localStorageSpy = spyOn ( localStorage , 'removeItem' ) ;
0 commit comments