|
| 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 | +}); |
0 commit comments