Skip to content

Commit d452631

Browse files
a7medevmzelzoghbi
authored andcommitted
feat: add runtime code push version API (#1143)
* feat(android): add native runtime setCodePushVersion * feat(ios): add native runtime setCodePushVersion * feat: add runtime code push version API * test: add tests for runtime code push version API * chore: update changelog
1 parent 6cd81ec commit d452631

File tree

10 files changed

+63
-0
lines changed

10 files changed

+63
-0
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.7.1...dev)
4+
5+
### Added
6+
7+
- Support setting the Code Push version after SDK initialization ([#1143](https://github.com/Instabug/Instabug-React-Native/pull/1143)).
8+
39
## [12.7.1](https://github.com/Instabug/Instabug-React-Native/compare/v12.7.0...v12.7.1) (February 15, 2024)
410

511
### Changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ public void run() {
160160
});
161161
}
162162

163+
@ReactMethod
164+
public void setCodePushVersion(@Nullable String version) {
165+
MainThreadHandler.runOnMainThread(new Runnable() {
166+
@Override
167+
public void run() {
168+
try {
169+
Instabug.setCodePushVersion(version);
170+
} catch (Exception e) {
171+
e.printStackTrace();
172+
}
173+
}
174+
});
175+
}
176+
163177

164178
/**
165179
* Adds tag(s) to issues before sending them

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ public void tearDown() {
199199
Instabug.setPrimaryColor(color);
200200
}
201201

202+
@Test
203+
public void testSetCodePushVersion() {
204+
String codePushVersion = "123";
205+
206+
rnModule.setCodePushVersion(codePushVersion);
207+
208+
mockInstabug.verify(() -> Instabug.setCodePushVersion(codePushVersion));
209+
}
210+
202211
@Test
203212
public void testIdentifyUserWithNoId() {
204213
// given

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ - (void)testInit {
8181
OCMVerify([self.mRNInstabug initWithToken:appToken invocationEvents:floatingButtonInvocationEvent debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception]);
8282
}
8383

84+
- (void)testSetCodePushVersion {
85+
id mock = OCMClassMock([Instabug class]);
86+
NSString *codePushVersion = @"123";
87+
88+
[self.instabugBridge setCodePushVersion:codePushVersion];
89+
90+
OCMVerify([mock setCodePushVersion:codePushVersion]);
91+
}
92+
8493
- (void)testSetUserData {
8594
id mock = OCMClassMock([Instabug class]);
8695
NSString *userData = @"user_data";

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel useNativeNetworkInterception:(BOOL)useNativeNetworkInterception codePushVersion:(NSString *)codePushVersion;
3131

32+
- (void)setCodePushVersion:(NSString *)version;
33+
3234
- (void)setUserData:(NSString *)userData;
3335

3436
- (void)setTrackUserSteps:(BOOL)isEnabled;

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ - (dispatch_queue_t)methodQueue {
5656
useNativeNetworkInterception:useNativeNetworkInterception];
5757
}
5858

59+
RCT_EXPORT_METHOD(setCodePushVersion:(NSString *)version) {
60+
[Instabug setCodePushVersion:version];
61+
}
62+
5963
RCT_EXPORT_METHOD(setReproStepsConfig:(IBGUserStepsMode)bugMode :(IBGUserStepsMode)crashMode:(IBGUserStepsMode)sessionReplayMode) {
6064
[Instabug setReproStepsFor:IBGIssueTypeBug withMode:bugMode];
6165
[Instabug setReproStepsFor:IBGIssueTypeCrash withMode:crashMode];

src/modules/Instabug.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ export const init = (config: InstabugConfig) => {
9090
}, 1000);
9191
};
9292

93+
/**
94+
* Sets the Code Push version to be sent with each report.
95+
* @param version the Code Push version.
96+
*/
97+
export const setCodePushVersion = (version: string) => {
98+
NativeInstabug.setCodePushVersion(version);
99+
};
100+
93101
/**
94102
* Attaches user data to each report being sent.
95103
* Each call to this method overrides the user data to be attached.

src/native/NativeInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface InstabugNativeModule extends NativeModule {
2929
show(): void;
3030

3131
// Misc APIs //
32+
setCodePushVersion(version: string): void;
3233
setIBGLogPrintsToConsole(printsToConsole: boolean): void;
3334
setSessionProfilerEnabled(isEnabled: boolean): void;
3435

test/mocks/mockInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const mockInstabug: InstabugNativeModule = {
1313
removeListeners: jest.fn(),
1414
setEnabled: jest.fn(),
1515
init: jest.fn(),
16+
setCodePushVersion: jest.fn(),
1617
setUserData: jest.fn(),
1718
setTrackUserSteps: jest.fn(),
1819
setIBGLogPrintsToConsole: jest.fn(),

test/modules/Instabug.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ describe('Instabug Module', () => {
257257
);
258258
});
259259

260+
it('setCodePushVersion should call native method setCodePushVersion', () => {
261+
const codePushVersion = '123';
262+
263+
Instabug.setCodePushVersion(codePushVersion);
264+
265+
expect(NativeInstabug.setCodePushVersion).toBeCalledTimes(1);
266+
expect(NativeInstabug.setCodePushVersion).toBeCalledWith(codePushVersion);
267+
});
268+
260269
it('init should disable JavaScript interceptor when using native interception mode', () => {
261270
const instabugConfig = {
262271
token: 'some-token',

0 commit comments

Comments
 (0)