Skip to content

Commit

Permalink
Merge branch 'master' into raju/universal_entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
raju-opti authored Feb 25, 2025
2 parents 1f43271 + 2089d96 commit 46994a5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/project_config/project_config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,34 @@ describe('createProjectConfig - flag variations', () => {
});
});

describe('createProjectConfig - cmab experiments', () => {
it('should populate cmab field correctly', function() {
const datafile = testDatafile.getTestProjectConfig();
datafile.experiments[0].cmab = {
attributes: ['808797688', '808797689'],
};

datafile.experiments[2].cmab = {
attributes: ['808797689'],
};

const configObj = projectConfig.createProjectConfig(datafile);

const experiment0 = configObj.experiments[0];
expect(experiment0.cmab).toEqual({
attributeIds: ['808797688', '808797689'],
});

const experiment1 = configObj.experiments[1];
expect(experiment1.cmab).toBeUndefined();

const experiment2 = configObj.experiments[2];
expect(experiment2.cmab).toEqual({
attributeIds: ['808797689'],
});
});
});

describe('getExperimentId', () => {
let testData: Record<string, any>;
let configObj: ProjectConfig;
Expand Down
10 changes: 10 additions & 0 deletions lib/project_config/project_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const RESERVED_ATTRIBUTE_PREFIX = '$opt_';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
const datafileCopy = { ...datafile };

datafileCopy.audiences = (datafile.audiences || []).map((audience: Audience) => {
return { ...audience };
});
Expand Down Expand Up @@ -155,6 +156,15 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str

projectConfig.__datafileStr = datafileStr === null ? JSON.stringify(datafileObj) : datafileStr;

/** rename cmab.attributes field from the datafile to cmab.attributeIds for each experiment */
projectConfig.experiments.forEach(experiment => {
if (experiment.cmab) {
const attributes = (experiment.cmab as any).attributes;
delete (experiment.cmab as any).attributes;
experiment.cmab.attributeIds = attributes;
}
});

/*
* Conditions of audiences in projectConfig.typedAudiences are not
* expected to be string-encoded as they are here in projectConfig.audiences.
Expand Down
13 changes: 13 additions & 0 deletions lib/project_config/project_config_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ var schemaDefinition = {
type: 'object',
required: true,
},
cmab: {
type: 'object',
required: false,
properties: {
attributes: {
type: 'array',
items: {
type: 'string',
},
required: true,
}
}
}
},
},
required: true,
Expand Down
3 changes: 3 additions & 0 deletions lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export interface Experiment {
trafficAllocation: TrafficAllocation[];
forcedVariations?: { [key: string]: string };
isRollout?: boolean;
cmab?: {
attributeIds: string[];
};
}

export enum VariableType {
Expand Down

0 comments on commit 46994a5

Please sign in to comment.