Skip to content

Commit 7e89e43

Browse files
authored
[FSSDK-11925] fix type in event.experimentIds field in projectConfig (#1088)
solves #991
1 parent a204cb7 commit 7e89e43

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

lib/core/optimizely_config/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export class OptimizelyConfig {
6262
public events: OptimizelyEvent[];
6363
private datafile: string;
6464

65-
6665
constructor(configObj: ProjectConfig, datafile: string, logger?: LoggerFacade) {
6766
this.sdkKey = configObj.sdkKey ?? '';
6867
this.environmentKey = configObj.environmentKey ?? '';

lib/core/project_config/index.tests.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ var logger = getLogger();
3131

3232
describe('lib/core/project_config', function() {
3333
describe('createProjectConfig method', function() {
34+
// Copy experimentIds to experimentsIds in each event to fix typo in property name
35+
// https://github.com/optimizely/javascript-sdk/issues/991
36+
const copyEventExperimentIds = (event) => {
37+
return {
38+
...event,
39+
experimentsIds: event.experimentIds,
40+
}
41+
};
42+
3443
it('should set properties correctly when createProjectConfig is called', function() {
3544
var testData = testDatafile.getTestProjectConfig();
3645
var configObj = projectConfig.createProjectConfig(testData);
@@ -42,7 +51,7 @@ describe('lib/core/project_config', function() {
4251
assert.strictEqual(configObj.accountId, testData.accountId);
4352
assert.strictEqual(configObj.projectId, testData.projectId);
4453
assert.strictEqual(configObj.revision, testData.revision);
45-
assert.deepEqual(configObj.events, testData.events);
54+
assert.deepEqual(configObj.events, testData.events.map((e) => copyEventExperimentIds(e)));
4655
assert.deepEqual(configObj.audiences, testData.audiences);
4756
testData.groups.forEach(function(group) {
4857
group.experiments.forEach(function(experiment) {
@@ -99,13 +108,13 @@ describe('lib/core/project_config', function() {
99108
assert.deepEqual(configObj.experimentKeyMap, expectedExperimentKeyMap);
100109

101110
var expectedEventKeyMap = {
102-
testEvent: testData.events[0],
103-
'Total Revenue': testData.events[1],
104-
testEventWithAudiences: testData.events[2],
105-
testEventWithoutExperiments: testData.events[3],
106-
testEventWithExperimentNotRunning: testData.events[4],
107-
testEventWithMultipleExperiments: testData.events[5],
108-
testEventLaunched: testData.events[6],
111+
testEvent: copyEventExperimentIds(testData.events[0]),
112+
'Total Revenue': copyEventExperimentIds(testData.events[1]),
113+
testEventWithAudiences: copyEventExperimentIds(testData.events[2]),
114+
testEventWithoutExperiments: copyEventExperimentIds(testData.events[3]),
115+
testEventWithExperimentNotRunning: copyEventExperimentIds(testData.events[4]),
116+
testEventWithMultipleExperiments: copyEventExperimentIds(testData.events[5]),
117+
testEventLaunched: copyEventExperimentIds(testData.events[6]),
109118
};
110119

111120
assert.deepEqual(configObj.eventKeyMap, expectedEventKeyMap);

lib/core/project_config/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2024, Optimizely
2+
* Copyright 2016-2025, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,6 +50,10 @@ interface Event {
5050
key: string;
5151
id: string;
5252
experimentsIds: string[];
53+
54+
// the field is named experimentIds in the datafile, but this type previously defined it as experimentsIds.
55+
// keeping both to avoid breaking changes, removed experimentsIds in v6.
56+
experimentIds: string[]; // fix typo in property name (https://github.com/optimizely/javascript-sdk/issues/991)
5357
}
5458

5559
interface VariableUsageMap {
@@ -101,6 +105,16 @@ const MODULE_NAME = 'PROJECT_CONFIG';
101105
// eslint-disable-next-line @typescript-eslint/no-explicit-any
102106
function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
103107
const datafileCopy = assign({}, datafile);
108+
109+
datafileCopy.events = (datafile.events || []).map((event: Event) => {
110+
const eventCopy: Event = assign({}, event);
111+
112+
// Copy experimentIds to experimentsIds in each event to fix typo in property name
113+
// https://github.com/optimizely/javascript-sdk/issues/991
114+
eventCopy.experimentsIds = event.experimentIds;
115+
return eventCopy;
116+
});
117+
104118
datafileCopy.audiences = (datafile.audiences || []).map((audience: Audience) => {
105119
return assign({}, audience);
106120
});

lib/shared_types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2020-2024, Optimizely
2+
* Copyright 2020-2025, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -469,6 +469,10 @@ export type OptimizelyEvent = {
469469
id: string;
470470
key: string;
471471
experimentsIds: string[];
472+
473+
// the field is named experimentIds in the datafile, but this type previously defined it as experimentsIds.
474+
// keeping both to avoid breaking changes, removed experimentsIds in v6.
475+
experimentIds: string[]; // fix typo in property name (https://github.com/optimizely/javascript-sdk/issues/991)
472476
};
473477

474478
export interface OptimizelyFeature {

0 commit comments

Comments
 (0)