|
1 | 1 | const ConfigurationObjectFeatureFlagProvider = FeatureManagement.ConfigurationObjectFeatureFlagProvider;
|
2 | 2 | const FeatureManager = FeatureManagement.FeatureManager;
|
3 | 3 |
|
4 |
| -describe("feature manager", () => { |
5 |
| - it("should load from json string", |
6 |
| - async () => { |
7 |
| - const jsonObject = { |
8 |
| - "feature_management": { |
9 |
| - "feature_flags": [ |
| 4 | +const jsonObject = { |
| 5 | + "feature_management": { |
| 6 | + "feature_flags": [ |
| 7 | + { |
| 8 | + "id": "ComplexTargeting", |
| 9 | + "description": "A feature flag using a targeting filter, that will return true for Alice, Stage1, and 50% of Stage2. Dave and Stage3 are excluded. The default rollout percentage is 25%.", |
| 10 | + "enabled": true, |
| 11 | + "conditions": { |
| 12 | + "client_filters": [ |
10 | 13 | {
|
11 |
| - "id": "ComplexTargeting", |
12 |
| - "description": "A feature flag using a targeting filter, that will return true for Alice, Stage1, and 50% of Stage2. Dave and Stage3 are excluded. The default rollout percentage is 25%.", |
13 |
| - "enabled": true, |
14 |
| - "conditions": { |
15 |
| - "client_filters": [ |
16 |
| - { |
17 |
| - "name": "Microsoft.Targeting", |
18 |
| - "parameters": { |
19 |
| - "Audience": { |
20 |
| - "Users": [ |
21 |
| - "Alice" |
22 |
| - ], |
23 |
| - "Groups": [ |
24 |
| - { |
25 |
| - "Name": "Stage1", |
26 |
| - "RolloutPercentage": 100 |
27 |
| - }, |
28 |
| - { |
29 |
| - "Name": "Stage2", |
30 |
| - "RolloutPercentage": 50 |
31 |
| - } |
32 |
| - ], |
33 |
| - "DefaultRolloutPercentage": 25, |
34 |
| - "Exclusion": { |
35 |
| - "Users": ["Dave"], |
36 |
| - "Groups": ["Stage3"] |
37 |
| - } |
38 |
| - } |
| 14 | + "name": "Microsoft.Targeting", |
| 15 | + "parameters": { |
| 16 | + "Audience": { |
| 17 | + "Users": [ |
| 18 | + "Alice" |
| 19 | + ], |
| 20 | + "Groups": [ |
| 21 | + { |
| 22 | + "Name": "Stage1", |
| 23 | + "RolloutPercentage": 100 |
| 24 | + }, |
| 25 | + { |
| 26 | + "Name": "Stage2", |
| 27 | + "RolloutPercentage": 50 |
39 | 28 | }
|
| 29 | + ], |
| 30 | + "DefaultRolloutPercentage": 25, |
| 31 | + "Exclusion": { |
| 32 | + "Users": ["Dave"], |
| 33 | + "Groups": ["Stage3"] |
40 | 34 | }
|
41 |
| - ] |
| 35 | + } |
42 | 36 | }
|
43 | 37 | }
|
44 | 38 | ]
|
45 | 39 | }
|
46 |
| - }; |
47 |
| - |
48 |
| - const provider = new ConfigurationObjectFeatureFlagProvider(jsonObject); |
49 |
| - const featureManager = new FeatureManager(provider); |
| 40 | + } |
| 41 | + ] |
| 42 | + } |
| 43 | +}; |
| 44 | + |
| 45 | +const provider = new ConfigurationObjectFeatureFlagProvider(jsonObject); |
| 46 | +const featureManager = new FeatureManager(provider); |
| 47 | + |
| 48 | +describe("feature manager", () => { |
| 49 | + it("should not target user Aiden in default rollout", |
| 50 | + async () => { |
50 | 51 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Aiden" })).to.eq(false);
|
| 52 | + } |
| 53 | + ).timeout(1000);; |
| 54 | + |
| 55 | + it("should target user Bloosom in default rollout", |
| 56 | + async () => { |
51 | 57 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Blossom" })).to.eq(true);
|
| 58 | + } |
| 59 | + ).timeout(1000);; |
| 60 | + |
| 61 | + it("should target user Alice", |
| 62 | + async () => { |
52 | 63 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Alice" })).to.eq(true);
|
| 64 | + } |
| 65 | + ).timeout(1000);; |
| 66 | + |
| 67 | + it("should target user Aiden in group Stage1", |
| 68 | + async () => { |
53 | 69 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Aiden", groups: ["Stage1"] })).to.eq(true);
|
| 70 | + } |
| 71 | + ).timeout(1000);; |
| 72 | + |
| 73 | + it("should not target user Dave in group Stage1", |
| 74 | + async () => { |
| 75 | + chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Dave", groups: ["Stage1"] })).to.eq(false); |
| 76 | + } |
| 77 | + ).timeout(1000);; |
| 78 | + |
| 79 | + it("should not target empty user in group Stage2", |
| 80 | + async () => { |
54 | 81 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { groups: ["Stage2"] })).to.eq(false);
|
| 82 | + } |
| 83 | + ).timeout(1000);; |
| 84 | + |
| 85 | + it("should target user Aiden in group Stage2", |
| 86 | + async () => { |
55 | 87 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Aiden", groups: ["Stage2"] })).to.eq(true);
|
| 88 | + } |
| 89 | + ).timeout(1000);; |
| 90 | + |
| 91 | + it("should not target user Chris in group Stage2", |
| 92 | + async () => { |
56 | 93 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Chris", groups: ["Stage2"] })).to.eq(false);
|
57 |
| - chai.expect(await featureManager.isEnabled("ComplexTargeting", { groups: ["Stage3"] })).to.eq(false), |
| 94 | + } |
| 95 | + ).timeout(1000);; |
| 96 | + |
| 97 | + it("should not target group Stage3", |
| 98 | + async () => { |
| 99 | + chai.expect(await featureManager.isEnabled("ComplexTargeting", { groups: ["Stage3"] })).to.eq(false); |
58 | 100 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Alice", groups: ["Stage3"] })).to.eq(false);
|
59 | 101 | chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Blossom", groups: ["Stage3"] })).to.eq(false);
|
60 |
| - chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Dave", groups: ["Stage1"] })).to.eq(false); |
61 | 102 | }
|
62 |
| - ); |
| 103 | + ).timeout(1000); |
63 | 104 | });
|
0 commit comments