@@ -2,12 +2,14 @@ import EncryptedStorage from 'react-native-encrypted-storage';
22import OidcAuthStateStorage , {
33 type OidcAuthState ,
44} from './OidcAuthStateStorage' ;
5+ import * as SentryIntegrationModule from './sentryIntegration' ;
56
67describe ( 'OidcAuthStateStorage' , ( ) => {
78 const CLIENT_ID = 'test-client-id' ;
89 const EXPECTED_STORAGE_KEY = `de.contentpass.${ CLIENT_ID } -OIDCAuthState` ;
910
1011 let storage : OidcAuthStateStorage ;
12+ let reportErrorSpy : jest . SpyInstance ;
1113 const mockAuthState : OidcAuthState = {
1214 accessToken : 'test-access-token' ,
1315 accessTokenExpirationDate : '2023-12-31T23:59:59Z' ,
@@ -18,6 +20,9 @@ describe('OidcAuthStateStorage', () => {
1820
1921 beforeEach ( ( ) => {
2022 storage = new OidcAuthStateStorage ( CLIENT_ID ) ;
23+ reportErrorSpy = jest
24+ . spyOn ( SentryIntegrationModule , 'reportError' )
25+ . mockReturnValue ( undefined ) ;
2126 } ) ;
2227
2328 afterEach ( ( ) => {
@@ -59,4 +64,18 @@ describe('OidcAuthStateStorage', () => {
5964 EXPECTED_STORAGE_KEY
6065 ) ;
6166 } ) ;
67+
68+ it ( 'should report error if clearing OIDC auth state fails' , async ( ) => {
69+ const error = new Error ( 'test-error' ) ;
70+ ( EncryptedStorage . removeItem as jest . Mock ) . mockRejectedValue ( error ) ;
71+
72+ await storage . clearOidcAuthState ( ) ;
73+
74+ expect ( EncryptedStorage . removeItem ) . toHaveBeenCalledWith (
75+ EXPECTED_STORAGE_KEY
76+ ) ;
77+ expect ( reportErrorSpy ) . toHaveBeenCalledWith ( error , {
78+ msg : 'Failed to clear OIDC auth state. Most probably we tried to remove item which does not exist' ,
79+ } ) ;
80+ } ) ;
6281} ) ;
0 commit comments