Skip to content

feat(log event notification): Update event processor version & pass notificationCenter to event processor #345

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 6 commits into from
Aug 15, 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
1 change: 1 addition & 0 deletions packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function Optimizely(config) {
dispatcher: this.eventDispatcher,
flushInterval: config.eventFlushInterval !== undefined ? config.eventFlushInterval : DEFAULT_EVENT_FLUSH_INTERVAL,
maxQueueSize: config.eventBatchSize !== undefined ? config.eventBatchSize : DEFAULT_EVENT_MAX_QUEUE_SIZE,
notificationCenter: this.notificationCenter,
});
this.eventProcessor.start();

Expand Down
65 changes: 61 additions & 4 deletions packages/optimizely-sdk/lib/optimizely/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5607,11 +5607,11 @@ describe('lib/optimizely', function() {
isValidInstance: true,
});

sinon.assert.calledWithExactly(eventProcessor.LogTierV1EventProcessor, {
sinon.assert.calledWithExactly(eventProcessor.LogTierV1EventProcessor, sinon.match({
dispatcher: eventDispatcher,
flushInterval: 5000,
maxQueueSize: 1,
});
}));
});
});

Expand All @@ -5629,11 +5629,11 @@ describe('lib/optimizely', function() {
eventBatchSize: 100,
});

sinon.assert.calledWithExactly(eventProcessor.LogTierV1EventProcessor, {
sinon.assert.calledWithExactly(eventProcessor.LogTierV1EventProcessor, sinon.match({
dispatcher: eventDispatcher,
flushInterval: 50,
maxQueueSize: 100,
});
}));
});
});
});
Expand Down Expand Up @@ -5939,4 +5939,61 @@ describe('lib/optimizely', function() {
});
});
});

describe('log event notification', function() {
var optlyInstance;
var bucketStub;
var eventDispatcherSpy;
beforeEach(function() {
bucketStub = sinon.stub(bucketer, 'bucket');
eventDispatcherSpy = sinon.spy();
optlyInstance = new Optimizely({
clientEngine: 'node-sdk',
datafile: testData.getTestProjectConfig(),
eventBuilder: eventBuilder,
errorHandler: {
handleError: function() {},
},
eventDispatcher: {
dispatchEvent: eventDispatcherSpy,
},
logger: {
log: function() {},
},
isValidInstance: true,
eventBatchSize: 1,
});
});

afterEach(function() {
bucketer.bucket.restore();
optlyInstance.close();
});

it('should trigger a log event notification when an impression event is dispatched', function() {
var notificationListener = sinon.spy();
optlyInstance.notificationCenter.addNotificationListener(
enums.NOTIFICATION_TYPES.LOG_EVENT,
notificationListener
);
bucketStub.returns('111129');
var activate = optlyInstance.activate('testExperiment', 'testUser');
assert.strictEqual(activate, 'variation');
sinon.assert.calledOnce(eventDispatcherSpy);
sinon.assert.calledOnce(notificationListener);
sinon.assert.calledWithExactly(notificationListener, eventDispatcherSpy.getCall(0).args[0]);
});

it('should trigger a log event notification when a conversion event is dispatched', function() {
var notificationListener = sinon.spy();
optlyInstance.notificationCenter.addNotificationListener(
enums.NOTIFICATION_TYPES.LOG_EVENT,
notificationListener
);
optlyInstance.track('testEvent', 'testUser');
sinon.assert.calledOnce(eventDispatcherSpy);
sinon.assert.calledOnce(notificationListener);
sinon.assert.calledWithExactly(notificationListener, eventDispatcherSpy.getCall(0).args[0]);
});
});
});
44 changes: 3 additions & 41 deletions packages/optimizely-sdk/lib/utils/enums/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License. *
***************************************************************************/

var jsSdkUtils = require('@optimizely/js-sdk-utils');

/**
* Contains global enums used throughout the library
*/
Expand Down Expand Up @@ -164,47 +166,7 @@ exports.VALID_CLIENT_ENGINES = [
exports.JAVASCRIPT_CLIENT_ENGINE,
];

/*
* Notification types for use with NotificationCenter
* Format is EVENT: <list of parameters to callback>
*
* SDK consumers can use these to register callbacks with the notification center.
*
* @deprecated since 3.1.0
* ACTIVATE: An impression event will be sent to Optimizely
* Callbacks will receive an object argument with the following properties:
* - experiment {Object}
* - userId {string}
* - attributes {Object|undefined}
* - variation {Object}
* - logEvent {Object}
*
* DECISION: A decision is made in the system. i.e. user activation,
* feature access or feature-variable value retrieval
* Callbacks will receive an object argument with the following properties:
* - type {string}
* - userId {string}
* - attributes {Object|undefined}
* - decisionInfo {Object|undefined}
*
* OPTIMIZELY_CONFIG_UPDATE: This Optimizely instance has been updated with a new
* config
*
* TRACK: A conversion event will be sent to Optimizely
* Callbacks will receive the an object argument with the following properties:
* - eventKey {string}
* - userId {string}
* - attributes {Object|undefined}
* - eventTags {Object|undefined}
* - logEvent {Object}
*
*/
exports.NOTIFICATION_TYPES = {
ACTIVATE: 'ACTIVATE:experiment, user_id,attributes, variation, event',
DECISION: 'DECISION:type, userId, attributes, decisionInfo',
OPTIMIZELY_CONFIG_UPDATE: 'OPTIMIZELY_CONFIG_UPDATE',
TRACK: 'TRACK:event_key, user_id, attributes, event_tags, event',
};
exports.NOTIFICATION_TYPES = jsSdkUtils.NOTIFICATION_TYPES;

exports.DECISION_NOTIFICATION_TYPES = {
AB_TEST: 'ab-test',
Expand Down
34 changes: 27 additions & 7 deletions packages/optimizely-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/optimizely-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"homepage": "https://github.com/optimizely/javascript-sdk/tree/master/packages/optimizely-sdk",
"dependencies": {
"@optimizely/js-sdk-datafile-manager": "^0.4.0",
"@optimizely/js-sdk-event-processor": "^0.2.1",
"@optimizely/js-sdk-event-processor": "^0.3.0",
"@optimizely/js-sdk-logging": "^0.1.0",
"@optimizely/js-sdk-utils": "^0.1.0",
"@optimizely/js-sdk-utils": "^0.2.0",
"json-schema": "^0.2.3",
"lodash": "^4.17.11",
"murmurhash": "0.0.2",
Expand Down