Skip to content

Commit 2089d96

Browse files
authored
[FSSDK-11124] add cmab experiment properties to project config (#1009)
1 parent cf595be commit 2089d96

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

lib/project_config/project_config.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,34 @@ describe('createProjectConfig - flag variations', () => {
252252
});
253253
});
254254

255+
describe('createProjectConfig - cmab experiments', () => {
256+
it('should populate cmab field correctly', function() {
257+
const datafile = testDatafile.getTestProjectConfig();
258+
datafile.experiments[0].cmab = {
259+
attributes: ['808797688', '808797689'],
260+
};
261+
262+
datafile.experiments[2].cmab = {
263+
attributes: ['808797689'],
264+
};
265+
266+
const configObj = projectConfig.createProjectConfig(datafile);
267+
268+
const experiment0 = configObj.experiments[0];
269+
expect(experiment0.cmab).toEqual({
270+
attributeIds: ['808797688', '808797689'],
271+
});
272+
273+
const experiment1 = configObj.experiments[1];
274+
expect(experiment1.cmab).toBeUndefined();
275+
276+
const experiment2 = configObj.experiments[2];
277+
expect(experiment2.cmab).toEqual({
278+
attributeIds: ['808797689'],
279+
});
280+
});
281+
});
282+
255283
describe('getExperimentId', () => {
256284
let testData: Record<string, any>;
257285
let configObj: ProjectConfig;

lib/project_config/project_config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const RESERVED_ATTRIBUTE_PREFIX = '$opt_';
114114
// eslint-disable-next-line @typescript-eslint/no-explicit-any
115115
function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
116116
const datafileCopy = { ...datafile };
117+
117118
datafileCopy.audiences = (datafile.audiences || []).map((audience: Audience) => {
118119
return { ...audience };
119120
});
@@ -155,6 +156,15 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
155156

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

159+
/** rename cmab.attributes field from the datafile to cmab.attributeIds for each experiment */
160+
projectConfig.experiments.forEach(experiment => {
161+
if (experiment.cmab) {
162+
const attributes = (experiment.cmab as any).attributes;
163+
delete (experiment.cmab as any).attributes;
164+
experiment.cmab.attributeIds = attributes;
165+
}
166+
});
167+
158168
/*
159169
* Conditions of audiences in projectConfig.typedAudiences are not
160170
* expected to be string-encoded as they are here in projectConfig.audiences.

lib/project_config/project_config_schema.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ var schemaDefinition = {
202202
type: 'object',
203203
required: true,
204204
},
205+
cmab: {
206+
type: 'object',
207+
required: false,
208+
properties: {
209+
attributes: {
210+
type: 'array',
211+
items: {
212+
type: 'string',
213+
},
214+
required: true,
215+
}
216+
}
217+
}
205218
},
206219
},
207220
required: true,

lib/shared_types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ export interface Experiment {
152152
trafficAllocation: TrafficAllocation[];
153153
forcedVariations?: { [key: string]: string };
154154
isRollout?: boolean;
155+
cmab?: {
156+
attributeIds: string[];
157+
};
155158
}
156159

157160
export enum VariableType {

0 commit comments

Comments
 (0)