Skip to content

Commit def8189

Browse files
feat: support IdentifyUserWithId
Support the identifyUser method which accepts the ID of the user.
1 parent fdb5225 commit def8189

File tree

9 files changed

+94
-15
lines changed

9 files changed

+94
-15
lines changed

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,19 @@ public void run() {
292292
*
293293
* @param userName Username.
294294
* @param userEmail User's default email
295+
* @param userId User's ID
295296
*/
296297
@ReactMethod
297-
@Deprecated
298-
public void identifyUser(final String userEmail, final String userName) {
298+
public void identifyUser(
299+
final String userEmail,
300+
final String userName,
301+
@Nullable final String userId
302+
) {
299303
MainThreadHandler.runOnMainThread(new Runnable() {
300304
@Override
301305
public void run() {
302306
try {
303-
Instabug.identifyUser(userName, userEmail);
307+
Instabug.identifyUser(userName, userEmail, userId);
304308
} catch (Exception e) {
305309
e.printStackTrace();
306310
}

android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,26 @@ public void tearDown() {
205205

206206
String email = "[email protected]";
207207
String userName = "salmaali";
208+
String id = null;
208209
// when
209-
rnModule.identifyUser(email, userName);
210+
rnModule.identifyUser(email, userName, id);
210211
// then
211212
verify(Instabug.class,times(1));
212-
Instabug.identifyUser(userName, email);
213+
Instabug.identifyUser(userName, email, id);
214+
}
215+
216+
@Test
217+
public void givenArgs$identifyUserwithId_whenQuery_thenShouldCallNativeApiWithArgs() {
218+
// given
219+
220+
String email = "[email protected]";
221+
String userName = "salmaali";
222+
String id = "salmaali";
223+
// when
224+
rnModule.identifyUser(email, userName, id);
225+
// then
226+
verify(Instabug.class,times(1));
227+
Instabug.identifyUser(userName, email, id);
213228
}
214229

215230
@Test

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,19 @@ - (void)testIdentifyUser {
188188
NSString *name = @"this is my name";
189189

190190
OCMStub([mock identifyUserWithEmail:email name:name]);
191-
[self.instabugBridge identifyUser:email name:name];
192-
OCMVerify([mock identifyUserWithEmail:email name:name]);
191+
[self.instabugBridge identifyUser:email name:name id:nil];
192+
OCMVerify([mock identifyUserWithID:nil email:email name:name]);
193+
}
194+
195+
- (void)testIdentifyUserWithID {
196+
id mock = OCMClassMock([Instabug class]);
197+
NSString *email = @"[email protected]";
198+
NSString *name = @"this is my name";
199+
NSString *id = @"this is my id";
200+
201+
OCMStub([mock identifyUserWithID:id email:email name:name]);
202+
[self.instabugBridge identifyUser:email name:name id:id];
203+
OCMVerify([mock identifyUserWithID:id email:email name:name]);
193204
}
194205

195206
- (void)testLogOut {

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
- (void)setString:(NSString *)value toKey:(NSString *)key;
5151

52-
- (void)identifyUser:(NSString *)email name:(NSString *)name;
52+
- (void)identifyUser:(NSString *)email name:(NSString *)name id:(nullable NSString *)id;
5353

5454
- (void)logOut;
5555

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ - (dispatch_queue_t)methodQueue {
191191
[Instabug clearFileAttachments];
192192
}
193193

194-
RCT_EXPORT_METHOD(identifyUser:(NSString *)email name:(NSString *)name) {
195-
[Instabug identifyUserWithEmail:email name:name];
194+
RCT_EXPORT_METHOD(identifyUser:(NSString *)email name:(NSString *)name id:(nullable NSString *)id) {
195+
[Instabug identifyUserWithID:id email:email name:name];
196+
}
197+
198+
RCT_EXPORT_METHOD(identifyUserWithID:(NSString *)userID email:(NSString *)email name:(NSString *)name) {
199+
[Instabug identifyUserWithID:userID email:email name:name];
196200
}
197201

198202
RCT_EXPORT_METHOD(logOut) {

src/modules/Instabug.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,16 @@ export const setString = (key: StringKey, string: string) => {
196196
};
197197

198198
/**
199-
* Sets the default value of the user's email and hides the email field from the reporting UI
199+
* Sets the default value of the user's email and ID and hides the email field from the reporting UI
200200
* and set the user's name to be included with all reports.
201201
* It also reset the chats on device to that email and removes user attributes,
202202
* user data and completed surveys.
203203
* @param email Email address to be set as the user's email.
204204
* @param name Name of the user to be set.
205+
* @param id optional ID of the user to be set.
205206
*/
206-
export const identifyUser = (email: string, name: string) => {
207-
NativeInstabug.identifyUser(email, name);
207+
export const identifyUser = (email: string, name: string, id?: string) => {
208+
NativeInstabug.identifyUser(email, name, id);
208209
};
209210

210211
/**
@@ -227,7 +228,7 @@ export const logUserEvent = (name: string) => {
227228

228229
/**
229230
* Appends a log message to Instabug internal log.
230-
* These logs are then sent along the next uploaded report.
231+
* These logs are then sent aalong the next uploaded report.
231232
* All log messages are timestamped.
232233
* Logs aren't cleared per single application run.
233234
* If you wish to reset the logs, use {@link clearLogs()}

src/native/NativeInstabug.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export interface InstabugNativeModule extends NativeModule {
6262
clearLogs(): void;
6363

6464
// User APIs //
65-
identifyUser(email: string, name: string): void;
65+
identifyUser(email: string, name: string, id?: string): void;
66+
identifyUserWithId(email: string, name: string, id: string): void;
6667
logOut(): void;
6768
logUserEvent(name: string): void;
6869
setUserData(data: string): void;

test/mocks/mockInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const mockInstabug: InstabugNativeModule = {
2525
getTags: jest.fn(),
2626
setString: jest.fn(),
2727
identifyUser: jest.fn(),
28+
identifyUserWithId: jest.fn(),
2829
logOut: jest.fn(),
2930
logUserEvent: jest.fn(),
3031
logVerbose: jest.fn(),

test/modules/Instabug.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,48 @@ describe('Instabug Module', () => {
412412
expect(NativeInstabug.identifyUser).toBeCalledWith(email, name);
413413
});
414414

415+
it('identifyUser when id is empty should call the native method identifyUser', () => {
416+
const email = '[email protected]';
417+
const name = 'Instabug';
418+
const id = '';
419+
Instabug.identifyUser(email, name, id);
420+
421+
expect(NativeInstabug.identifyUser).toBeCalledTimes(1);
422+
expect(NativeInstabug.identifyUser).toBeCalledWith(email, name);
423+
});
424+
425+
it('identifyUser when id is undefined should call the native method identifyUser', () => {
426+
const email = '[email protected]';
427+
const name = 'Instabug';
428+
const id = undefined;
429+
Instabug.identifyUser(email, name, id);
430+
431+
expect(NativeInstabug.identifyUser).toBeCalledTimes(1);
432+
expect(NativeInstabug.identifyUser).toBeCalledWith(email, name);
433+
});
434+
435+
it('identifyUser when id is present should call the Android native method identifyUser', () => {
436+
Platform.OS = 'android';
437+
const email = '[email protected]';
438+
const name = 'Instabug';
439+
const id = 'id';
440+
Instabug.identifyUser(email, name, id);
441+
442+
expect(NativeInstabug.identifyUser).toBeCalledTimes(1);
443+
expect(NativeInstabug.identifyUser).toBeCalledWith(email, name, id);
444+
});
445+
446+
it('identifyUser when id is present should call the iOS native method identifyUserWithID', () => {
447+
Platform.OS = 'ios';
448+
const email = '[email protected]';
449+
const name = 'Instabug';
450+
const id = 'id';
451+
Instabug.identifyUser(email, name, id);
452+
453+
expect(NativeInstabug.identifyUserWithId).toBeCalledTimes(1);
454+
expect(NativeInstabug.identifyUserWithId).toBeCalledWith(email, name, id);
455+
});
456+
415457
it('should call the native method logOut', () => {
416458
Instabug.logOut();
417459

0 commit comments

Comments
 (0)