11/**
2- * Tests for setUserJWT API specifically
2+ * Tests for setUserJwt API specifically
33 */
44
5- describe ( 'Intercom setUserJWT API' , ( ) => {
5+ describe ( 'Intercom setUserJwt API' , ( ) => {
66 let mockIntercomModule ;
77 let Intercom ;
88
@@ -13,7 +13,7 @@ describe('Intercom setUserJWT API', () => {
1313 jest . doMock ( 'react-native' , ( ) => ( {
1414 NativeModules : {
1515 IntercomModule : {
16- setUserJWT : jest . fn ( ) ,
16+ setUserJwt : jest . fn ( ) ,
1717 setUserHash : jest . fn ( ) ,
1818 loginUserWithUserAttributes : jest . fn ( ) ,
1919 logout : jest . fn ( ) ,
@@ -54,46 +54,46 @@ describe('Intercom setUserJWT API', () => {
5454 jest . clearAllMocks ( ) ;
5555 } ) ;
5656
57- describe ( 'setUserJWT method' , ( ) => {
58- test ( 'should call native setUserJWT with valid JWT' , async ( ) => {
57+ describe ( 'setUserJwt method' , ( ) => {
58+ test ( 'should call native setUserJwt with valid JWT' , async ( ) => {
5959 const testJWT =
6060 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.test' ;
61- mockIntercomModule . setUserJWT . mockResolvedValue ( true ) ;
61+ mockIntercomModule . setUserJwt . mockResolvedValue ( true ) ;
6262
63- const result = await Intercom . setUserJWT ( testJWT ) ;
63+ const result = await Intercom . setUserJwt ( testJWT ) ;
6464
65- expect ( mockIntercomModule . setUserJWT ) . toHaveBeenCalledWith ( testJWT ) ;
65+ expect ( mockIntercomModule . setUserJwt ) . toHaveBeenCalledWith ( testJWT ) ;
6666 expect ( result ) . toBe ( true ) ;
6767 } ) ;
6868
6969 test ( 'should handle JWT authentication errors' , async ( ) => {
7070 const invalidJWT = 'invalid.jwt' ;
7171 const error = new Error ( 'JWT validation failed' ) ;
72- mockIntercomModule . setUserJWT . mockRejectedValue ( error ) ;
72+ mockIntercomModule . setUserJwt . mockRejectedValue ( error ) ;
7373
74- await expect ( Intercom . setUserJWT ( invalidJWT ) ) . rejects . toThrow (
74+ await expect ( Intercom . setUserJwt ( invalidJWT ) ) . rejects . toThrow (
7575 'JWT validation failed'
7676 ) ;
7777 } ) ;
7878
7979 test ( 'should work with empty JWT string' , async ( ) => {
8080 const emptyJWT = '' ;
81- mockIntercomModule . setUserJWT . mockResolvedValue ( true ) ;
81+ mockIntercomModule . setUserJwt . mockResolvedValue ( true ) ;
8282
83- const result = await Intercom . setUserJWT ( emptyJWT ) ;
83+ const result = await Intercom . setUserJwt ( emptyJWT ) ;
8484
85- expect ( mockIntercomModule . setUserJWT ) . toHaveBeenCalledWith ( emptyJWT ) ;
85+ expect ( mockIntercomModule . setUserJwt ) . toHaveBeenCalledWith ( emptyJWT ) ;
8686 expect ( result ) . toBe ( true ) ;
8787 } ) ;
8888
8989 test ( 'should handle long JWT tokens' , async ( ) => {
9090 const longJWT =
9191 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzNDU2Nzg5MCIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsIm5hbWUiOiJKb2huIERvZSIsImN1c3RvbV9hdHRyaWJ1dGVzIjp7InBsYW4iOiJwcmVtaXVtIiwiY29tcGFueSI6IkFjbWUgSW5jIn19.very_long_signature' ;
92- mockIntercomModule . setUserJWT . mockResolvedValue ( true ) ;
92+ mockIntercomModule . setUserJwt . mockResolvedValue ( true ) ;
9393
94- const result = await Intercom . setUserJWT ( longJWT ) ;
94+ const result = await Intercom . setUserJwt ( longJWT ) ;
9595
96- expect ( mockIntercomModule . setUserJWT ) . toHaveBeenCalledWith ( longJWT ) ;
96+ expect ( mockIntercomModule . setUserJwt ) . toHaveBeenCalledWith ( longJWT ) ;
9797 expect ( result ) . toBe ( true ) ;
9898 } ) ;
9999 } ) ;
@@ -104,18 +104,18 @@ describe('Intercom setUserJWT API', () => {
104104 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzIn0.test' ;
105105 const userAttributes = { email :
'[email protected] ' } ; 106106
107- mockIntercomModule . setUserJWT . mockResolvedValue ( true ) ;
107+ mockIntercomModule . setUserJwt . mockResolvedValue ( true ) ;
108108 mockIntercomModule . loginUserWithUserAttributes . mockResolvedValue ( true ) ;
109109
110- await Intercom . setUserJWT ( jwt ) ;
110+ await Intercom . setUserJwt ( jwt ) ;
111111 await Intercom . loginUserWithUserAttributes ( userAttributes ) ;
112112
113- expect ( mockIntercomModule . setUserJWT ) . toHaveBeenCalledWith ( jwt ) ;
113+ expect ( mockIntercomModule . setUserJwt ) . toHaveBeenCalledWith ( jwt ) ;
114114 expect (
115115 mockIntercomModule . loginUserWithUserAttributes
116116 ) . toHaveBeenCalledWith ( userAttributes ) ;
117- // Verify setUserJWT was called first by checking call counts
118- expect ( mockIntercomModule . setUserJWT ) . toHaveBeenCalledTimes ( 1 ) ;
117+ // Verify setUserJwt was called first by checking call counts
118+ expect ( mockIntercomModule . setUserJwt ) . toHaveBeenCalledTimes ( 1 ) ;
119119 expect (
120120 mockIntercomModule . loginUserWithUserAttributes
121121 ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -126,13 +126,13 @@ describe('Intercom setUserJWT API', () => {
126126 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzIn0.test' ;
127127 const hash = 'hmac_hash_123' ;
128128
129- mockIntercomModule . setUserJWT . mockResolvedValue ( true ) ;
129+ mockIntercomModule . setUserJwt . mockResolvedValue ( true ) ;
130130 mockIntercomModule . setUserHash . mockResolvedValue ( true ) ;
131131
132- const jwtResult = await Intercom . setUserJWT ( jwt ) ;
132+ const jwtResult = await Intercom . setUserJwt ( jwt ) ;
133133 const hashResult = await Intercom . setUserHash ( hash ) ;
134134
135- expect ( mockIntercomModule . setUserJWT ) . toHaveBeenCalledWith ( jwt ) ;
135+ expect ( mockIntercomModule . setUserJwt ) . toHaveBeenCalledWith ( jwt ) ;
136136 expect ( mockIntercomModule . setUserHash ) . toHaveBeenCalledWith ( hash ) ;
137137 expect ( jwtResult ) . toBe ( true ) ;
138138 expect ( hashResult ) . toBe ( true ) ;
@@ -143,13 +143,13 @@ describe('Intercom setUserJWT API', () => {
143143 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzIn0.test' ;
144144 const userAttributes = { userId :
'123' , email :
'[email protected] ' } ; 145145
146- mockIntercomModule . setUserJWT . mockResolvedValue ( true ) ;
146+ mockIntercomModule . setUserJwt . mockResolvedValue ( true ) ;
147147 mockIntercomModule . loginUserWithUserAttributes . mockResolvedValue ( true ) ;
148148 mockIntercomModule . isUserLoggedIn . mockResolvedValue ( true ) ;
149149 mockIntercomModule . updateUser . mockResolvedValue ( true ) ;
150150
151151 // Set JWT first
152- await Intercom . setUserJWT ( jwt ) ;
152+ await Intercom . setUserJwt ( jwt ) ;
153153
154154 // Login user
155155 await Intercom . loginUserWithUserAttributes ( userAttributes ) ;
@@ -160,7 +160,7 @@ describe('Intercom setUserJWT API', () => {
160160 // Update user
161161 await Intercom . updateUser ( { name : 'Updated Name' } ) ;
162162
163- expect ( mockIntercomModule . setUserJWT ) . toHaveBeenCalledWith ( jwt ) ;
163+ expect ( mockIntercomModule . setUserJwt ) . toHaveBeenCalledWith ( jwt ) ;
164164 expect (
165165 mockIntercomModule . loginUserWithUserAttributes
166166 ) . toHaveBeenCalledWith ( userAttributes ) ;
@@ -175,19 +175,19 @@ describe('Intercom setUserJWT API', () => {
175175 test ( 'should handle network errors' , async ( ) => {
176176 const jwt = 'test.jwt.token' ;
177177 const networkError = new Error ( 'Network request failed' ) ;
178- mockIntercomModule . setUserJWT . mockRejectedValue ( networkError ) ;
178+ mockIntercomModule . setUserJwt . mockRejectedValue ( networkError ) ;
179179
180- await expect ( Intercom . setUserJWT ( jwt ) ) . rejects . toThrow (
180+ await expect ( Intercom . setUserJwt ( jwt ) ) . rejects . toThrow (
181181 'Network request failed'
182182 ) ;
183183 } ) ;
184184
185185 test ( 'should handle invalid JWT format errors' , async ( ) => {
186186 const invalidJWT = 'not.a.valid.jwt' ;
187187 const formatError = new Error ( 'Invalid JWT format' ) ;
188- mockIntercomModule . setUserJWT . mockRejectedValue ( formatError ) ;
188+ mockIntercomModule . setUserJwt . mockRejectedValue ( formatError ) ;
189189
190- await expect ( Intercom . setUserJWT ( invalidJWT ) ) . rejects . toThrow (
190+ await expect ( Intercom . setUserJwt ( invalidJWT ) ) . rejects . toThrow (
191191 'Invalid JWT format'
192192 ) ;
193193 } ) ;
@@ -196,9 +196,9 @@ describe('Intercom setUserJWT API', () => {
196196 const jwtWithBadSignature =
197197 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzIn0.bad_signature' ;
198198 const signatureError = new Error ( 'JWT signature verification failed' ) ;
199- mockIntercomModule . setUserJWT . mockRejectedValue ( signatureError ) ;
199+ mockIntercomModule . setUserJwt . mockRejectedValue ( signatureError ) ;
200200
201- await expect ( Intercom . setUserJWT ( jwtWithBadSignature ) ) . rejects . toThrow (
201+ await expect ( Intercom . setUserJwt ( jwtWithBadSignature ) ) . rejects . toThrow (
202202 'JWT signature verification failed'
203203 ) ;
204204 } ) ;
0 commit comments