@@ -8,6 +8,7 @@ import 'package:splitio_platform_interface/split_certificate_pinning_configurati
88import 'package:splitio_platform_interface/split_configuration.dart' ;
99import 'package:splitio_platform_interface/split_evaluation_options.dart' ;
1010import 'package:splitio_platform_interface/split_sync_config.dart' ;
11+ import 'package:splitio_platform_interface/split_result.dart' ;
1112import 'package:splitio_platform_interface/split_rollout_cache_configuration.dart' ;
1213
1314extension on web.Window {
@@ -27,6 +28,52 @@ void main() {
2728 ));
2829 return 'on' .toJS;
2930 }.toJS;
31+ mockClient['getTreatments' ] =
32+ (JSAny ? flagNames, JSAny ? attributes, JSAny ? evaluationOptions) {
33+ calls.add ((
34+ methodName: 'getTreatments' ,
35+ methodArguments: [flagNames, attributes, evaluationOptions]
36+ ));
37+ if (flagNames is JSArray ) {
38+ return flagNames.toDart.fold (JSObject (), (previousValue, element) {
39+ if (element is JSString ) {
40+ previousValue.setProperty (element, 'on' .toJS);
41+ }
42+ return previousValue;
43+ });
44+ }
45+ return JSObject ();
46+ }.toJS;
47+ mockClient['getTreatmentWithConfig' ] =
48+ (JSAny ? flagName, JSAny ? attributes, JSAny ? evaluationOptions) {
49+ calls.add ((
50+ methodName: 'getTreatmentWithConfig' ,
51+ methodArguments: [flagName, attributes, evaluationOptions]
52+ ));
53+ final result = JSObject ();
54+ result.setProperty ('treatment' .toJS, 'on' .toJS);
55+ result.setProperty ('config' .toJS, 'some-config' .toJS);
56+ return result;
57+ }.toJS;
58+ mockClient['getTreatmentsWithConfig' ] =
59+ (JSAny ? flagNames, JSAny ? attributes, JSAny ? evaluationOptions) {
60+ calls.add ((
61+ methodName: 'getTreatmentsWithConfig' ,
62+ methodArguments: [flagNames, attributes, evaluationOptions]
63+ ));
64+ if (flagNames is JSArray ) {
65+ return flagNames.toDart.fold (JSObject (), (previousValue, element) {
66+ if (element is JSString ) {
67+ final result = JSObject ();
68+ result.setProperty ('treatment' .toJS, 'on' .toJS);
69+ result.setProperty ('config' .toJS, 'some-config' .toJS);
70+ previousValue.setProperty (element, result);
71+ }
72+ return previousValue;
73+ });
74+ }
75+ return JSObject ();
76+ }.toJS;
3077
3178 final mockLog = JSObject ();
3279 mockLog['warn' ] = (JSAny ? arg1) {
@@ -170,6 +217,106 @@ void main() {
170217 'Invalid property value: [value1, 100, false], for key: propList, will be ignored' ));
171218 });
172219
220+ test ('getTreatments without attributes' , () async {
221+ final result = await _platform.getTreatments (
222+ matchingKey: 'matching-key' ,
223+ bucketingKey: 'bucketing-key' ,
224+ splitNames: ['split1' , 'split2' ]);
225+
226+ expect (result, {'split1' : 'on' , 'split2' : 'on' });
227+ expect (calls.last.methodName, 'getTreatments' );
228+ expect (calls.last.methodArguments.map (jsAnyToDart), [
229+ ['split1' , 'split2' ],
230+ {},
231+ {}
232+ ]);
233+ });
234+
235+ test ('getTreatments with attributes and evaluation properties' , () async {
236+ final result = await _platform.getTreatments (
237+ matchingKey: 'matching-key' ,
238+ bucketingKey: 'bucketing-key' ,
239+ splitNames: ['split1' , 'split2' ],
240+ attributes: {'attr1' : true });
241+
242+ expect (result, {'split1' : 'on' , 'split2' : 'on' });
243+ expect (calls.last.methodName, 'getTreatments' );
244+ expect (calls.last.methodArguments.map (jsAnyToDart), [
245+ ['split1' , 'split2' ],
246+ {'attr1' : true },
247+ {}
248+ ]);
249+ });
250+
251+ test ('getTreatmentWithConfig with attributes' , () async {
252+ final result = await _platform.getTreatmentWithConfig (
253+ matchingKey: 'matching-key' ,
254+ bucketingKey: 'bucketing-key' ,
255+ splitName: 'split1' ,
256+ attributes: {'attr1' : true });
257+
258+ expect (result.toString (), SplitResult ('on' , 'some-config' ).toString ());
259+ expect (calls.last.methodName, 'getTreatmentWithConfig' );
260+ expect (calls.last.methodArguments.map (jsAnyToDart), [
261+ 'split1' ,
262+ {'attr1' : true },
263+ {}
264+ ]);
265+ });
266+
267+ test ('getTreatmentWithConfig without attributes' , () async {
268+ final result = await _platform.getTreatmentWithConfig (
269+ matchingKey: 'matching-key' ,
270+ bucketingKey: 'bucketing-key' ,
271+ splitName: 'split1' );
272+
273+ expect (result.toString (), SplitResult ('on' , 'some-config' ).toString ());
274+ expect (calls.last.methodName, 'getTreatmentWithConfig' );
275+ expect (calls.last.methodArguments.map (jsAnyToDart), ['split1' , {}, {}]);
276+ });
277+
278+ test ('getTreatmentsWithConfig without attributes' , () async {
279+ final result = await _platform.getTreatmentsWithConfig (
280+ matchingKey: 'matching-key' ,
281+ bucketingKey: 'bucketing-key' ,
282+ splitNames: ['split1' , 'split2' ]);
283+
284+ expect (result, predicate <Map <String , SplitResult >>((result) {
285+ return result.length == 2 &&
286+ result['split1' ].toString () ==
287+ SplitResult ('on' , 'some-config' ).toString () &&
288+ result['split2' ].toString () ==
289+ SplitResult ('on' , 'some-config' ).toString ();
290+ }));
291+ expect (calls.last.methodName, 'getTreatmentsWithConfig' );
292+ expect (calls.last.methodArguments.map (jsAnyToDart), [
293+ ['split1' , 'split2' ],
294+ {},
295+ {}
296+ ]);
297+ });
298+
299+ test ('getTreatmentsWithConfig with attributes' , () async {
300+ final result = await _platform.getTreatmentsWithConfig (
301+ matchingKey: 'matching-key' ,
302+ bucketingKey: 'bucketing-key' ,
303+ splitNames: ['split1' , 'split2' ],
304+ attributes: {'attr1' : true });
305+
306+ expect (result, predicate <Map <String , SplitResult >>((result) {
307+ return result.length == 2 &&
308+ result['split1' ].toString () ==
309+ SplitResult ('on' , 'some-config' ).toString () &&
310+ result['split2' ].toString () ==
311+ SplitResult ('on' , 'some-config' ).toString ();
312+ }));
313+ expect (calls.last.methodName, 'getTreatmentsWithConfig' );
314+ expect (calls.last.methodArguments.map (jsAnyToDart), [
315+ ['split1' , 'split2' ],
316+ {'attr1' : true },
317+ {}
318+ ]);
319+ });
173320 });
174321
175322 group ('initialization' , () {
@@ -429,5 +576,4 @@ void main() {
429576 ]);
430577 });
431578 });
432-
433579}
0 commit comments