Skip to content

Commit 05868d9

Browse files
authored
New evaluation methods in platform (#90)
New evaluation methods in platform
2 parents c91c179 + d31b9f7 commit 05868d9

File tree

3 files changed

+227
-1
lines changed

3 files changed

+227
-1
lines changed

splitio_platform_interface/lib/method_channel_platform.dart

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class MethodChannelPlatform extends SplitioPlatform {
3333
Map<String, Object?> arguments = {
3434
'apiKey': apiKey,
3535
'matchingKey': matchingKey,
36-
'sdkConfiguration': sdkConfiguration?.configurationMap ?? SplitConfiguration().configurationMap, // If sdkConfiguration is null, create a new SplitConfiguration to apply default values
36+
'sdkConfiguration': sdkConfiguration?.configurationMap ??
37+
SplitConfiguration().configurationMap,
38+
// If sdkConfiguration is null, create a new SplitConfiguration to apply default values
3739
};
3840

3941
if (bucketingKey != null) {
@@ -165,6 +167,70 @@ class MethodChannelPlatform extends SplitioPlatform {
165167
{for (var item in splitNames) item: _controlResult};
166168
}
167169

170+
@override
171+
Future<Map<String, String>> getTreatmentsByFlagSet(
172+
{required String matchingKey,
173+
required String? bucketingKey,
174+
required String flagSet,
175+
Map<String, dynamic> attributes = const {}}) async {
176+
Map? treatments = await methodChannel.invokeMapMethod(
177+
'getTreatmentsByFlagSet',
178+
_buildParameters(matchingKey, bucketingKey,
179+
{'flagSet': flagSet, 'attributes': attributes}));
180+
181+
return treatments
182+
?.map((key, value) => MapEntry<String, String>(key, value)) ??
183+
{};
184+
}
185+
186+
@override
187+
Future<Map<String, String>> getTreatmentsByFlagSets(
188+
{required String matchingKey,
189+
required String? bucketingKey,
190+
required List<String> flagSets,
191+
Map<String, dynamic> attributes = const {}}) async {
192+
Map? treatments = await methodChannel.invokeMapMethod(
193+
'getTreatmentsByFlagSets',
194+
_buildParameters(matchingKey, bucketingKey,
195+
{'flagSets': flagSets, 'attributes': attributes}));
196+
197+
return treatments
198+
?.map((key, value) => MapEntry<String, String>(key, value)) ??
199+
{};
200+
}
201+
202+
@override
203+
Future<Map<String, SplitResult>> getTreatmentsWithConfigByFlagSet(
204+
{required String matchingKey,
205+
required String? bucketingKey,
206+
required String flagSet,
207+
Map<String, dynamic> attributes = const {}}) async {
208+
Map? treatments = await methodChannel.invokeMapMethod(
209+
'getTreatmentsWithConfigByFlagSet',
210+
_buildParameters(matchingKey, bucketingKey,
211+
{'flagSet': flagSet, 'attributes': attributes}));
212+
213+
return treatments?.map((key, value) =>
214+
MapEntry(key, SplitResult(value['treatment'], value['config']))) ??
215+
{};
216+
}
217+
218+
@override
219+
Future<Map<String, SplitResult>> getTreatmentsWithConfigByFlagSets(
220+
{required String matchingKey,
221+
required String? bucketingKey,
222+
required List<String> flagSets,
223+
Map<String, dynamic> attributes = const {}}) async {
224+
Map? treatments = await methodChannel.invokeMapMethod(
225+
'getTreatmentsWithConfigByFlagSets',
226+
_buildParameters(matchingKey, bucketingKey,
227+
{'flagSets': flagSets, 'attributes': attributes}));
228+
229+
return treatments?.map((key, value) =>
230+
MapEntry(key, SplitResult(value['treatment'], value['config']))) ??
231+
{};
232+
}
233+
168234
@override
169235
Future<bool> removeAttribute(
170236
{required String matchingKey,

splitio_platform_interface/lib/splitio_platform_interface.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@ abstract class _ClientPlatform {
9090
throw UnimplementedError();
9191
}
9292

93+
Future<Map<String, String>> getTreatmentsByFlagSet(
94+
{required String matchingKey,
95+
required String? bucketingKey,
96+
required String flagSet,
97+
Map<String, dynamic> attributes = const {}}) {
98+
throw UnimplementedError();
99+
}
100+
101+
Future<Map<String, String>> getTreatmentsByFlagSets(
102+
{required String matchingKey,
103+
required String? bucketingKey,
104+
required List<String> flagSets,
105+
Map<String, dynamic> attributes = const {}}) {
106+
throw UnimplementedError();
107+
}
108+
109+
Future<Map<String, SplitResult>> getTreatmentsWithConfigByFlagSet(
110+
{required String matchingKey,
111+
required String? bucketingKey,
112+
required String flagSet,
113+
Map<String, dynamic> attributes = const {}}) {
114+
throw UnimplementedError();
115+
}
116+
117+
Future<Map<String, SplitResult>> getTreatmentsWithConfigByFlagSets(
118+
{required String matchingKey,
119+
required String? bucketingKey,
120+
required List<String> flagSets,
121+
Map<String, dynamic> attributes = const {}}) {
122+
throw UnimplementedError();
123+
}
124+
93125
Future<Map<String, dynamic>> getAllAttributes(
94126
{required String matchingKey, required String? bucketingKey}) {
95127
throw UnimplementedError();

splitio_platform_interface/test/method_channel_platform_test.dart

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ void main() {
3333
case 'getTreatment':
3434
return '';
3535
case 'getTreatments':
36+
case 'getTreatmentsByFlagSet':
37+
case 'getTreatmentsByFlagSets':
3638
return {'split1': 'on', 'split2': 'off'};
3739
case 'getTreatmentsWithConfig':
40+
case 'getTreatmentsWithConfigByFlagSet':
41+
case 'getTreatmentsWithConfigByFlagSets':
3842
return {
3943
'split1': {'treatment': 'on', 'config': null},
4044
'split2': {'treatment': 'off', 'config': null}
@@ -185,6 +189,130 @@ void main() {
185189
'attributes': {'attr1': true}
186190
});
187191
});
192+
193+
test('getTreatmentsByFlagSet without attributes', () async {
194+
_platform.getTreatmentsByFlagSet(
195+
matchingKey: 'matching-key',
196+
bucketingKey: 'bucketing-key',
197+
flagSet: 'set_1');
198+
199+
expect(methodName, 'getTreatmentsByFlagSet');
200+
expect(methodArguments, {
201+
'flagSet': 'set_1',
202+
'matchingKey': 'matching-key',
203+
'bucketingKey': 'bucketing-key',
204+
'attributes': {}
205+
});
206+
});
207+
208+
test('getTreatmentsByFlagSet with attributes', () async {
209+
_platform.getTreatmentsByFlagSet(
210+
matchingKey: 'matching-key',
211+
bucketingKey: 'bucketing-key',
212+
flagSet: 'set_1',
213+
attributes: {'attr1': true});
214+
215+
expect(methodName, 'getTreatmentsByFlagSet');
216+
expect(methodArguments, {
217+
'flagSet': 'set_1',
218+
'matchingKey': 'matching-key',
219+
'bucketingKey': 'bucketing-key',
220+
'attributes': {'attr1': true}
221+
});
222+
});
223+
224+
test('getTreatmentsByFlagSets without attributes', () async {
225+
_platform.getTreatmentsByFlagSets(
226+
matchingKey: 'matching-key',
227+
bucketingKey: 'bucketing-key',
228+
flagSets: ['set_1', 'set_2']);
229+
230+
expect(methodName, 'getTreatmentsByFlagSets');
231+
expect(methodArguments, {
232+
'flagSets': ['set_1', 'set_2'],
233+
'matchingKey': 'matching-key',
234+
'bucketingKey': 'bucketing-key',
235+
'attributes': {}
236+
});
237+
});
238+
239+
test('getTreatmentsByFlagSets with attributes', () async {
240+
_platform.getTreatmentsByFlagSets(
241+
matchingKey: 'matching-key',
242+
bucketingKey: 'bucketing-key',
243+
flagSets: ['set_1', 'set_2'],
244+
attributes: {'attr1': true});
245+
246+
expect(methodName, 'getTreatmentsByFlagSets');
247+
expect(methodArguments, {
248+
'flagSets': ['set_1', 'set_2'],
249+
'matchingKey': 'matching-key',
250+
'bucketingKey': 'bucketing-key',
251+
'attributes': {'attr1': true}
252+
});
253+
});
254+
255+
test('getTreatmentsWithConfigByFlagSet without attributes', () async {
256+
_platform.getTreatmentsWithConfigByFlagSet(
257+
matchingKey: 'matching-key',
258+
bucketingKey: 'bucketing-key',
259+
flagSet: 'set_1');
260+
261+
expect(methodName, 'getTreatmentsWithConfigByFlagSet');
262+
expect(methodArguments, {
263+
'flagSet': 'set_1',
264+
'matchingKey': 'matching-key',
265+
'bucketingKey': 'bucketing-key',
266+
'attributes': {}
267+
});
268+
});
269+
270+
test('getTreatmentsWithConfigByFlagSet with attributes', () async {
271+
_platform.getTreatmentsWithConfigByFlagSet(
272+
matchingKey: 'matching-key',
273+
bucketingKey: 'bucketing-key',
274+
flagSet: 'set_1',
275+
attributes: {'attr1': true});
276+
277+
expect(methodName, 'getTreatmentsWithConfigByFlagSet');
278+
expect(methodArguments, {
279+
'flagSet': 'set_1',
280+
'matchingKey': 'matching-key',
281+
'bucketingKey': 'bucketing-key',
282+
'attributes': {'attr1': true}
283+
});
284+
});
285+
286+
test('getTreatmentsWithConfigByFlagSets without attributes', () async {
287+
_platform.getTreatmentsWithConfigByFlagSets(
288+
matchingKey: 'matching-key',
289+
bucketingKey: 'bucketing-key',
290+
flagSets: ['set_1', 'set_2']);
291+
292+
expect(methodName, 'getTreatmentsWithConfigByFlagSets');
293+
expect(methodArguments, {
294+
'flagSets': ['set_1', 'set_2'],
295+
'matchingKey': 'matching-key',
296+
'bucketingKey': 'bucketing-key',
297+
'attributes': {}
298+
});
299+
});
300+
301+
test('getTreatmentsWithConfigByFlagSets with attributes', () async {
302+
_platform.getTreatmentsWithConfigByFlagSets(
303+
matchingKey: 'matching-key',
304+
bucketingKey: 'bucketing-key',
305+
flagSets: ['set_1', 'set_2'],
306+
attributes: {'attr1': true});
307+
308+
expect(methodName, 'getTreatmentsWithConfigByFlagSets');
309+
expect(methodArguments, {
310+
'flagSets': ['set_1', 'set_2'],
311+
'matchingKey': 'matching-key',
312+
'bucketingKey': 'bucketing-key',
313+
'attributes': {'attr1': true}
314+
});
315+
});
188316
});
189317

190318
group('track', () {

0 commit comments

Comments
 (0)