Skip to content

Commit 466dc88

Browse files
committed
handle undefined include and exclude flags
1 parent 5436b87 commit 466dc88

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/project_config/project_config.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,18 @@ describe('createProjectConfig - holdouts, feature toggle is on', () => {
442442
expect(configObj.excludedHoldouts).toEqual({});
443443
expect(configObj.flagHoldoutsMap).toEqual({});
444444
});
445+
446+
it('should handle undefined includeFlags and excludeFlags in holdout', function() {
447+
const datafile = getHoldoutDatafile();
448+
datafile.holdouts[0].includeFlags = undefined;
449+
datafile.holdouts[0].excludeFlags = undefined;
450+
451+
const configObj = projectConfig.createProjectConfig(JSON.parse(JSON.stringify(datafile)));
452+
453+
expect(configObj.holdouts).toHaveLength(3);
454+
expect(configObj.holdouts[0].includeFlags).toEqual([]);
455+
expect(configObj.holdouts[0].excludeFlags).toEqual([]);
456+
});
445457
});
446458

447459
describe('getHoldoutsForFlag: feature toggle is on', () => {

lib/project_config/project_config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ const parseHoldoutsConfig = (projectConfig: ProjectConfig): void => {
361361
projectConfig.flagHoldoutsMap = {};
362362

363363
projectConfig.holdouts.forEach((holdout) => {
364+
if (!holdout.includeFlags) {
365+
holdout.includeFlags = [];
366+
}
367+
368+
if (!holdout.excludeFlags) {
369+
holdout.excludeFlags = [];
370+
}
371+
364372
holdout.variationKeyMap = keyBy(holdout.variations, 'key');
365373
if (holdout.includeFlags.length === 0) {
366374
projectConfig.globalHoldouts.push(holdout);

0 commit comments

Comments
 (0)