Skip to content

Commit ab939e6

Browse files
authored
feat: add nested fractional weight assertion (#352)
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
1 parent fc148a6 commit ab939e6

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

flags/custom-ops.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,31 @@
141141
]
142142
}
143143
},
144+
"fractional-nested-weight-flag": {
145+
"state": "ENABLED",
146+
"variants": {
147+
"red": "red",
148+
"blue": "blue",
149+
"fallback": "fallback"
150+
},
151+
"defaultVariant": "fallback",
152+
"targeting": {
153+
"fractional": [
154+
{ "var": "targetingKey" },
155+
[
156+
"red",
157+
{
158+
"if": [
159+
{ "==": [{ "var": "tier" }, "premium"] },
160+
100,
161+
0
162+
]
163+
}
164+
],
165+
[ "blue", 10 ]
166+
]
167+
}
168+
},
144169
"starts-ends-flag": {
145170
"state": "ENABLED",
146171
"variants": {

gherkin/targeting.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ Feature: Targeting rules
171171
| jon@company.com | yellow | fallback |
172172
| jon@company.com | | fallback |
173173

174+
@fractional @fractional-nested
175+
Scenario Outline: Fractional operator with nested if expression as weight
176+
# fractional-nested-weight-flag: seed=targetingKey, bucket0=["red",if(tier=="premium",100,0)], bucket1=["blue",10]
177+
Given a String-flag with key "fractional-nested-weight-flag" and a default value "fallback"
178+
And a context containing a targeting key with value "<targetingKey>"
179+
And a context containing a key "tier", with type "String" and with value "<tier>"
180+
When the flag was evaluated with details
181+
Then the resolved details value should be "<value>"
182+
Examples:
183+
| targetingKey | tier | value |
184+
| jon@company.com | premium | red |
185+
| jon@company.com | basic | blue |
186+
| user1 | premium | red |
187+
| user1 | basic | blue |
188+
174189
@string
175190
Scenario Outline: Substring operators
176191
Given a String-flag with key "starts-ends-flag" and a default value "fallback"

0 commit comments

Comments
 (0)