Skip to content

Commit 4c49bc4

Browse files
authored
fix (audiences): Update project config - no longer expect conditions of audiences in typedAudiences to be strings (#182)
Summary: Update project config to handle the latest datafile format for 3.0 with typed audience evaluation. conditions properties of objects in typedAudiences will be Arrays, and no longer JSON-strings. Test Plan: Updated typed audiences datafile in test data to the latest format. Existing tests should pass - no change in behavior.
1 parent f0b45d5 commit 4c49bc4

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

packages/optimizely-sdk/lib/core/project_config/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ module.exports = {
3636
createProjectConfig: function(datafile) {
3737
var projectConfig = fns.cloneDeep(datafile);
3838

39-
// Manually parsed for audience targeting
39+
/*
40+
* Conditions of audiences in projectConfig.typedAudiences are not
41+
* expected to be string-encoded as they are here in projectConfig.audiences.
42+
*/
4043
fns.forEach(projectConfig.audiences, function(audience) {
4144
audience.conditions = JSON.parse(audience.conditions);
4245
});
43-
fns.forEach(projectConfig.typedAudiences, function(audience) {
44-
audience.conditions = JSON.parse(audience.conditions);
45-
});
4646
projectConfig.audiencesById = fns.keyBy(projectConfig.audiences, 'id');
4747
fns.assign(projectConfig.audiencesById, fns.keyBy(projectConfig.typedAudiences, 'id'));
4848

packages/optimizely-sdk/lib/core/project_config/index.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ describe('lib/core/project_config', function() {
529529
it('should retrieve audiences by checking first in typedAudiences, and then second in audiences', function() {
530530
assert.deepEqual(
531531
projectConfig.getAudiencesById(configObj),
532-
testDatafile.parsedTypedAudiences
532+
testDatafile.typedAudiencesById
533533
);
534534
});
535535
});

packages/optimizely-sdk/lib/tests/test_data.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,32 +2085,32 @@ var typedAudiencesConfig = {
20852085
{
20862086
'id': '3988293898',
20872087
'name': 'substringString',
2088-
'conditions': '["and", ["or", ["or", {"name": "house", "type": "custom_attribute", "match":"substring", "value":"Slytherin"}]]]'
2088+
'conditions': ['and', ['or', ['or', {'name': 'house', 'type': 'custom_attribute', 'match':'substring', 'value':'Slytherin'}]]]
20892089
},
20902090
{
20912091
'id': '3988293899',
20922092
'name': 'exists',
2093-
'conditions': '["and", ["or", ["or", {"name": "favorite_ice_cream", "type": "custom_attribute", "match":"exists"}]]]'
2093+
'conditions': ['and', ['or', ['or', {'name': 'favorite_ice_cream', 'type': 'custom_attribute', 'match':'exists'}]]]
20942094
},
20952095
{
20962096
'id': '3468206646',
20972097
'name': 'exactNumber',
2098-
'conditions': '["and", ["or", ["or", {"name": "lasers", "type": "custom_attribute", "match":"exact", "value": 45.5}]]]'
2098+
'conditions': ['and', ['or', ['or', {'name': 'lasers', 'type': 'custom_attribute', 'match':'exact', 'value': 45.5}]]]
20992099
},
21002100
{
21012101
'id': '3468206647',
21022102
'name': 'gtNumber',
2103-
'conditions': '["and", ["or", ["or", {"name": "lasers", "type": "custom_attribute", "match":"gt", "value": 70 }]]]'
2103+
'conditions': ['and', ['or', ['or', {'name': 'lasers', 'type': 'custom_attribute', 'match':'gt', 'value': 70 }]]]
21042104
},
21052105
{
21062106
'id': '3468206644',
21072107
'name': 'ltNumber',
2108-
'conditions': '["and", ["or", ["or", {"name": "lasers", "type": "custom_attribute", "match":"lt", "value": 1.0 }]]]'
2108+
'conditions': ['and', ['or', ['or', {'name': 'lasers', 'type': 'custom_attribute', 'match':'lt', 'value': 1.0 }]]]
21092109
},
21102110
{
21112111
'id': '3468206643',
21122112
'name': 'exactBoolean',
2113-
'conditions': '["and", ["or", ["or", {"name": "should_do_it", "type": "custom_attribute", "match":"exact", "value": true}]]]'
2113+
'conditions': ['and', ['or', ['or', {'name': 'should_do_it', 'type': 'custom_attribute', 'match':'exact', 'value': true}]]]
21142114
}
21152115
],
21162116
'groups': [],
@@ -2156,7 +2156,7 @@ var getTypedAudiencesConfig = function() {
21562156
return cloneDeep(typedAudiencesConfig);
21572157
};
21582158

2159-
var parsedTypedAudiences = {
2159+
var typedAudiencesById = {
21602160
3468206642: {
21612161
'id': '3468206642',
21622162
'name': 'exactString',
@@ -2206,5 +2206,5 @@ module.exports = {
22062206
datafileWithFeaturesExpectedData: datafileWithFeaturesExpectedData,
22072207
getUnsupportedVersionConfig: getUnsupportedVersionConfig,
22082208
getTypedAudiencesConfig: getTypedAudiencesConfig,
2209-
parsedTypedAudiences: parsedTypedAudiences,
2209+
typedAudiencesById: typedAudiencesById,
22102210
};

0 commit comments

Comments
 (0)