Skip to content

Commit 8954372

Browse files
committed
fixes
1 parent f547842 commit 8954372

File tree

14 files changed

+124
-353
lines changed

14 files changed

+124
-353
lines changed

lib/core/audience_evaluator/index.tests.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616
import sinon from 'sinon';
1717
import { assert } from 'chai';
1818
import { sprintf } from '../../utils/fns';
19-
import { getLogger } from '../../modules/logging';
19+
// import { getMockLogger } from '../../tests/mock/mock_logger';
2020

2121
import AudienceEvaluator, { createAudienceEvaluator } from './index';
2222
import * as conditionTreeEvaluator from '../condition_tree_evaluator';
2323
import * as customAttributeConditionEvaluator from '../custom_attribute_condition_evaluator';
2424

2525
var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2));
26-
var mockLogger = getLogger();
26+
var mockLogger = {
27+
debug: () => {},
28+
info: () => {},
29+
warn: () => {},
30+
error: () => {},
31+
}
2732

2833
var getMockUserContext = (attributes, segments) => ({
2934
getAttributes: () => ({ ... (attributes || {})}),
@@ -82,11 +87,17 @@ describe('lib/core/audience_evaluator', function() {
8287
var audienceEvaluator;
8388

8489
beforeEach(function() {
85-
sinon.stub(mockLogger, 'log');
90+
sinon.stub(mockLogger, 'info');
91+
sinon.stub(mockLogger, 'debug');
92+
sinon.stub(mockLogger, 'warn');
93+
sinon.stub(mockLogger, 'error');
8694
});
8795

8896
afterEach(function() {
89-
mockLogger.log.restore();
97+
mockLogger.info.restore();
98+
mockLogger.debug.restore();
99+
mockLogger.warn.restore();
100+
mockLogger.error.restore();
90101
});
91102

92103
describe('APIs', function() {

lib/core/audience_evaluator/odp_segment_condition_evaluator/index.tests.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { assert } from 'chai';
1818
import { sprintf } from '../../../utils/fns';
1919

2020
import { LOG_LEVEL } from '../../../utils/enums';
21-
import * as logging from '../../../modules/logging';
2221
import * as odpSegmentEvalutor from './';
2322
import { UNKNOWN_MATCH_TYPE } from '../../../error_messages';
2423

@@ -34,38 +33,44 @@ var getMockUserContext = (attributes, segments) => ({
3433
isQualifiedFor: segment => segments.indexOf(segment) > -1
3534
});
3635

36+
var createLogger = () => ({
37+
debug: () => {},
38+
info: () => {},
39+
warn: () => {},
40+
error: () => {},
41+
child: () => createLogger(),
42+
})
43+
3744
describe('lib/core/audience_evaluator/odp_segment_condition_evaluator', function() {
38-
var stubLogHandler;
45+
const mockLogger = createLogger();
46+
const { evaluate } = odpSegmentEvalutor.getEvaluator(mockLogger);
3947

4048
beforeEach(function() {
41-
stubLogHandler = {
42-
log: sinon.stub(),
43-
};
44-
logging.setLogLevel('notset');
45-
logging.setLogHandler(stubLogHandler);
49+
sinon.stub(mockLogger, 'warn');
50+
sinon.stub(mockLogger, 'error');
4651
});
4752

4853
afterEach(function() {
49-
logging.resetLogger();
54+
mockLogger.warn.restore();
55+
mockLogger.error.restore();
5056
});
5157

5258
it('should return true when segment qualifies and known match type is provided', () => {
53-
assert.isTrue(odpSegmentEvalutor.evaluate(odpSegment1Condition, getMockUserContext({}, ['odp-segment-1'])));
59+
assert.isTrue(evaluate(odpSegment1Condition, getMockUserContext({}, ['odp-segment-1'])));
5460
});
5561

5662
it('should return false when segment does not qualify and known match type is provided', () => {
57-
assert.isFalse(odpSegmentEvalutor.evaluate(odpSegment1Condition, getMockUserContext({}, ['odp-segment-2'])));
63+
assert.isFalse(evaluate(odpSegment1Condition, getMockUserContext({}, ['odp-segment-2'])));
5864
})
5965

6066
it('should return null when segment qualifies but unknown match type is provided', () => {
6167
const invalidOdpMatchCondition = {
6268
... odpSegment1Condition,
6369
"match": 'unknown',
6470
};
65-
assert.isNull(odpSegmentEvalutor.evaluate(invalidOdpMatchCondition, getMockUserContext({}, ['odp-segment-1'])));
66-
sinon.assert.calledOnce(stubLogHandler.log);
67-
assert.strictEqual(stubLogHandler.log.args[0][0], LOG_LEVEL.WARNING);
68-
var logMessage = stubLogHandler.log.args[0][1];
69-
assert.strictEqual(logMessage, sprintf(UNKNOWN_MATCH_TYPE, 'ODP_SEGMENT_CONDITION_EVALUATOR', JSON.stringify(invalidOdpMatchCondition)));
71+
assert.isNull(evaluate(invalidOdpMatchCondition, getMockUserContext({}, ['odp-segment-1'])));
72+
sinon.assert.calledOnce(mockLogger.warn);
73+
assert.strictEqual(mockLogger.warn.args[0][0], UNKNOWN_MATCH_TYPE);
74+
assert.strictEqual(mockLogger.warn.args[0][1], JSON.stringify(invalidOdpMatchCondition));
7075
});
7176
});

lib/core/bucketer/index.tests.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
*/
1616
import sinon from 'sinon';
1717
import { assert, expect } from 'chai';
18-
import { cloneDeep } from 'lodash';
18+
import { cloneDeep, create } from 'lodash';
1919
import { sprintf } from '../../utils/fns';
2020

2121
import * as bucketer from './';
2222
import { LOG_LEVEL } from '../../utils/enums';
23-
import { createLogger } from '../../plugins/logger';
2423
import projectConfig from '../../project_config/project_config';
2524
import { getTestProjectConfig } from '../../tests/test_data';
2625
import { INVALID_BUCKETING_ID, INVALID_GROUP_ID } from '../../error_messages';
@@ -30,23 +29,38 @@ import {
3029
USER_NOT_IN_ANY_EXPERIMENT,
3130
USER_ASSIGNED_TO_EXPERIMENT_BUCKET,
3231
} from '.';
32+
import { mock } from 'node:test';
3333

3434
var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2));
3535
var testData = getTestProjectConfig();
3636

37+
var createLogger = () => ({
38+
debug: () => {},
39+
info: () => {},
40+
warn: () => {},
41+
error: () => {},
42+
child: () => createLogger(),
43+
})
44+
3745
describe('lib/core/bucketer', function () {
3846
describe('APIs', function () {
3947
describe('bucket', function () {
4048
var configObj;
41-
var createdLogger = createLogger({ logLevel: LOG_LEVEL.INFO });
49+
var createdLogger = createLogger();
4250
var bucketerParams;
4351

4452
beforeEach(function () {
45-
sinon.stub(createdLogger, 'log');
53+
sinon.stub(createdLogger, 'info');
54+
sinon.stub(createdLogger, 'debug');
55+
sinon.stub(createdLogger, 'warn');
56+
sinon.stub(createdLogger, 'error');
4657
});
4758

4859
afterEach(function () {
49-
createdLogger.log.restore();
60+
createdLogger.info.restore();
61+
createdLogger.debug.restore();
62+
createdLogger.warn.restore();
63+
createdLogger.error.restore();
5064
});
5165

5266
describe('return values for bucketing (excluding groups)', function () {

lib/core/custom_attribute_condition_evaluator/index.tests.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { sprintf } from '../../utils/fns';
2020
import {
2121
LOG_LEVEL,
2222
} from '../../utils/enums';
23-
import * as logging from '../../modules/logging';
2423
import * as customAttributeEvaluator from './';
2524
import {
2625
MISSING_ATTRIBUTE_VALUE,
@@ -63,12 +62,9 @@ describe('lib/core/custom_attribute_condition_evaluator', function() {
6362
stubLogHandler = {
6463
log: sinon.stub(),
6564
};
66-
logging.setLogLevel('notset');
67-
logging.setLogHandler(stubLogHandler);
6865
});
6966

7067
afterEach(function() {
71-
logging.resetLogger();
7268
});
7369

7470
it('should return true when the attributes pass the audience conditions and no match type is provided', function() {

lib/core/decision_service/index.tests.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
LOG_LEVEL,
2525
DECISION_SOURCES,
2626
} from '../../utils/enums';
27-
import { createLogger } from '../../plugins/logger';
2827
import { getForwardingEventProcessor } from '../../event_processor/forwarding_event_processor';
2928
import { createNotificationCenter } from '../../notification_center';
3029
import Optimizely from '../../optimizely';
@@ -45,6 +44,14 @@ var testData = getTestProjectConfig();
4544
var testDataWithFeatures = getTestProjectConfigWithFeatures();
4645
var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2));
4746

47+
var createLogger = () => ({
48+
debug: () => {},
49+
info: () => {},
50+
warn: () => {},
51+
error: () => {},
52+
child: () => createLogger(),
53+
})
54+
4855
describe('lib/core/decision_service', function() {
4956
describe('APIs', function() {
5057
var configObj = projectConfig.createProjectConfig(cloneDeep(testData));

lib/index.browser.tests.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import logging, { getLogger } from './modules/logging/logger';
17-
1816
import { assert } from 'chai';
1917
import sinon from 'sinon';
2018
import Optimizely from './optimizely';
@@ -63,6 +61,14 @@ const pause = timeoutMilliseconds => {
6361
return new Promise(resolve => setTimeout(resolve, timeoutMilliseconds));
6462
};
6563

64+
var getLogger = () => ({
65+
debug: () => {},
66+
info: () => {},
67+
warn: () => {},
68+
error: () => {},
69+
child: () => getLogger(),
70+
})
71+
6672
describe('javascript-sdk (Browser)', function() {
6773
var clock;
6874
beforeEach(function() {

lib/index.lite.tests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import sinon from 'sinon';
1818

1919
import * as enums from './utils/enums';
2020
import Optimizely from './optimizely';
21-
import * as loggerPlugin from './plugins/logger';
2221
import optimizelyFactory from './index.lite';
2322
import configValidator from './utils/config_validator';
2423
import { getMockProjectConfigManager } from './tests/mock/mock_project_config_manager';

lib/index.node.tests.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
import { assert } from 'chai';
1717
import sinon from 'sinon';
1818

19-
import * as enums from './utils/enums';
2019
import Optimizely from './optimizely';
2120
import testData from './tests/test_data';
22-
import * as loggerPlugin from './plugins/logger';
2321
import optimizelyFactory from './index.node';
2422
import configValidator from './utils/config_validator';
2523
import { getMockProjectConfigManager } from './tests/mock/mock_project_config_manager';

lib/index.node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { createForwardingEventProcessor, createBatchEventProcessor } from './eve
2828
import { createVuidManager } from './vuid/vuid_manager_factory.node';
2929
import { createOdpManager } from './odp/odp_manager_factory.node';
3030
import { ODP_DISABLED } from './log_messages';
31+
import { create } from 'domain';
3132

3233
const DEFAULT_EVENT_BATCH_SIZE = 10;
3334
const DEFAULT_EVENT_FLUSH_INTERVAL = 30000; // Unit is ms, default is 30s

lib/notification_center/index.tests.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ import { assert } from 'chai';
1818

1919
import { createNotificationCenter } from './';
2020
import * as enums from '../utils/enums';
21-
import { createLogger } from '../plugins/logger';
2221
import errorHandler from '../plugins/error_handler';
2322
import { NOTIFICATION_TYPES } from './type';
23+
import { create } from 'lodash';
2424

2525
var LOG_LEVEL = enums.LOG_LEVEL;
2626

27+
var createLogger = () => ({
28+
debug: () => {},
29+
info: () => {},
30+
warn: () => {},
31+
error: () => {},
32+
child: () => createLogger(),
33+
})
34+
2735
describe('lib/core/notification_center', function() {
2836
describe('APIs', function() {
2937
var mockLogger = createLogger({ logLevel: LOG_LEVEL.INFO });

0 commit comments

Comments
 (0)