Skip to content

Commit 13822e9

Browse files
committed
config
1 parent ce7847a commit 13822e9

File tree

3 files changed

+40
-42
lines changed

3 files changed

+40
-42
lines changed

lib/project_config/project_config.tests.js

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ import projectConfig from './project_config';
2222
import { FEATURE_VARIABLE_TYPES, LOG_LEVEL } from '../utils/enums';
2323
import testDatafile from '../tests/test_data';
2424
import configValidator from '../utils/config_validator';
25-
import { INVALID_EXPERIMENT_ID, INVALID_EXPERIMENT_KEY } from '../error_messages';
25+
import {
26+
INVALID_EXPERIMENT_ID,
27+
INVALID_EXPERIMENT_KEY,
28+
UNEXPECTED_RESERVED_ATTRIBUTE_PREFIX,
29+
UNRECOGNIZED_ATTRIBUTE,
30+
VARIABLE_KEY_NOT_IN_DATAFILE,
31+
FEATURE_NOT_IN_DATAFILE,
32+
UNABLE_TO_CAST_VALUE
33+
} from '../error_messages';
2634

2735
var createLogger = () => ({
2836
debug: () => {},
@@ -289,11 +297,11 @@ describe('lib/core/project_config', function() {
289297

290298
beforeEach(function() {
291299
configObj = projectConfig.createProjectConfig(cloneDeep(testData));
292-
sinon.stub(createdLogger, 'log');
300+
sinon.stub(createdLogger, 'warn');
293301
});
294302

295303
afterEach(function() {
296-
createdLogger.log.restore();
304+
createdLogger.warn.restore();
297305
});
298306

299307
it('should retrieve experiment ID for valid experiment key in getExperimentId', function() {
@@ -329,10 +337,8 @@ describe('lib/core/project_config', function() {
329337

330338
it('should return null for invalid attribute key in getAttributeId', function() {
331339
assert.isNull(projectConfig.getAttributeId(configObj, 'invalidAttributeKey', createdLogger));
332-
assert.strictEqual(
333-
buildLogMessageFromArgs(createdLogger.log.lastCall.args),
334-
'PROJECT_CONFIG: Unrecognized attribute invalidAttributeKey provided. Pruning before sending event to Optimizely.'
335-
);
340+
341+
assert.deepEqual(createdLogger.warn.lastCall.args, [UNRECOGNIZED_ATTRIBUTE, 'invalidAttributeKey']);
336342
});
337343

338344
it('should return null for invalid attribute key in getAttributeId', function() {
@@ -342,10 +348,8 @@ describe('lib/core/project_config', function() {
342348
key: '$opt_some_reserved_attribute',
343349
};
344350
assert.strictEqual(projectConfig.getAttributeId(configObj, '$opt_some_reserved_attribute', createdLogger), '42');
345-
assert.strictEqual(
346-
buildLogMessageFromArgs(createdLogger.log.lastCall.args),
347-
'Attribute $opt_some_reserved_attribute unexpectedly has reserved prefix $opt_; using attribute ID instead of reserved attribute name.'
348-
);
351+
352+
assert.deepEqual(createdLogger.warn.lastCall.args, [UNEXPECTED_RESERVED_ATTRIBUTE_PREFIX, '$opt_some_reserved_attribute', '$opt_']);
349353
});
350354

351355
it('should retrieve event ID for valid event key in getEventId', function() {
@@ -439,11 +443,17 @@ describe('lib/core/project_config', function() {
439443
var featureManagementLogger = createLogger({ logLevel: LOG_LEVEL.INFO });
440444
beforeEach(function() {
441445
configObj = projectConfig.createProjectConfig(testDatafile.getTestProjectConfigWithFeatures());
442-
sinon.stub(featureManagementLogger, 'log');
446+
sinon.stub(featureManagementLogger, 'warn');
447+
sinon.stub(featureManagementLogger, 'error');
448+
sinon.stub(featureManagementLogger, 'info');
449+
sinon.stub(featureManagementLogger, 'debug');
443450
});
444451

445452
afterEach(function() {
446-
featureManagementLogger.log.restore();
453+
featureManagementLogger.warn.restore();
454+
featureManagementLogger.error.restore();
455+
featureManagementLogger.info.restore();
456+
featureManagementLogger.debug.restore();
447457
});
448458

449459
describe('getVariableForFeature', function() {
@@ -464,35 +474,29 @@ describe('lib/core/project_config', function() {
464474
var variableKey = 'notARealVariable____';
465475
var result = projectConfig.getVariableForFeature(configObj, featureKey, variableKey, featureManagementLogger);
466476
assert.strictEqual(result, null);
467-
sinon.assert.calledOnce(featureManagementLogger.log);
468-
assert.strictEqual(
469-
buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args),
470-
'PROJECT_CONFIG: Variable with key "notARealVariable____" associated with feature with key "test_feature_for_experiment" is not in datafile.'
471-
);
477+
sinon.assert.calledOnce(featureManagementLogger.error);
478+
479+
assert.deepEqual(featureManagementLogger.error.lastCall.args, [VARIABLE_KEY_NOT_IN_DATAFILE, 'notARealVariable____', 'test_feature_for_experiment']);
472480
});
473481

474482
it('should return null for an invalid feature key', function() {
475483
var featureKey = 'notARealFeature_____';
476484
var variableKey = 'num_buttons';
477485
var result = projectConfig.getVariableForFeature(configObj, featureKey, variableKey, featureManagementLogger);
478486
assert.strictEqual(result, null);
479-
sinon.assert.calledOnce(featureManagementLogger.log);
480-
assert.strictEqual(
481-
buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args),
482-
'PROJECT_CONFIG: Feature key notARealFeature_____ is not in datafile.'
483-
);
487+
sinon.assert.calledOnce(featureManagementLogger.error);
488+
489+
assert.deepEqual(featureManagementLogger.error.lastCall.args, [FEATURE_NOT_IN_DATAFILE, 'notARealFeature_____']);
484490
});
485491

486492
it('should return null for an invalid variable key and an invalid feature key', function() {
487493
var featureKey = 'notARealFeature_____';
488494
var variableKey = 'notARealVariable____';
489495
var result = projectConfig.getVariableForFeature(configObj, featureKey, variableKey, featureManagementLogger);
490496
assert.strictEqual(result, null);
491-
sinon.assert.calledOnce(featureManagementLogger.log);
492-
assert.strictEqual(
493-
buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args),
494-
'PROJECT_CONFIG: Feature key notARealFeature_____ is not in datafile.'
495-
);
497+
sinon.assert.calledOnce(featureManagementLogger.error);
498+
499+
assert.deepEqual(featureManagementLogger.error.lastCall.args, [FEATURE_NOT_IN_DATAFILE, 'notARealFeature_____']);
496500
});
497501
});
498502

@@ -634,10 +638,8 @@ describe('lib/core/project_config', function() {
634638
featureManagementLogger
635639
);
636640
assert.strictEqual(result, null);
637-
assert.strictEqual(
638-
buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args),
639-
'PROJECT_CONFIG: Unable to cast value notabool to type boolean, returning null.'
640-
);
641+
642+
assert.deepEqual(featureManagementLogger.error.lastCall.args, [UNABLE_TO_CAST_VALUE, 'notabool', 'boolean']);
641643
});
642644

643645
it('returns null and logs an error for an invalid integer', function() {
@@ -647,10 +649,8 @@ describe('lib/core/project_config', function() {
647649
featureManagementLogger
648650
);
649651
assert.strictEqual(result, null);
650-
assert.strictEqual(
651-
buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args),
652-
'PROJECT_CONFIG: Unable to cast value notanint to type integer, returning null.'
653-
);
652+
653+
assert.deepEqual(featureManagementLogger.error.lastCall.args, [UNABLE_TO_CAST_VALUE, 'notanint', 'integer']);
654654
});
655655

656656
it('returns null and logs an error for an invalid double', function() {
@@ -660,10 +660,8 @@ describe('lib/core/project_config', function() {
660660
featureManagementLogger
661661
);
662662
assert.strictEqual(result, null);
663-
assert.strictEqual(
664-
buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args),
665-
'PROJECT_CONFIG: Unable to cast value notadouble to type double, returning null.'
666-
);
663+
664+
assert.deepEqual(featureManagementLogger.error.lastCall.args, [UNABLE_TO_CAST_VALUE, 'notadouble', 'double']);
667665
});
668666
});
669667
});

lib/project_config/project_config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export const getAttributeId = function(
408408
return attributeKey;
409409
}
410410

411-
logger?.debug(UNRECOGNIZED_ATTRIBUTE, attributeKey);
411+
logger?.warn(UNRECOGNIZED_ATTRIBUTE, attributeKey);
412412
return null;
413413
};
414414

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"clean:win": "(if exist dist rd /s/q dist)",
7575
"lint": "tsc --noEmit && eslint 'lib/**/*.js' 'lib/**/*.ts'",
7676
"test-vitest": "tsc --noEmit --p tsconfig.spec.json && vitest run",
77-
"test-mocha": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register -r lib/tests/exit_on_unhandled_rejection.js 'lib/**/*.tests.ts' 'lib/**/optimizely_user_context/*.tests.js'",
77+
"test-mocha": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register -r lib/tests/exit_on_unhandled_rejection.js 'lib/**/*.tests.ts' 'lib/**/**/project_config.tests.js'",
7878
"test": "npm run test-mocha && npm run test-vitest",
7979
"posttest": "npm run lint",
8080
"test-ci": "npm run test-xbrowser && npm run test-umdbrowser",

0 commit comments

Comments
 (0)