Skip to content

Commit 9a77240

Browse files
[FSSDK-11528] decision service tests improvement
1 parent f6c4cda commit 9a77240

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

lib/core/bucketer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
5656
const decideReasons: DecisionReason[] = [];
5757
// Check if user is in a random group; if so, check if user is bucketed into a specific experiment
5858
const experiment = bucketerParams.experimentIdMap[bucketerParams.experimentId];
59-
const groupId = experiment['groupId'];
59+
const groupId = experiment?.['groupId'];
6060
if (groupId) {
6161
const group = bucketerParams.groupIdMap[groupId];
6262
if (!group) {

lib/core/decision_service/index.spec.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,8 +1947,10 @@ describe('DecisionService', () => {
19471947
});
19481948

19491949
describe('holdout', () => {
1950-
beforeEach(() => {
1950+
beforeEach(async() => {
19511951
mockHoldoutToggle.mockReturnValue(true);
1952+
const actualBucketModule = (await vi.importActual('../bucketer')) as { bucket: typeof bucket };
1953+
mockBucket.mockImplementation(actualBucketModule.bucket);
19521954
});
19531955

19541956
it('should return holdout variation when user is bucketed into running holdout', async () => {
@@ -1961,21 +1963,6 @@ describe('DecisionService', () => {
19611963
age: 20,
19621964
},
19631965
});
1964-
1965-
mockBucket.mockImplementation((param: BucketerParams) => {
1966-
const ruleKey = param.experimentKey;
1967-
if (ruleKey === 'holdout_running') {
1968-
return {
1969-
result: 'holdout_variation_running_id',
1970-
reasons: [],
1971-
};
1972-
}
1973-
return {
1974-
result: null,
1975-
reasons: [],
1976-
};
1977-
});
1978-
19791966
const feature = config.featureKeyMap['flag_1'];
19801967
const value = decisionService.resolveVariationsForFeatureList('async', config, [feature], user, {}).get();
19811968

0 commit comments

Comments
 (0)