Skip to content

Commit 3603a2e

Browse files
committed
test fixes
1 parent 3597763 commit 3603a2e

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

lib/core/decision_service/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,12 @@ export class DecisionService {
290290
this.getDecisionFromBucketer(op, configObj, experiment, user);
291291

292292
return decisionVariationValue.then((variationResult): Value<OP, VariationResult> => {
293+
decideReasons.push(...variationResult.reasons);
293294
if (variationResult.error) {
294295
return Value.of(op, {
295296
error: true,
296297
result: {},
297-
reasons: [...decideReasons, ...variationResult.reasons],
298+
reasons: decideReasons,
298299
});
299300
}
300301

@@ -509,7 +510,7 @@ export class DecisionService {
509510
options: DecideOptionsMap = {}
510511
): DecisionResponse<string | null> {
511512
const shouldIgnoreUPS = options[OptimizelyDecideOption.IGNORE_USER_PROFILE_SERVICE];
512-
let userProfileTracker: Maybe<UserProfileTracker> = shouldIgnoreUPS ? undefined
513+
const userProfileTracker: Maybe<UserProfileTracker> = shouldIgnoreUPS ? undefined
513514
: {
514515
isProfileUpdated: false,
515516
userProfile: this.resolveExperimentBucketMap('sync', user.getUserId(), user.getAttributes()).get(),
@@ -938,7 +939,10 @@ export class DecisionService {
938939
decideOptions: DecideOptionsMap,
939940
userProfileTracker?: UserProfileTracker
940941
): Value<OP, DecisionResult> {
942+
const decideReasons: DecisionReason[] = [];
943+
941944
const forcedDecisionResponse = this.findValidatedForcedDecision(configObj, user, feature.key);
945+
decideReasons.push(...forcedDecisionResponse.reasons);
942946

943947
if (forcedDecisionResponse.result) {
944948
return Value.of(op, {
@@ -947,7 +951,7 @@ export class DecisionService {
947951
experiment: null,
948952
decisionSource: DECISION_SOURCES.FEATURE_TEST,
949953
},
950-
reasons: forcedDecisionResponse.reasons,
954+
reasons: decideReasons,
951955
});
952956
}
953957

@@ -956,7 +960,7 @@ export class DecisionService {
956960
return Value.of(op, experimentDecision);
957961
}
958962

959-
const decideReasons = experimentDecision.reasons;
963+
decideReasons.push(...experimentDecision.reasons);
960964

961965
const rolloutDecision = this.getVariationForRollout(configObj, feature, user);
962966
decideReasons.push(...rolloutDecision.reasons);

lib/optimizely/index.tests.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,23 @@ describe('lib/optimizely', function() {
224224
save: function() {},
225225
};
226226

227+
const cmabService = {};
228+
227229
new Optimizely({
228230
clientEngine: 'node-sdk',
229231
logger: createdLogger,
230232
projectConfigManager: getMockProjectConfigManager(),
231233
jsonSchemaValidator: jsonSchemaValidator,
232234
userProfileService: userProfileServiceInstance,
233235
notificationCenter,
236+
cmabService,
234237
eventProcessor,
235238
});
236239

237240
sinon.assert.calledWith(decisionService.createDecisionService, {
238241
userProfileService: userProfileServiceInstance,
239242
logger: createdLogger,
243+
cmabService,
240244
UNSTABLE_conditionEvaluators: undefined,
241245
});
242246

@@ -251,6 +255,8 @@ describe('lib/optimizely', function() {
251255
save: function() {},
252256
};
253257

258+
const cmabService = {};
259+
254260
new Optimizely({
255261
clientEngine: 'node-sdk',
256262
logger: createdLogger,
@@ -259,12 +265,14 @@ describe('lib/optimizely', function() {
259265
userProfileService: invalidUserProfile,
260266
notificationCenter,
261267
eventProcessor,
268+
cmabService,
262269
});
263270

264271
sinon.assert.calledWith(decisionService.createDecisionService, {
265272
userProfileService: undefined,
266273
logger: createdLogger,
267274
UNSTABLE_conditionEvaluators: undefined,
275+
cmabService,
268276
});
269277

270278
// var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]);
@@ -5261,6 +5269,7 @@ describe('lib/optimizely', function() {
52615269
userId,
52625270
});
52635271
var decision = optlyInstance.decide(user, flagKey);
5272+
52645273
expect(decision.reasons).to.include(
52655274
sprintf(USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP, userId, experimentKey, groupId)
52665275
);

lib/utils/promise/operation_value.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { PROMISE_NOT_ALLOWED } from '../../message/error_message';
22
import { OptimizelyError } from '../../error/optimizly_error';
33
import { OpType, OpValue } from '../type';
44

5-
export const isPromise = (val: any): boolean => {
5+
6+
const isPromise = (val: any): boolean => {
67
return val && typeof val.then === 'function';
78
}
89

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"clean:win": "(if exist dist rd /s/q dist)",
5454
"lint": "tsc --noEmit && eslint 'lib/**/*.js' 'lib/**/*.ts'",
5555
"test-vitest": "vitest run",
56-
"test-mocha": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register -r tsconfig-paths/register -r lib/tests/exit_on_unhandled_rejection.js 'lib/**/*.tests.ts' 'lib/**/decision_service/index.tests.js'",
56+
"test-mocha": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register -r tsconfig-paths/register -r lib/tests/exit_on_unhandled_rejection.js 'lib/**/*.tests.ts' 'lib/**/*.tests.js'",
5757
"test": "npm run test-mocha && npm run test-vitest",
5858
"posttest": "npm run lint",
5959
"test-ci": "npm run test-xbrowser && npm run test-umdbrowser",

test.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)