Skip to content

Commit f165b5c

Browse files
abdelhamid-f-nasserHeshamMegid
authored andcommitted
feat: support identify user by id (#1115)
Jira ID: MOB-13746
1 parent 502d2eb commit f165b5c

File tree

9 files changed

+64
-17
lines changed

9 files changed

+64
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v12.6.0...dev)
4+
5+
### Added
6+
7+
- Support user identification using ID ([#1115](https://github.com/Instabug/Instabug-React-Native/pull/1115))
8+
39
## [12.6.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.5.0...v12.6.0) (January 14, 2024)
410

511
### Changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,22 @@ public void run() {
294294
* Set the user identity.
295295
* Instabug will pre-fill the user email in reports.
296296
*
297-
* @param userName Username.
298297
* @param userEmail User's default email
298+
* @param userName Username.
299+
* @param userId User's ID
299300
*/
300301
@ReactMethod
301-
public void identifyUser(final String userEmail, final String userName) {
302+
public void identifyUser(
303+
final String userEmail,
304+
final String userName,
305+
@Nullable final String userId
306+
) {
302307
MainThreadHandler.runOnMainThread(new Runnable() {
303308
@Override
304309
public void run() {
305310
try {
306-
Instabug.identifyUser(userName, userEmail);
311+
// The arguments get re-ordered here to match the API signature.
312+
Instabug.identifyUser(userName, userEmail, userId);
307313
} catch (Exception e) {
308314
e.printStackTrace();
309315
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,29 @@ public void tearDown() {
200200
}
201201

202202
@Test
203-
public void givenArgs$identifyUser_whenQuery_thenShouldCallNativeApiWithArgs() {
203+
public void testIdentifyUserWithNoId() {
204204
// given
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
211-
verify(Instabug.class,times(1));
212-
Instabug.identifyUser(userName, email);
212+
mockInstabug.verify(() -> Instabug.identifyUser(userName, email, id));
213+
}
214+
215+
@Test
216+
public void testIdentifyUserWithId() {
217+
// given
218+
219+
String email = "[email protected]";
220+
String userName = "salmaali";
221+
String id = "salmaali";
222+
// when
223+
rnModule.identifyUser(email, userName, id);
224+
// then
225+
mockInstabug.verify(() -> Instabug.identifyUser(userName, email, id));
213226
}
214227

215228
@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 userId: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 *userId = @"this is my id";
200+
201+
OCMStub([mock identifyUserWithID:userId email:email name:name]);
202+
[self.instabugBridge identifyUser:email name:name userId:userId];
203+
OCMVerify([mock identifyUserWithID:userId 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 userId:(nullable NSString *)userId;
5353

5454
- (void)logOut;
5555

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ - (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 userId:(nullable NSString *)userId) {
195+
[Instabug identifyUserWithID:userId email:email name:name];
196196
}
197197

198198
RCT_EXPORT_METHOD(logOut) {

src/modules/Instabug.ts

Lines changed: 4 additions & 3 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] 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
/**

src/native/NativeInstabug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ 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;
6666
logOut(): void;
6767
logUserEvent(name: string): void;
6868
setUserData(data: string): void;

test/modules/Instabug.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,17 @@ describe('Instabug Module', () => {
409409
Instabug.identifyUser(email, name);
410410

411411
expect(NativeInstabug.identifyUser).toBeCalledTimes(1);
412-
expect(NativeInstabug.identifyUser).toBeCalledWith(email, name);
412+
expect(NativeInstabug.identifyUser).toBeCalledWith(email, name, undefined);
413+
});
414+
415+
it('identifyUser when id is defined should call the native method identifyUser', () => {
416+
const email = '[email protected]';
417+
const name = 'Instabug';
418+
const id = 'instabug-id';
419+
Instabug.identifyUser(email, name, id);
420+
421+
expect(NativeInstabug.identifyUser).toBeCalledTimes(1);
422+
expect(NativeInstabug.identifyUser).toBeCalledWith(email, name, id);
413423
});
414424

415425
it('should call the native method logOut', () => {

0 commit comments

Comments
 (0)