@@ -17,15 +17,15 @@ describe('KeycloakService', () => {
1717 } ) ;
1818 } ) ;
1919
20- it ( 'Should be created' , inject (
20+ it ( 'should be created' , inject (
2121 [ KeycloakService ] ,
2222 ( service : KeycloakService ) => {
2323 expect ( service ) . toBeTruthy ( ) ;
2424 }
2525 ) ) ;
2626
2727 describe ( '#loadExcludedUrls' , ( ) => {
28- it ( 'Should create the ExcludedUrlRegex objects if the bearerExcludedUrls arg is a string array' , inject (
28+ it ( 'should create the ExcludedUrlRegex objects if the bearerExcludedUrls arg is a string array' , inject (
2929 [ KeycloakService ] ,
3030 ( service : KeycloakService ) => {
3131 const loadExcludedUrls = service [ 'loadExcludedUrls' ] ;
@@ -39,7 +39,7 @@ describe('KeycloakService', () => {
3939 }
4040 ) ) ;
4141
42- it ( 'Should create the ExcludedUrlRegex objects if the bearerExcludedUrls arg is an mixed array of strings and ExcludedUrl objects' , inject (
42+ it ( 'should create the ExcludedUrlRegex objects if the bearerExcludedUrls arg is an mixed array of strings and ExcludedUrl objects' , inject (
4343 [ KeycloakService ] ,
4444 ( service : KeycloakService ) => {
4545 const loadExcludedUrls = service [ 'loadExcludedUrls' ] ;
@@ -63,5 +63,33 @@ describe('KeycloakService', () => {
6363 expect ( excludedRegex2 . httpMethods [ 0 ] ) . toBe ( 'GET' ) ;
6464 }
6565 ) ) ;
66+
67+ it ( 'should not call login in error case if getToken is called with forceLogin false' , inject (
68+ [ KeycloakService ] ,
69+ async ( service : KeycloakService ) => {
70+ service . updateToken = async ( ) => Promise . reject ( new Error ( 'test' ) ) ;
71+ spyOn ( service , 'login' ) ;
72+
73+ let error : Error ;
74+ await service . getToken ( false ) . catch ( e => error = e ) ;
75+
76+ expect ( error ) . toBeDefined ( ) ;
77+ expect ( service . login ) . not . toHaveBeenCalled ( ) ;
78+ }
79+ ) ) ;
80+
81+ it ( 'should return correct token in success case if getToken is called with forceLogin false' , inject (
82+ [ KeycloakService ] ,
83+ async ( service : KeycloakService ) => {
84+ service . updateToken = async ( ) => Promise . resolve ( true ) ;
85+ ( service [ '_instance' ] as any ) = {
86+ token : 'testToken'
87+ } ;
88+
89+ const token = await service . getToken ( false ) ;
90+
91+ expect ( token ) . toEqual ( 'testToken' ) ;
92+ }
93+ ) ) ;
6694 } ) ;
6795} ) ;
0 commit comments