Skip to content

feat(api): Decision Notification Listener for activate and getVariation APIs. #244

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
Mar 14, 2019

Conversation

mfahadahmed
Copy link
Contributor

Summary

  • Implemented onDecisionListener in activate and getVariation APIs.

Test plan

  • Added unit tests.

@coveralls
Copy link

coveralls commented Mar 8, 2019

Coverage Status

Coverage increased (+0.01%) to 97.663% when pulling 7f3c0a8 on fahad/on-decision-listener-activate into 553e6ff on master.

@@ -392,14 +395,30 @@ describe('lib/optimizely', function() {
});

describe('#activate', function() {
it('should call bucketer and dispatchEvent with proper args and return variation key', function() {
it('should call bucketer, send notifications and dispatchEvent with proper args and return variation key', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets split this test up, please add a new #activate for these notification center tests.

it's important to keep the base case of these tests without notificationCenter.

Copy link
Contributor

@jordangarcia jordangarcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate the tests up and don't change the current enums.NOTIFICATION_TYPES

ACTIVATE: 'ACTIVATE:experiment, user_id,attributes, variation, event',
TRACK: 'TRACK:event_key, user_id, attributes, event_tags, event',
ACTIVATE: 'ACTIVATE:experiment, userId, attributes, variation, logEvent',
TRACK: 'TRACK:eventKey, userId, attributes, eventTags, logEvent',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't change these enums, customers are already using them.

Please revert the NOTIFICATION_TYPES back to the way they were and make them use snake_case

Copy link
Contributor

@jordangarcia jordangarcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need to change the attributes to default to {} when not supplied, then LGTM

sinon.assert.calledWith(onDecisionListener, {
type: DECISION_INFO_TYPES.EXPERIMENT,
userId: 'testUser',
attributes: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this listener should be called with attributes: {} even if no attributes are provided.

Please change the logic where you send the notification

{
type: DECISION_INFO_TYPES.EXPERIMENT,
userId: userId,
attributes: attributes,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linking to comment below, this should default to empty object if attribute isn't passed through

attributes: attributes || {},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done for decision listener. I just want to confirm that should we change it for activate and track listeners also?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed with Ali, for Decision Listener it's fine.

@@ -2287,7 +2288,7 @@ describe('lib/optimizely', function() {
browser_type: 'firefox',
};
optlyInstance.notificationCenter.addNotificationListener(
enums.NOTIFICATION_TYPES.ACTIVATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why make this change. It seems we are pretty consistent about using enums.XXX

Please change it back since this seems unnecessary and not the conventional way we access enums.

@mfahadahmed mfahadahmed changed the title feat(api): OnDecision Notification Listener for activate and getVariation APIs. feat(api): Decision Notification Listener for activate and getVariation APIs. Mar 13, 2019
@aliabbasrizvi
Copy link
Contributor

LGTM. @jordangarcia may want to take another look.

*/
exports.NOTIFICATION_TYPES = {
ACTIVATE: 'ACTIVATE:experiment, user_id,attributes, variation, event',
TRACK: 'TRACK:event_key, user_id, attributes, event_tags, event',
ON_DECISION: 'ON_DECISION:type, userId, attributes, decisionInfo',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to feedback in other PR. This should be DECISION and not ON_DECISION.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it has already been renamed. Please see the latest changes.

Copy link
Contributor

@jordangarcia jordangarcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@aliabbasrizvi aliabbasrizvi merged commit 1edba1f into master Mar 14, 2019
@aliabbasrizvi aliabbasrizvi deleted the fahad/on-decision-listener-activate branch March 14, 2019 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants