Skip to content

Commit 9f963df

Browse files
Apply follow-up changes requested in PR comments
1 parent 3915cf2 commit 9f963df

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

__tests__/intercom-jwt.test.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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
});

__tests__/setupTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { NativeModules } from 'react-native';
77
// Mock the native modules
88
const mockIntercomModule = {
99
setUserHash: jest.fn(),
10-
setUserJWT: jest.fn(),
10+
setUserJwt: jest.fn(),
1111
loginUnidentifiedUser: jest.fn(),
1212
loginUserWithUserAttributes: jest.fn(),
1313
logout: jest.fn(),

android/src/main/java/com/intercom/reactnative/IntercomModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ public void setUserHash(String userHash, Promise promise) {
180180
}
181181

182182
@ReactMethod
183-
public void setUserJWT(String jwt, Promise promise) {
183+
public void setUserJwt(String jwt, Promise promise) {
184184
try {
185-
Intercom.client().setUserJWT(jwt);
185+
Intercom.client().setUserJwt(jwt);
186186
promise.resolve(true);
187187
} catch (Exception err) {
188-
Log.e(NAME, "setUserJWT error:");
188+
Log.e(NAME, "setUserJwt error:");
189189
Log.e(NAME, err.toString());
190190
promise.reject(IntercomErrorCodes.SET_USER_JWT, err.toString());
191191
}

ios/IntercomModule.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ - (NSData *)dataFromHexString:(NSString *)string {
155155
}
156156
};
157157

158-
RCT_EXPORT_METHOD(setUserJWT:(NSString *)jwt
158+
RCT_EXPORT_METHOD(setUserJwt:(NSString *)jwt
159159
resolver:(RCTPromiseResolveBlock)resolve
160160
rejecter:(RCTPromiseRejectBlock)reject) {
161161
@try {
162-
[Intercom setUserJWT:jwt];
162+
[Intercom setUserJwt:jwt];
163163
resolve(@(YES));
164164
} @catch (NSException *exception) {
165-
reject(UPDATE_USER, @"Error in setUserJWT", [self exceptionToError:exception :SET_USER_JWT :@"setUserJWT"]);
165+
reject(UPDATE_USER, @"Error in setUserJwt", [self exceptionToError:exception :SET_USER_JWT :@"setUserJwt"]);
166166
}
167167
};
168168

src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export type IntercomType = {
149149
* @see More information on JWT authentication can be found {@link https://www.intercom.com/help/en/articles/10589769-authenticating-users-in-the-messenger-with-json-web-tokens-jwts here}
150150
* @param jwt A JWT string generated by your server using your Intercom secret key.
151151
*/
152-
setUserJWT(jwt: string): Promise<boolean>;
152+
setUserJwt(jwt: string): Promise<boolean>;
153153

154154
/**
155155
* Update a user in Intercom with data specified in {@link UserAttributes}.
@@ -315,7 +315,7 @@ const Intercom: IntercomType = {
315315
IntercomModule.loginUserWithUserAttributes(userAttributes),
316316
logout: () => IntercomModule.logout(),
317317
setUserHash: (hash) => IntercomModule.setUserHash(hash),
318-
setUserJWT: (jwt) => IntercomModule.setUserJWT(jwt),
318+
setUserJwt: (jwt) => IntercomModule.setUserJwt(jwt),
319319
updateUser: (userAttributes) => IntercomModule.updateUser(userAttributes),
320320
isUserLoggedIn: () => IntercomModule.isUserLoggedIn(),
321321
fetchLoggedInUserAttributes: () =>

0 commit comments

Comments
 (0)