Skip to content

[FSSDK-11124] add cmab experiment properties to project config #1009

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 3 commits into from
Feb 25, 2025
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
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
Loading