Skip to content

Commit d06f24e

Browse files
author
James Fox
committed
add test for logger
1 parent e51e145 commit d06f24e

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ var audiencesById = {
6363
describe('lib/core/audience_evaluator', function() {
6464
var audienceEvaluator;
6565

66+
beforeEach(function() {
67+
sinon.stub(mockLogger, 'log');
68+
});
69+
70+
afterEach(function() {
71+
mockLogger.log.restore();
72+
});
73+
6674
describe('APIs', function() {
6775
context('with default condition evaluator', function() {
6876
beforeEach(function() {
6977
audienceEvaluator = new AudienceEvaluator();
7078
});
71-
describe('evaluate', function() {
72-
beforeEach(function() {
73-
sinon.stub(mockLogger, 'log');
74-
});
75-
76-
afterEach(function() {
77-
mockLogger.log.restore();
78-
});
79-
79+
describe('evaluate', function() {
8080
it('should return true if there are no audiences', function() {
8181
assert.isTrue(audienceEvaluator.evaluate([], audiencesById, {}));
8282
});
@@ -282,8 +282,10 @@ describe('lib/core/audience_evaluator', function() {
282282
};
283283
audienceEvaluator = new AudienceEvaluator({
284284
special_condition_type: {
285-
evaluate: function(condition, userAttributes) {
286-
return mockEnvironment[condition.value] && userAttributes[condition.match] > 0;
285+
evaluate: function(condition, userAttributes, logger) {
286+
const result = mockEnvironment[condition.value] && userAttributes[condition.match] > 0;
287+
logger.log(`special_condition_type: ${result} for ${condition.value}:${condition.match}`)
288+
return result;
287289
}
288290
},
289291
});
@@ -293,6 +295,13 @@ describe('lib/core/audience_evaluator', function() {
293295
assert.isFalse(audienceEvaluator.evaluate(['3'], audiencesById, {interest_level: 0}));
294296
assert.isTrue(audienceEvaluator.evaluate(['3'], audiencesById, {interest_level: 1}));
295297
})
298+
299+
it('should pass the logger instance to the custom condition evaluator', function() {
300+
assert.isFalse(audienceEvaluator.evaluate(['3'], audiencesById, {interest_level: 0}));
301+
assert.isTrue(audienceEvaluator.evaluate(['3'], audiencesById, {interest_level: 1}));
302+
sinon.assert.calledWithExactly(mockLogger.log, 'special_condition_type: false for special:interest_level');
303+
sinon.assert.calledWithExactly(mockLogger.log, 'special_condition_type: true for special:interest_level');
304+
})
296305
})
297306

298307
describe('when passing an invalid additional evaluator' , function() {

0 commit comments

Comments
 (0)