Skip to content

Commit c2748d4

Browse files
emyllerclaude
andcommitted
Add mapper test cases for environment document to evaluation context conversion
Co-authored-by: Claude <[email protected]>
1 parent 0d9040a commit c2748d4

File tree

2 files changed

+301
-1
lines changed

2 files changed

+301
-1
lines changed
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
{
2+
"environment_document": {
3+
"api_key": "B62qaMZNwfiqT76p38ggrQ",
4+
"name": "Test environment",
5+
"project": {
6+
"name": "Test project",
7+
"organisation": {
8+
"feature_analytics": false,
9+
"name": "Test Org",
10+
"id": 1,
11+
"persist_trait_data": true,
12+
"stop_serving_flags": false
13+
},
14+
"id": 1,
15+
"hide_disabled_flags": false,
16+
"segments": [
17+
{
18+
"id": 1,
19+
"name": "Test segment",
20+
"rules": [
21+
{
22+
"type": "ALL",
23+
"rules": [
24+
{
25+
"type": "ALL",
26+
"rules": [],
27+
"conditions": [
28+
{
29+
"operator": "EQUAL",
30+
"property_": "foo",
31+
"value": "bar"
32+
}
33+
]
34+
}
35+
]
36+
}
37+
]
38+
}
39+
]
40+
},
41+
"segment_overrides": [],
42+
"id": 1,
43+
"feature_states": [
44+
{
45+
"feature_state_value": "some-value",
46+
"id": 1,
47+
"featurestate_uuid": "00000000-0000-0000-0000-000000000000",
48+
"feature": {
49+
"name": "some_feature",
50+
"type": "STANDARD",
51+
"id": 1
52+
},
53+
"segment_id": null,
54+
"enabled": true,
55+
"multivariate_feature_state_values": []
56+
},
57+
{
58+
"feature_state_value": "default_value",
59+
"django_id": 2,
60+
"featurestate_uuid": "11111111-1111-1111-1111-111111111111",
61+
"feature": {
62+
"name": "mv_feature_with_ids",
63+
"type": "MULTIVARIATE",
64+
"id": 2
65+
},
66+
"segment_id": null,
67+
"enabled": true,
68+
"multivariate_feature_state_values": [
69+
{
70+
"id": 100,
71+
"multivariate_feature_option": {
72+
"id": 10,
73+
"value": "variant_a"
74+
},
75+
"mv_fs_value_uuid": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
76+
"percentage_allocation": 30.0
77+
},
78+
{
79+
"id": 200,
80+
"multivariate_feature_option": {
81+
"id": 20,
82+
"value": "variant_b"
83+
},
84+
"mv_fs_value_uuid": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
85+
"percentage_allocation": 70.0
86+
}
87+
]
88+
},
89+
{
90+
"feature_state_value": "fallback_value",
91+
"django_id": 3,
92+
"featurestate_uuid": "22222222-2222-2222-2222-222222222222",
93+
"feature": {
94+
"name": "mv_feature_without_ids",
95+
"type": "MULTIVARIATE",
96+
"id": 3
97+
},
98+
"segment_id": null,
99+
"enabled": false,
100+
"multivariate_feature_state_values": [
101+
{
102+
"multivariate_feature_option": {
103+
"id": 40,
104+
"value": "option_y"
105+
},
106+
"mv_fs_value_uuid": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
107+
"percentage_allocation": 50.0
108+
},
109+
{
110+
"multivariate_feature_option": {
111+
"id": 30,
112+
"value": "option_x"
113+
},
114+
"mv_fs_value_uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
115+
"percentage_allocation": 25.0
116+
},
117+
{
118+
"multivariate_feature_option": {
119+
"id": 50,
120+
"value": "option_z"
121+
},
122+
"mv_fs_value_uuid": "zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz",
123+
"percentage_allocation": 25.0
124+
}
125+
]
126+
}
127+
],
128+
"identity_overrides": [
129+
{
130+
"identifier": "overridden-id",
131+
"identity_uuid": "0f21cde8-63c5-4e50-baca-87897fa6cd01",
132+
"created_date": "2019-08-27T14:53:45.698555Z",
133+
"updated_at": "2023-07-14 16:12:00.000000",
134+
"environment_api_key": "B62qaMZNwfiqT76p38ggrQ",
135+
"identity_features": [
136+
{
137+
"id": 1,
138+
"feature": {
139+
"id": 1,
140+
"name": "some_feature",
141+
"type": "STANDARD"
142+
},
143+
"featurestate_uuid": "1bddb9a5-7e59-42c6-9be9-625fa369749f",
144+
"feature_state_value": "some-overridden-value",
145+
"enabled": false,
146+
"environment": 1,
147+
"identity": null,
148+
"feature_segment": null
149+
}
150+
]
151+
}
152+
]
153+
},
154+
"expected_evaluation_context": {
155+
"environment": {
156+
"key": "B62qaMZNwfiqT76p38ggrQ",
157+
"name": "Test environment"
158+
},
159+
"identity": null,
160+
"segments": {
161+
"0": {
162+
"key": "1",
163+
"name": "Test segment",
164+
"rules": [
165+
{
166+
"type": "ALL",
167+
"conditions": [],
168+
"rules": [
169+
{
170+
"type": "ALL",
171+
"conditions": [
172+
{
173+
"property": "foo",
174+
"operator": "EQUAL",
175+
"value": "bar"
176+
}
177+
],
178+
"rules": []
179+
}
180+
]
181+
}
182+
],
183+
"overrides": [],
184+
"metadata": {
185+
"source": "api",
186+
"id": 1
187+
}
188+
},
189+
"1011e8db6ebc6fc7d7ad32c3c49e6b2b79ea110abfd8bb9eaa0a228e1b924a74": {
190+
"key": "",
191+
"name": "identity_overrides",
192+
"rules": [
193+
{
194+
"type": "ALL",
195+
"conditions": [
196+
{
197+
"property": "$.identity.identifier",
198+
"operator": "IN",
199+
"value": ["overridden-id"]
200+
}
201+
],
202+
"rules": null
203+
}
204+
],
205+
"overrides": [
206+
{
207+
"key": "",
208+
"name": "some_feature",
209+
"enabled": false,
210+
"value": "some-overridden-value",
211+
"priority": "-INF",
212+
"variants": null,
213+
"metadata": {
214+
"id": 1
215+
}
216+
}
217+
],
218+
"metadata": {
219+
"source": "identity_override"
220+
}
221+
}
222+
},
223+
"features": {
224+
"some_feature": {
225+
"key": "00000000-0000-0000-0000-000000000000",
226+
"name": "some_feature",
227+
"enabled": true,
228+
"value": "some-value",
229+
"priority": null,
230+
"variants": [],
231+
"metadata": {
232+
"id": 1
233+
}
234+
},
235+
"mv_feature_with_ids": {
236+
"key": "2",
237+
"name": "mv_feature_with_ids",
238+
"enabled": true,
239+
"value": "default_value",
240+
"priority": null,
241+
"variants": [
242+
{
243+
"value": "variant_a",
244+
"weight": 30.0,
245+
"priority": 100
246+
},
247+
{
248+
"value": "variant_b",
249+
"weight": 70.0,
250+
"priority": 200
251+
}
252+
],
253+
"metadata": {
254+
"id": 2
255+
}
256+
},
257+
"mv_feature_without_ids": {
258+
"key": "3",
259+
"name": "mv_feature_without_ids",
260+
"enabled": false,
261+
"value": "fallback_value",
262+
"priority": null,
263+
"variants": [
264+
{
265+
"value": "option_y",
266+
"weight": 50.0,
267+
"priority": 1
268+
},
269+
{
270+
"value": "option_x",
271+
"weight": 25.0,
272+
"priority": 0
273+
},
274+
{
275+
"value": "option_z",
276+
"weight": 25.0,
277+
"priority": 2
278+
}
279+
],
280+
"metadata": {
281+
"id": 3
282+
}
283+
}
284+
}
285+
}
286+
}

