Skip to content

Allow react-sdk to be passed in as clientEngine #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/optimizely-sdk/lib/index.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ module.exports = {
hasRetriedEvents = true;
}

config = fns.assignIn({}, config, {
eventDispatcher: wrappedEventDispatcher,
config = fns.assignIn({
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
}, config, {
eventDispatcher: wrappedEventDispatcher,
// always get the OptimizelyLogger facade from logging
logger: logger,
errorHandler: logging.getErrorHandler(),
Expand Down
26 changes: 26 additions & 0 deletions packages/optimizely-sdk/lib/index.browser.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ describe('javascript-sdk', function() {
assert.equal(packageJSON.version, optlyInstance.clientVersion);
});

it('should allow passing of "react-sdk" as the clientEngine', function() {
var optlyInstance = optimizelyFactory.createInstance({
clientEngine: 'react-sdk',
datafile: {},
errorHandler: fakeErrorHandler,
eventDispatcher: fakeEventDispatcher,
logger: silentLogger,
});
// Invalid datafile causes onReady Promise rejection - catch this error
optlyInstance.onReady().catch(function() {});
assert.equal('react-sdk', optlyInstance.clientEngine);
});

it('should allow passing of "react-sdk" as the clientEngine', function() {
var optlyInstance = optimizelyFactory.createInstance({
clientEngine: 'react-sdk',
datafile: {},
errorHandler: fakeErrorHandler,
eventDispatcher: fakeEventDispatcher,
logger: silentLogger,
});
// Invalid datafile causes onReady Promise rejection - catch this error
optlyInstance.onReady().catch(function() {});
assert.equal('react-sdk', optlyInstance.clientEngine);
});

it('should activate with provided event dispatcher', function() {
var optlyInstance = optimizelyFactory.createInstance({
datafile: testData.getTestProjectConfig(),
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ module.exports = {

config = fns.assign(
{
clientEngine: enums.NODE_CLIENT_ENGINE,
eventDispatcher: defaultEventDispatcher,
jsonSchemaValidator: jsonSchemaValidator,
skipJSONValidation: false,
},
config,
{
clientEngine: enums.NODE_CLIENT_ENGINE,
// always get the OptimizelyLogger facade from logging
logger: logger,
errorHandler: logging.getErrorHandler(),
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var DEFAULT_ONREADY_TIMEOUT = 30000;
*/
function Optimizely(config) {
var clientEngine = config.clientEngine;
if (clientEngine !== enums.NODE_CLIENT_ENGINE && clientEngine !== enums.JAVASCRIPT_CLIENT_ENGINE) {
if (enums.VALID_CLIENT_ENGINES.indexOf(clientEngine) === -1) {
config.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, MODULE_NAME, clientEngine));
clientEngine = enums.NODE_CLIENT_ENGINE;
}
Expand Down
12 changes: 12 additions & 0 deletions packages/optimizely-sdk/lib/optimizely/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ describe('lib/optimizely', function() {
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, 'OPTIMIZELY', 'undefined'));
});

it('should allow passing `react-sdk` as the clientEngine', function() {
var instance = new Optimizely({
clientEngine: 'react-sdk',
datafile: testData.getTestProjectConfig(),
errorHandler: stubErrorHandler,
eventDispatcher: stubEventDispatcher,
logger: createdLogger,
});

assert.strictEqual(instance.clientEngine, 'react-sdk');
});

describe('when a user profile service is provided', function() {
beforeEach(function() {
sinon.stub(decisionService, 'createDecisionService');
Expand Down
7 changes: 7 additions & 0 deletions packages/optimizely-sdk/lib/utils/enums/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,15 @@ exports.CONTROL_ATTRIBUTES = {

exports.JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk';
exports.NODE_CLIENT_ENGINE = 'node-sdk';
exports.REACT_CLIENT_ENGINE = 'react-sdk';
exports.NODE_CLIENT_VERSION = '3.2.0-beta';

exports.VALID_CLIENT_ENGINES = [
exports.NODE_CLIENT_ENGINE,
exports.REACT_CLIENT_ENGINE,
exports.JAVASCRIPT_CLIENT_ENGINE,
];

/*
* Notification types for use with NotificationCenter
* Format is EVENT: <list of parameters to callback>
Expand Down