Skip to content

fix (audiences): Update project config - no longer expect conditions of audiences in typedAudiences to be strings #182

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 2 commits into from
Nov 6, 2018
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
8 changes: 4 additions & 4 deletions packages/optimizely-sdk/lib/core/project_config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ module.exports = {
createProjectConfig: function(datafile) {
var projectConfig = fns.cloneDeep(datafile);

// Manually parsed for audience targeting
/*
* Conditions of audiences in projectConfig.typedAudiences are not
* expected to be string-encoded as they are here in projectConfig.audiences.
*/
fns.forEach(projectConfig.audiences, function(audience) {
audience.conditions = JSON.parse(audience.conditions);
});
fns.forEach(projectConfig.typedAudiences, function(audience) {
audience.conditions = JSON.parse(audience.conditions);
});
projectConfig.audiencesById = fns.keyBy(projectConfig.audiences, 'id');
fns.assign(projectConfig.audiencesById, fns.keyBy(projectConfig.typedAudiences, 'id'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ describe('lib/core/project_config', function() {
it('should retrieve audiences by checking first in typedAudiences, and then second in audiences', function() {
assert.deepEqual(
projectConfig.getAudiencesById(configObj),
testDatafile.parsedTypedAudiences
testDatafile.typedAudiencesById
);
});
});
Expand Down
16 changes: 8 additions & 8 deletions packages/optimizely-sdk/lib/tests/test_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2085,32 +2085,32 @@ var typedAudiencesConfig = {
{
'id': '3988293898',
'name': 'substringString',
'conditions': '["and", ["or", ["or", {"name": "house", "type": "custom_attribute", "match":"substring", "value":"Slytherin"}]]]'
'conditions': ['and', ['or', ['or', {'name': 'house', 'type': 'custom_attribute', 'match':'substring', 'value':'Slytherin'}]]]
},
{
'id': '3988293899',
'name': 'exists',
'conditions': '["and", ["or", ["or", {"name": "favorite_ice_cream", "type": "custom_attribute", "match":"exists"}]]]'
'conditions': ['and', ['or', ['or', {'name': 'favorite_ice_cream', 'type': 'custom_attribute', 'match':'exists'}]]]
},
{
'id': '3468206646',
'name': 'exactNumber',
'conditions': '["and", ["or", ["or", {"name": "lasers", "type": "custom_attribute", "match":"exact", "value": 45.5}]]]'
'conditions': ['and', ['or', ['or', {'name': 'lasers', 'type': 'custom_attribute', 'match':'exact', 'value': 45.5}]]]
},
{
'id': '3468206647',
'name': 'gtNumber',
'conditions': '["and", ["or", ["or", {"name": "lasers", "type": "custom_attribute", "match":"gt", "value": 70 }]]]'
'conditions': ['and', ['or', ['or', {'name': 'lasers', 'type': 'custom_attribute', 'match':'gt', 'value': 70 }]]]
},
{
'id': '3468206644',
'name': 'ltNumber',
'conditions': '["and", ["or", ["or", {"name": "lasers", "type": "custom_attribute", "match":"lt", "value": 1.0 }]]]'
'conditions': ['and', ['or', ['or', {'name': 'lasers', 'type': 'custom_attribute', 'match':'lt', 'value': 1.0 }]]]
},
{
'id': '3468206643',
'name': 'exactBoolean',
'conditions': '["and", ["or", ["or", {"name": "should_do_it", "type": "custom_attribute", "match":"exact", "value": true}]]]'
'conditions': ['and', ['or', ['or', {'name': 'should_do_it', 'type': 'custom_attribute', 'match':'exact', 'value': true}]]]
}
],
'groups': [],
Expand Down Expand Up @@ -2156,7 +2156,7 @@ var getTypedAudiencesConfig = function() {
return cloneDeep(typedAudiencesConfig);
};

var parsedTypedAudiences = {
var typedAudiencesById = {
3468206642: {
'id': '3468206642',
'name': 'exactString',
Expand Down Expand Up @@ -2206,5 +2206,5 @@ module.exports = {
datafileWithFeaturesExpectedData: datafileWithFeaturesExpectedData,
getUnsupportedVersionConfig: getUnsupportedVersionConfig,
getTypedAudiencesConfig: getTypedAudiencesConfig,
parsedTypedAudiences: parsedTypedAudiences,
typedAudiencesById: typedAudiencesById,
};