Skip to content

Commit 2e77149

Browse files
committed
Add environmentKey and sdkKey to datafile, OptimizelyConfig, and ProjectConfig
1 parent 9aac96f commit 2e77149

File tree

6 files changed

+26
-25
lines changed

6 files changed

+26
-25
lines changed

packages/optimizely-sdk/lib/core/optimizely_config/index.tests.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019-2020, Optimizely
2+
* Copyright 2019-2021, 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.
@@ -137,5 +137,13 @@ describe('lib/core/optimizely_config', function() {
137137
it('should return correct config revision', function() {
138138
assert.equal(optimizelyConfigObject.revision, datafile.revision);
139139
});
140+
141+
it('should return correct config sdkKey ', function() {
142+
assert.equal(optimizelyConfigObject.sdkKey, datafile.sdkKey);
143+
});
144+
145+
it('should return correct config environmentKey ', function() {
146+
assert.equal(optimizelyConfigObject.environmentKey, datafile.environmentKey);
147+
});
140148
});
141149
});

packages/optimizely-sdk/lib/core/optimizely_config/index.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class OptimizelyConfig {
3737
public experimentsMap: OptimizelyExperimentsMap;
3838
public featuresMap: OptimizelyFeaturesMap;
3939
public revision: string;
40-
private sdkKey: string;
41-
private environmentKey: string;
40+
public sdkKey: string;
41+
public environmentKey: string;
4242
private datafile: string;
4343

4444
constructor(configObj: ProjectConfig, datafile: string) {
@@ -58,22 +58,6 @@ export class OptimizelyConfig {
5858
return this.datafile;
5959
}
6060

61-
/**
62-
* Get the sdkKey
63-
* @returns {string} sdkKey
64-
*/
65-
getSdkKey(): string {
66-
return this.sdkKey;
67-
}
68-
69-
/**
70-
* Get the environmentKey
71-
* @returns {string} environmentKey
72-
*/
73-
getEnvironmentKey(): string {
74-
return this.environmentKey;
75-
}
76-
7761
/**
7862
* Get Experiment Ids which are part of rollout
7963
* @param {Rollout[]} rollouts

packages/optimizely-sdk/lib/core/project_config/index.tests.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2020, Optimizely
2+
* Copyright 2016-2021, 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.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import sinon from 'sinon';
17-
import { assert, expect, config } from 'chai';
17+
import { assert } from 'chai';
1818
import { forEach, cloneDeep } from 'lodash';
1919
import { getLogger } from '@optimizely/js-sdk-logging';
2020
import { sprintf } from '@optimizely/js-sdk-utils';
@@ -41,7 +41,10 @@ describe('lib/core/project_config', function() {
4141
forEach(testData.audiences, function(audience) {
4242
audience.conditions = JSON.parse(audience.conditions);
4343
});
44-
44+
// since v2 datafile testData does not contain sdkKey, configObj will have an empty string as sdkKey
45+
assert.strictEqual(configObj.sdkKey, '');
46+
// since v2 datafile testData does not contain environmentKey, configObj will have an empty string as environmentKey
47+
assert.strictEqual(configObj.environmentKey, '');
4548
assert.strictEqual(configObj.accountId, testData.accountId);
4649
assert.strictEqual(configObj.projectId, testData.projectId);
4750
assert.strictEqual(configObj.revision, testData.revision);

packages/optimizely-sdk/lib/core/project_config/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
115115
});
116116
return rolloutCopy;
117117
});
118+
119+
datafileCopy.environmentKey = datafile.environmentKey || '';
120+
datafileCopy.sdkKey = datafile.sdkKey || '';
121+
118122
return datafileCopy;
119123
}
120124

packages/optimizely-sdk/lib/shared_types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ export interface OptimizelyConfig {
304304
experimentsMap: OptimizelyExperimentsMap;
305305
featuresMap: OptimizelyFeaturesMap;
306306
revision: string;
307-
sdkKey: string,
308-
environmentKey: string,
307+
sdkKey: string;
308+
environmentKey: string;
309309
getDatafile(): string;
310310
}
311311

packages/optimizely-sdk/lib/tests/test_data.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ var decideConfig = {
418418
],
419419
anonymizeIP: true,
420420
botFiltering: true,
421+
sdkKey: 'ValidProjectConfigV4',
422+
environmentKey: 'production',
421423
projectId: '10431130345',
422424
variables: [],
423425
featureFlags: [
@@ -1143,7 +1145,7 @@ var configWithFeatures = {
11431145
],
11441146
anonymizeIP: true,
11451147
botFiltering: true,
1146-
sdkKey: 'ValidProjectConfigWithFeatures',
1148+
sdkKey: 'ValidProjectConfigV4',
11471149
environmentKey: 'development',
11481150
audiences: [
11491151
{

0 commit comments

Comments
 (0)