Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 2ac685b

Browse files
authored
feat: Added React Native Client Engines to be sent in events (optimizely#435)
## Summary Added Two new client engine values to be sent in events. #### react-native-js Client Engine will be set to `react-native-js` when a react native application will use javascript sdk directly #### react-native Client Engine will be set to `react-native` when a react native application will use react sdk #### Client Versions Client versions behave correctly without any change. Current behaviour is. 1. When a react native app uses javascript SDK directly, clientVersion will be the version of javascript SDK. Which means `react-native-js` goes with `clientVersion` of javascript SDK 2. When a react native app uses React SDK, clientVersion will be the version passed in by react SDK. This means `react-native` goes with `clientVersion` of react SDK. ## Test plan Made appropriate changes to already existing unit tests.
1 parent 645ea8a commit 2ac685b

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

packages/optimizely-sdk/lib/index.react_native.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module.exports = {
8888

8989
config = fns.assign(
9090
{
91-
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
91+
clientEngine: enums.REACT_NATIVE_JS_CLIENT_ENGINE,
9292
eventBatchSize: DEFAULT_EVENT_BATCH_SIZE,
9393
eventDispatcher: defaultEventDispatcher,
9494
eventFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
@@ -101,6 +101,11 @@ module.exports = {
101101
}
102102
);
103103

104+
// If client engine is react, convert it to react native
105+
if (config.clientEngine === enums.REACT_CLIENT_ENGINE) {
106+
config.clientEngine = enums.REACT_NATIVE_CLIENT_ENGINE
107+
}
108+
104109
if (!eventProcessorConfigValidator.validateEventBatchSize(config.eventBatchSize)) {
105110
logger.warn('Invalid eventBatchSize %s, defaulting to %s', config.eventBatchSize, DEFAULT_EVENT_BATCH_SIZE);
106111
config.eventBatchSize = DEFAULT_EVENT_BATCH_SIZE;

packages/optimizely-sdk/lib/index.react_native.tests.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('javascript-sdk/react-native', function() {
9595
assert.equal(optlyInstance.clientVersion, '3.6.0-alpha.1');
9696
});
9797

98-
it('should set the JavaScript client engine and version', function() {
98+
it('should set the React Native JS client engine and javascript SDK version', function() {
9999
var optlyInstance = optimizelyFactory.createInstance({
100100
datafile: {},
101101
errorHandler: fakeErrorHandler,
@@ -104,11 +104,11 @@ describe('javascript-sdk/react-native', function() {
104104
});
105105
// Invalid datafile causes onReady Promise rejection - catch this error
106106
optlyInstance.onReady().catch(function() {});
107-
assert.equal('javascript-sdk', optlyInstance.clientEngine);
107+
assert.equal('react-native-js-sdk', optlyInstance.clientEngine);
108108
assert.equal(packageJSON.version, optlyInstance.clientVersion);
109109
});
110110

111-
it('should allow passing of "react-sdk" as the clientEngine', function() {
111+
it('should allow passing of "react-sdk" as the clientEngine and convert it to "react-native-sdk"', function() {
112112
var optlyInstance = optimizelyFactory.createInstance({
113113
clientEngine: 'react-sdk',
114114
datafile: {},
@@ -118,7 +118,7 @@ describe('javascript-sdk/react-native', function() {
118118
});
119119
// Invalid datafile causes onReady Promise rejection - catch this error
120120
optlyInstance.onReady().catch(function() {});
121-
assert.equal('react-sdk', optlyInstance.clientEngine);
121+
assert.equal('react-native-sdk', optlyInstance.clientEngine);
122122
});
123123

124124
it('should activate with provided event dispatcher', function() {

packages/optimizely-sdk/lib/utils/enums/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,16 @@ exports.CONTROL_ATTRIBUTES = {
174174
exports.JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk';
175175
exports.NODE_CLIENT_ENGINE = 'node-sdk';
176176
exports.REACT_CLIENT_ENGINE = 'react-sdk';
177+
exports.REACT_NATIVE_CLIENT_ENGINE = 'react-native-sdk';
178+
exports.REACT_NATIVE_JS_CLIENT_ENGINE = 'react-native-js-sdk';
177179
exports.NODE_CLIENT_VERSION = '3.6.0-alpha.1';
178180

179181
exports.VALID_CLIENT_ENGINES = [
180182
exports.NODE_CLIENT_ENGINE,
181183
exports.REACT_CLIENT_ENGINE,
182184
exports.JAVASCRIPT_CLIENT_ENGINE,
185+
exports.REACT_NATIVE_CLIENT_ENGINE,
186+
exports.REACT_NATIVE_JS_CLIENT_ENGINE,
183187
];
184188

185189
exports.NOTIFICATION_TYPES = jsSdkUtils.NOTIFICATION_TYPES;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/****************************************************************************
2+
* Copyright 2020, Optimizely, Inc. and contributors *
3+
* *
4+
* Licensed under the Apache License, Version 2.0 (the "License"); *
5+
* you may not use this file except in compliance with the License. *
6+
* You may obtain a copy of the License at *
7+
* *
8+
* http://www.apache.org/licenses/LICENSE-2.0 *
9+
* *
10+
* Unless required by applicable law or agreed to in writing, software *
11+
* distributed under the License is distributed on an "AS IS" BASIS, *
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13+
* See the License for the specific language governing permissions and *
14+
* limitations under the License. *
15+
***************************************************************************/
16+
17+
var chai = require('chai')
18+
var enums = require('./')
19+
var assert = chai.assert;
20+
21+
describe('lib/utils/enums', function() {
22+
describe('valid client engines', function() {
23+
it('all valid client engines should end with "-sdk"', function() {
24+
enums.VALID_CLIENT_ENGINES.forEach(function(clientEngine) {
25+
assert.isTrue(clientEngine.endsWith('-sdk'))
26+
});
27+
});
28+
});
29+
});

0 commit comments

Comments
 (0)