Skip to content

Commit 4cd128a

Browse files
[FSSDK-1119] decision test addition
1 parent 506d441 commit 4cd128a

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

lib/core/decision/index.spec.ts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* Copyright 2024, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { describe, it, expect } from 'vitest';
17+
import { rolloutDecisionObj, featureTestDecisionObj } from '../../tests/test_data';
18+
import * as decision from './';
19+
20+
describe('getExperimentKey method', () => {
21+
it('should return empty string when experiment is null', () => {
22+
const experimentKey = decision.getExperimentKey(rolloutDecisionObj);
23+
24+
expect(experimentKey).toEqual('');
25+
});
26+
27+
it('should return empty string when experiment is not defined', () => {
28+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
29+
// @ts-ignore
30+
const experimentKey = decision.getExperimentKey({});
31+
32+
expect(experimentKey).toEqual('');
33+
});
34+
35+
it('should return experiment key when experiment is defined', () => {
36+
const experimentKey = decision.getExperimentKey(featureTestDecisionObj);
37+
38+
expect(experimentKey).toEqual('testing_my_feature');
39+
});
40+
});
41+
42+
describe('getExperimentId method', function() {
43+
it('should return null when experiment is null', function() {
44+
const experimentId = decision.getExperimentId(rolloutDecisionObj);
45+
46+
expect(experimentId).toEqual(null);
47+
});
48+
49+
it('should return null when experiment is not defined', function() {
50+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
51+
// @ts-ignore
52+
const experimentId = decision.getExperimentId({});
53+
54+
expect(experimentId).toEqual(null);
55+
});
56+
57+
it('should return experiment id when experiment is defined', function() {
58+
const experimentId = decision.getExperimentId(featureTestDecisionObj);
59+
60+
expect(experimentId).toEqual('594098');
61+
});
62+
63+
describe('getVariationKey method', function() {
64+
it('should return empty string when variation is null', function() {
65+
const variationKey = decision.getVariationKey(rolloutDecisionObj);
66+
67+
expect(variationKey).toEqual('');
68+
});
69+
70+
it('should return empty string when variation is not defined', function() {
71+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
72+
// @ts-ignore
73+
const variationKey = decision.getVariationKey({});
74+
75+
expect(variationKey).toEqual('');
76+
});
77+
78+
it('should return variation key when variation is defined', function() {
79+
const variationKey = decision.getVariationKey(featureTestDecisionObj);
80+
81+
expect(variationKey).toEqual('variation');
82+
});
83+
});
84+
85+
describe('getVariationId method', function() {
86+
it('should return null when variation is null', function() {
87+
const variationId = decision.getVariationId(rolloutDecisionObj);
88+
89+
expect(variationId).toEqual(null);
90+
});
91+
92+
it('should return null when variation is not defined', function() {
93+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
94+
// @ts-ignore
95+
const variationId = decision.getVariationId({});
96+
97+
expect(variationId).toEqual(null);
98+
});
99+
100+
it('should return variation id when variation is defined', function() {
101+
const variationId = decision.getVariationId(featureTestDecisionObj);
102+
103+
expect(variationId).toEqual('594096');
104+
});
105+
});
106+
107+
describe('getFeatureEnabledFromVariation method', function() {
108+
it('should return false when variation is null', function() {
109+
const featureEnabled = decision.getFeatureEnabledFromVariation(rolloutDecisionObj);
110+
111+
expect(featureEnabled).toEqual(false);
112+
});
113+
114+
it('should return false when variation is not defined', function() {
115+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
116+
// @ts-ignore
117+
const featureEnabled = decision.getFeatureEnabledFromVariation({});
118+
119+
expect(featureEnabled).toEqual(false);
120+
});
121+
122+
it('should return featureEnabled boolean when variation is defined', function() {
123+
const featureEnabled = decision.getFeatureEnabledFromVariation(featureTestDecisionObj);
124+
125+
expect(featureEnabled).toEqual(true);
126+
});
127+
});
128+
});

lib/tests/test_data.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,12 +3573,14 @@ export var featureTestDecisionObj = {
35733573
id: '594096',
35743574
featureEnabled: true,
35753575
variables: [],
3576+
variablesMap: {},
35763577
},
35773578
{
35783579
key: 'control',
35793580
id: '594097',
35803581
featureEnabled: true,
35813582
variables: [],
3583+
variablesMap: {}
35823584
},
35833585
],
35843586
status: 'Running',
@@ -3590,20 +3592,24 @@ export var featureTestDecisionObj = {
35903592
id: '594096',
35913593
featureEnabled: true,
35923594
variables: [],
3595+
variablesMap: {}
35933596
},
35943597
control: {
35953598
key: 'control',
35963599
id: '594097',
35973600
featureEnabled: true,
35983601
variables: [],
3602+
variablesMap: {}
35993603
},
36003604
},
3605+
audienceConditions: []
36013606
},
36023607
variation: {
36033608
key: 'variation',
36043609
id: '594096',
36053610
featureEnabled: true,
36063611
variables: [],
3612+
variablesMap: {}
36073613
},
36083614
decisionSource: 'feature-test',
36093615
};

0 commit comments

Comments
 (0)