Skip to content

Commit 47d2a71

Browse files
author
Matt Carroll
committed
Update project config: no longer assume that conditions of audiences in typedAudiences are strings.
1 parent 615d9da commit 47d2a71

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ module.exports = {
4040
fns.forEach(projectConfig.audiences, function(audience) {
4141
audience.conditions = JSON.parse(audience.conditions);
4242
});
43-
fns.forEach(projectConfig.typedAudiences, function(audience) {
44-
audience.conditions = JSON.parse(audience.conditions);
45-
});
43+
/*
44+
* Note: conditions of audiences in projectConfig.typedAudiences are not
45+
* expected to be string-encoded as they are in projectConfig.audiences.
46+
*/
4647
projectConfig.audiencesById = fns.keyBy(projectConfig.audiences, 'id');
4748
fns.assign(projectConfig.audiencesById, fns.keyBy(projectConfig.typedAudiences, 'id'));
4849

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)