readme.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
# Engine Test Data
22

3+
> [!NOTE]
4+
> Test case files may contain descriptions in JSON5-compliant comments. Test implementations should be ready to parse JSON5.
5+
36
E2E tests for all Flagsmith Engine implementations.
47

8+
## Engine Evaluation Tests
9+
510
Test cases ported from v1 are named in the pattern of `test_case/test_{context_value}__{matching_segments}.json`, where:
611
- `{context_value}` is the main context value matched in the case — usually, `$.identity.identifier`.
712
- `{matching_segments}` is a dunder-delimited matched segments list, e.g. `segment_two__segment_three`. In case no segments match, `default` is used.
813

914
Single test case contents are described with [schema.json](./schema.json) JSONSchema.
1015

11-
A test case file may contain a test description in the form of a JSON5-compliant comment in the beginning of the file. Test implementations should be ready to parse JSON5.
16+
## Mapper Tests
17+
18+
> [!WARNING]
19+
> Mapper tests exist only to support safe deprecation of the environment document. These tests validate the conversion layer between the legacy environment document format and the evaluation context.
20+
21+
Mapper test cases validate the conversion from environment documents to evaluation contexts. Test files are located in `mapper_test_cases/` and follow the naming pattern `test_mapper__{description}.jsonc`.
22+
23+
Each mapper test case contains:
24+
- `environment_document`: The input environment document
25+
- `expected_evaluation_context`: The expected output evaluation context

0 commit comments

Comments
 (0)