Skip to content
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
1 change: 0 additions & 1 deletion lib/core/optimizely_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class OptimizelyConfig {
public events: OptimizelyEvent[];
private datafile: string;


constructor(configObj: ProjectConfig, datafile: string, logger?: LoggerFacade) {
this.sdkKey = configObj.sdkKey ?? '';
this.environmentKey = configObj.environmentKey ?? '';
Expand Down
25 changes: 17 additions & 8 deletions lib/core/project_config/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ var logger = getLogger();

describe('lib/core/project_config', function() {
describe('createProjectConfig method', function() {
// Copy experimentIds to experimentsIds in each event to fix typo in property name
// https://github.com/optimizely/javascript-sdk/issues/991
const copyEventExperimentIds = (event) => {
return {
...event,
experimentsIds: event.experimentIds,
}
};

it('should set properties correctly when createProjectConfig is called', function() {
var testData = testDatafile.getTestProjectConfig();
var configObj = projectConfig.createProjectConfig(testData);
Expand All @@ -42,7 +51,7 @@ describe('lib/core/project_config', function() {
assert.strictEqual(configObj.accountId, testData.accountId);
assert.strictEqual(configObj.projectId, testData.projectId);
assert.strictEqual(configObj.revision, testData.revision);
assert.deepEqual(configObj.events, testData.events);
assert.deepEqual(configObj.events, testData.events.map((e) => copyEventExperimentIds(e)));
assert.deepEqual(configObj.audiences, testData.audiences);
testData.groups.forEach(function(group) {
group.experiments.forEach(function(experiment) {
Expand Down Expand Up @@ -99,13 +108,13 @@ describe('lib/core/project_config', function() {
assert.deepEqual(configObj.experimentKeyMap, expectedExperimentKeyMap);

var expectedEventKeyMap = {
testEvent: testData.events[0],
'Total Revenue': testData.events[1],
testEventWithAudiences: testData.events[2],
testEventWithoutExperiments: testData.events[3],
testEventWithExperimentNotRunning: testData.events[4],
testEventWithMultipleExperiments: testData.events[5],
testEventLaunched: testData.events[6],
testEvent: copyEventExperimentIds(testData.events[0]),
'Total Revenue': copyEventExperimentIds(testData.events[1]),
testEventWithAudiences: copyEventExperimentIds(testData.events[2]),
testEventWithoutExperiments: copyEventExperimentIds(testData.events[3]),
testEventWithExperimentNotRunning: copyEventExperimentIds(testData.events[4]),
testEventWithMultipleExperiments: copyEventExperimentIds(testData.events[5]),
testEventLaunched: copyEventExperimentIds(testData.events[6]),
};

assert.deepEqual(configObj.eventKeyMap, expectedEventKeyMap);
Expand Down
16 changes: 15 additions & 1 deletion lib/core/project_config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2024, Optimizely
* Copyright 2016-2025, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,6 +50,10 @@ interface Event {
key: string;
id: string;
experimentsIds: string[];

// the field is named experimentIds in the datafile, but this type previously defined it as experimentsIds.
// keeping both to avoid breaking changes, removed experimentsIds in v6.
experimentIds: string[]; // fix typo in property name (https://github.com/optimizely/javascript-sdk/issues/991)
}

interface VariableUsageMap {
Expand Down Expand Up @@ -101,6 +105,16 @@ const MODULE_NAME = 'PROJECT_CONFIG';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
const datafileCopy = assign({}, datafile);

datafileCopy.events = (datafile.events || []).map((event: Event) => {
const eventCopy: Event = assign({}, event);

// Copy experimentIds to experimentsIds in each event to fix typo in property name
// https://github.com/optimizely/javascript-sdk/issues/991
eventCopy.experimentsIds = event.experimentIds;
return eventCopy;
});

datafileCopy.audiences = (datafile.audiences || []).map((audience: Audience) => {
return assign({}, audience);
});
Expand Down
6 changes: 5 additions & 1 deletion lib/shared_types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020-2024, Optimizely
* Copyright 2020-2025, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -469,6 +469,10 @@ export type OptimizelyEvent = {
id: string;
key: string;
experimentsIds: string[];

// the field is named experimentIds in the datafile, but this type previously defined it as experimentsIds.
// keeping both to avoid breaking changes, removed experimentsIds in v6.
experimentIds: string[]; // fix typo in property name (https://github.com/optimizely/javascript-sdk/issues/991)
};

export interface OptimizelyFeature {
Expand Down
Loading