Skip to content

[FSSDK-8475] ODP Integration for Optimizely Client and User Context (Browser) #799

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 7 commits into from
Mar 9, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ dist/
# user-specific ignores ought to be defined in user's `core.excludesfile`
.idea/*
.DS_STORE

browserstack.err
local.log
3 changes: 2 additions & 1 deletion packages/optimizely-sdk/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
"uuid": require.resolve('uuid'),
},
"testPathIgnorePatterns" : [
"tests/testUtils.ts"
"tests/testUtils.ts",
"dist"
],
"moduleFileExtensions": [
"ts",
Expand Down
39 changes: 39 additions & 0 deletions packages/optimizely-sdk/lib/core/decision_service/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('lib/core/decision_service', function() {
describe('#getVariation', function() {
it('should return the correct variation for the given experiment key and user ID for a running experiment', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'tester'
});
Expand All @@ -86,6 +87,7 @@ describe('lib/core/decision_service', function() {

it('should return the whitelisted variation if the user is whitelisted', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user2'
});
Expand All @@ -108,6 +110,7 @@ describe('lib/core/decision_service', function() {

it('should return null if the user does not meet audience conditions', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user3'
});
Expand Down Expand Up @@ -136,6 +139,7 @@ describe('lib/core/decision_service', function() {

it('should return null if the experiment is not running', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1'
});
Expand Down Expand Up @@ -165,6 +169,7 @@ describe('lib/core/decision_service', function() {
},
};
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
attributes,
Expand Down Expand Up @@ -222,6 +227,7 @@ describe('lib/core/decision_service', function() {
});
experiment = configObj.experimentIdMap['111127'];
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
});
Expand Down Expand Up @@ -250,6 +256,7 @@ describe('lib/core/decision_service', function() {
});
experiment = configObj.experimentIdMap['111127'];
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
});
Expand All @@ -276,6 +283,7 @@ describe('lib/core/decision_service', function() {
userProfileLookupStub.returns(null);
experiment = configObj.experimentIdMap['111127'];
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
});
Expand Down Expand Up @@ -308,6 +316,7 @@ describe('lib/core/decision_service', function() {
});
experiment = configObj.experimentIdMap['111127'];
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
});
Expand Down Expand Up @@ -343,6 +352,7 @@ describe('lib/core/decision_service', function() {
experiment_bucket_map: {}, // no decisions for user
});
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
});
Expand Down Expand Up @@ -378,6 +388,7 @@ describe('lib/core/decision_service', function() {
userProfileLookupStub.throws(new Error('I am an error'));
experiment = configObj.experimentIdMap['111127'];
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
});
Expand All @@ -403,6 +414,7 @@ describe('lib/core/decision_service', function() {
userProfileSaveStub.throws(new Error('I am an error'));
experiment = configObj.experimentIdMap['111127'];
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
});
Expand Down Expand Up @@ -456,6 +468,7 @@ describe('lib/core/decision_service', function() {
experiment = configObj.experimentIdMap['111127'];

user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
attributes,
Expand Down Expand Up @@ -500,6 +513,7 @@ describe('lib/core/decision_service', function() {
};

user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
attributes,
Expand Down Expand Up @@ -544,6 +558,7 @@ describe('lib/core/decision_service', function() {
};

user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
attributes,
Expand Down Expand Up @@ -579,6 +594,7 @@ describe('lib/core/decision_service', function() {
};

user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'decision_service_user',
attributes,
Expand Down Expand Up @@ -1146,6 +1162,7 @@ describe('lib/core/decision_service', function() {
},
});
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'test_user',
attributes: userAttributesWithBucketingId,
Expand Down Expand Up @@ -1248,6 +1265,7 @@ describe('lib/core/decision_service', function() {
var experiment;
beforeEach(function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: {
Expand Down Expand Up @@ -1489,6 +1507,7 @@ describe('lib/core/decision_service', function() {
var getVariationStub;
beforeEach(function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
});
Expand Down Expand Up @@ -1523,6 +1542,7 @@ describe('lib/core/decision_service', function() {
var user;
beforeEach(function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
});
Expand Down Expand Up @@ -1583,6 +1603,7 @@ describe('lib/core/decision_service', function() {
var user;
beforeEach(function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
});
Expand Down Expand Up @@ -1642,6 +1663,7 @@ describe('lib/core/decision_service', function() {

it('returns a decision with a variation and experiment from the audience targeting rule', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { test_attribute: 'test_value' },
Expand Down Expand Up @@ -1778,6 +1800,7 @@ describe('lib/core/decision_service', function() {

it('returns a decision with a variation and experiment from the everyone else targeting rule', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: {},
Expand Down Expand Up @@ -1913,6 +1936,7 @@ describe('lib/core/decision_service', function() {

it('returns a decision with no variation, no experiment and source rollout', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
});
Expand Down Expand Up @@ -1960,6 +1984,7 @@ describe('lib/core/decision_service', function() {

it('returns a decision with a variation and experiment from the everyone else targeting rule', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { test_attribute: 'test_value' }
Expand Down Expand Up @@ -2109,6 +2134,7 @@ describe('lib/core/decision_service', function() {
// No attributes passed to the user context, so user is not in the audience for the experiment
// It should fall through to the rollout
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1'
});
Expand Down Expand Up @@ -2203,6 +2229,7 @@ describe('lib/core/decision_service', function() {

it('returns a decision with no variation, no experiment and source rollout', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1'
});
Expand Down Expand Up @@ -2239,6 +2266,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with a variation in mutex group bucket less than 2500', function() {
generateBucketValueStub.returns(2400);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment' }
Expand Down Expand Up @@ -2268,6 +2296,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with a variation in mutex group bucket range 2500 to 5000', function() {
generateBucketValueStub.returns(4000);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment' }
Expand Down Expand Up @@ -2297,6 +2326,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with a variation in mutex group bucket range 5000 to 7500', function() {
generateBucketValueStub.returns(6500);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment' }
Expand Down Expand Up @@ -2326,6 +2356,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with variation and source rollout in mutex group bucket greater than 7500', function() {
generateBucketValueStub.returns(8000);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment' }
Expand Down Expand Up @@ -2373,6 +2404,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with variation for rollout in mutex group with audience mismatch', function() {
generateBucketValueStub.returns(2400);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment_invalid' }
Expand Down Expand Up @@ -2429,6 +2461,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with a variation in mutex group bucket less than 2500', function() {
generateBucketValueStub.returns(2400);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment' }
Expand Down Expand Up @@ -2459,6 +2492,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with a variation in mutex group bucket range 2500 to 5000', function() {
generateBucketValueStub.returns(4000);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment' }
Expand Down Expand Up @@ -2489,6 +2523,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with a variation in mutex group bucket range 5000 to 7500', function() {
generateBucketValueStub.returns(6500);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment' }
Expand Down Expand Up @@ -2519,6 +2554,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with variation and source rollout in mutex group bucket greater than 7500', function() {
generateBucketValueStub.returns(8000);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment' }
Expand Down Expand Up @@ -2566,6 +2602,7 @@ describe('lib/core/decision_service', function() {
it('returns a decision with variation for rollout in mutex group bucket range 2500 to 5000', function() {
generateBucketValueStub.returns(4000);
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'user1',
attributes: { experiment_attr: 'group_experiment_invalid' }
Expand Down Expand Up @@ -2634,6 +2671,7 @@ describe('lib/core/decision_service', function() {

it('should call buildBucketerParams with user Id when bucketing Id is not provided in the attributes', function() {
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'testUser',
attributes: { test_attribute: 'test_value' }
Expand All @@ -2651,6 +2689,7 @@ describe('lib/core/decision_service', function() {
$opt_bucketing_id: 'abcdefg',
};
user = new OptimizelyUserContext({
shouldIdentifyUser: false,
optimizely: {},
userId: 'testUser',
attributes,
Expand Down
Loading