@@ -7,6 +7,7 @@ import type { ContentpassState } from './types/ContentpassState';
77import OidcAuthStateStorage from './OidcAuthStateStorage' ;
88import * as FetchContentpassTokenModule from './utils/fetchContentpassToken' ;
99import { SCOPES } from './consts/oidcConsts' ;
10+ import * as SentryScopeModule from './sentryScope' ;
1011
1112const config : ContentpassConfig = {
1213 propertyId : 'propertyId-1' ,
@@ -39,6 +40,7 @@ describe('Contentpass', () => {
3940 let contentpass : Contentpass ;
4041 let authorizeSpy : jest . SpyInstance ;
4142 let refreshSpy : jest . SpyInstance ;
43+ let reportErrorSpy : jest . SpyInstance ;
4244 let fetchContentpassTokenSpy : jest . SpyInstance ;
4345 let oidcAuthStorageMock : OidcAuthStateStorage ;
4446
@@ -50,6 +52,9 @@ describe('Contentpass', () => {
5052 refreshSpy = jest
5153 . spyOn ( AppAuthModule , 'refresh' )
5254 . mockResolvedValue ( EXAMPLE_REFRESH_RESULT ) ;
55+ reportErrorSpy = jest
56+ . spyOn ( SentryScopeModule , 'reportError' )
57+ . mockReturnValue ( undefined ) ;
5358
5459 oidcAuthStorageMock = {
5560 storeOidcAuthState : jest . fn ( ) ,
@@ -166,13 +171,18 @@ describe('Contentpass', () => {
166171
167172 it ( 'should change contentpass state to error when authorize throws an error' , async ( ) => {
168173 const contentpassStates : ContentpassState [ ] = [ ] ;
169- authorizeSpy . mockRejectedValue ( new Error ( 'Authorize error' ) ) ;
174+ const error = new Error ( 'Authorize error' ) ;
175+ authorizeSpy . mockRejectedValue ( error ) ;
170176 contentpass . registerObserver ( ( state ) => {
171177 contentpassStates . push ( state ) ;
172178 } ) ;
173179
174180 await contentpass . authenticate ( ) ;
175181
182+ expect ( reportErrorSpy ) . toHaveBeenCalledWith ( error , {
183+ msg : 'Failed to authorize' ,
184+ } ) ;
185+
176186 expect ( contentpassStates ) . toHaveLength ( 2 ) ;
177187 expect ( contentpassStates [ 1 ] ) . toEqual ( {
178188 state : 'ERROR' ,
@@ -291,7 +301,8 @@ describe('Contentpass', () => {
291301 ) . getTime ( ) ;
292302 const expectedDelay = expirationDate - NOW ;
293303
294- refreshSpy . mockRejectedValue ( new Error ( 'Refresh error' ) ) ;
304+ const refreshError = new Error ( 'Refresh error' ) ;
305+ refreshSpy . mockRejectedValue ( refreshError ) ;
295306
296307 await jest . advanceTimersByTimeAsync ( expectedDelay ) ;
297308 expect ( contentpassStates ) . toHaveLength ( 2 ) ;
@@ -308,7 +319,11 @@ describe('Contentpass', () => {
308319 } ) ;
309320
310321 // after 6 retries the state should change to error
311- await jest . advanceTimersByTimeAsync ( 180001 ) ;
322+ await jest . advanceTimersByTimeAsync ( 120001 ) ;
323+ expect ( reportErrorSpy ) . toHaveBeenCalledTimes ( 7 ) ;
324+ expect ( reportErrorSpy ) . toHaveBeenCalledWith ( refreshError , {
325+ msg : 'Failed to refresh token after 6 retries' ,
326+ } ) ;
312327 expect ( contentpassStates ) . toHaveLength ( 3 ) ;
313328 expect ( contentpassStates [ 2 ] ) . toEqual ( {
314329 state : 'UNAUTHENTICATED' ,
0 commit comments