diff --git a/splitio_platform_interface/lib/method_channel_platform.dart b/splitio_platform_interface/lib/method_channel_platform.dart index 4bc0400..d3fb11d 100644 --- a/splitio_platform_interface/lib/method_channel_platform.dart +++ b/splitio_platform_interface/lib/method_channel_platform.dart @@ -33,7 +33,9 @@ class MethodChannelPlatform extends SplitioPlatform { Map arguments = { 'apiKey': apiKey, 'matchingKey': matchingKey, - 'sdkConfiguration': sdkConfiguration?.configurationMap ?? SplitConfiguration().configurationMap, // If sdkConfiguration is null, create a new SplitConfiguration to apply default values + 'sdkConfiguration': sdkConfiguration?.configurationMap ?? + SplitConfiguration().configurationMap, + // If sdkConfiguration is null, create a new SplitConfiguration to apply default values }; if (bucketingKey != null) { @@ -165,6 +167,70 @@ class MethodChannelPlatform extends SplitioPlatform { {for (var item in splitNames) item: _controlResult}; } + @override + Future> getTreatmentsByFlagSet( + {required String matchingKey, + required String? bucketingKey, + required String flagSet, + Map attributes = const {}}) async { + Map? treatments = await methodChannel.invokeMapMethod( + 'getTreatmentsByFlagSet', + _buildParameters(matchingKey, bucketingKey, + {'flagSet': flagSet, 'attributes': attributes})); + + return treatments + ?.map((key, value) => MapEntry(key, value)) ?? + {}; + } + + @override + Future> getTreatmentsByFlagSets( + {required String matchingKey, + required String? bucketingKey, + required List flagSets, + Map attributes = const {}}) async { + Map? treatments = await methodChannel.invokeMapMethod( + 'getTreatmentsByFlagSets', + _buildParameters(matchingKey, bucketingKey, + {'flagSets': flagSets, 'attributes': attributes})); + + return treatments + ?.map((key, value) => MapEntry(key, value)) ?? + {}; + } + + @override + Future> getTreatmentsWithConfigByFlagSet( + {required String matchingKey, + required String? bucketingKey, + required String flagSet, + Map attributes = const {}}) async { + Map? treatments = await methodChannel.invokeMapMethod( + 'getTreatmentsWithConfigByFlagSet', + _buildParameters(matchingKey, bucketingKey, + {'flagSet': flagSet, 'attributes': attributes})); + + return treatments?.map((key, value) => + MapEntry(key, SplitResult(value['treatment'], value['config']))) ?? + {}; + } + + @override + Future> getTreatmentsWithConfigByFlagSets( + {required String matchingKey, + required String? bucketingKey, + required List flagSets, + Map attributes = const {}}) async { + Map? treatments = await methodChannel.invokeMapMethod( + 'getTreatmentsWithConfigByFlagSets', + _buildParameters(matchingKey, bucketingKey, + {'flagSets': flagSets, 'attributes': attributes})); + + return treatments?.map((key, value) => + MapEntry(key, SplitResult(value['treatment'], value['config']))) ?? + {}; + } + @override Future removeAttribute( {required String matchingKey, diff --git a/splitio_platform_interface/lib/splitio_platform_interface.dart b/splitio_platform_interface/lib/splitio_platform_interface.dart index 3e71adb..a367fdf 100644 --- a/splitio_platform_interface/lib/splitio_platform_interface.dart +++ b/splitio_platform_interface/lib/splitio_platform_interface.dart @@ -90,6 +90,38 @@ abstract class _ClientPlatform { throw UnimplementedError(); } + Future> getTreatmentsByFlagSet( + {required String matchingKey, + required String? bucketingKey, + required String flagSet, + Map attributes = const {}}) { + throw UnimplementedError(); + } + + Future> getTreatmentsByFlagSets( + {required String matchingKey, + required String? bucketingKey, + required List flagSets, + Map attributes = const {}}) { + throw UnimplementedError(); + } + + Future> getTreatmentsWithConfigByFlagSet( + {required String matchingKey, + required String? bucketingKey, + required String flagSet, + Map attributes = const {}}) { + throw UnimplementedError(); + } + + Future> getTreatmentsWithConfigByFlagSets( + {required String matchingKey, + required String? bucketingKey, + required List flagSets, + Map attributes = const {}}) { + throw UnimplementedError(); + } + Future> getAllAttributes( {required String matchingKey, required String? bucketingKey}) { throw UnimplementedError(); diff --git a/splitio_platform_interface/test/method_channel_platform_test.dart b/splitio_platform_interface/test/method_channel_platform_test.dart index d03c4f5..5dceddf 100644 --- a/splitio_platform_interface/test/method_channel_platform_test.dart +++ b/splitio_platform_interface/test/method_channel_platform_test.dart @@ -33,8 +33,12 @@ void main() { case 'getTreatment': return ''; case 'getTreatments': + case 'getTreatmentsByFlagSet': + case 'getTreatmentsByFlagSets': return {'split1': 'on', 'split2': 'off'}; case 'getTreatmentsWithConfig': + case 'getTreatmentsWithConfigByFlagSet': + case 'getTreatmentsWithConfigByFlagSets': return { 'split1': {'treatment': 'on', 'config': null}, 'split2': {'treatment': 'off', 'config': null} @@ -185,6 +189,130 @@ void main() { 'attributes': {'attr1': true} }); }); + + test('getTreatmentsByFlagSet without attributes', () async { + _platform.getTreatmentsByFlagSet( + matchingKey: 'matching-key', + bucketingKey: 'bucketing-key', + flagSet: 'set_1'); + + expect(methodName, 'getTreatmentsByFlagSet'); + expect(methodArguments, { + 'flagSet': 'set_1', + 'matchingKey': 'matching-key', + 'bucketingKey': 'bucketing-key', + 'attributes': {} + }); + }); + + test('getTreatmentsByFlagSet with attributes', () async { + _platform.getTreatmentsByFlagSet( + matchingKey: 'matching-key', + bucketingKey: 'bucketing-key', + flagSet: 'set_1', + attributes: {'attr1': true}); + + expect(methodName, 'getTreatmentsByFlagSet'); + expect(methodArguments, { + 'flagSet': 'set_1', + 'matchingKey': 'matching-key', + 'bucketingKey': 'bucketing-key', + 'attributes': {'attr1': true} + }); + }); + + test('getTreatmentsByFlagSets without attributes', () async { + _platform.getTreatmentsByFlagSets( + matchingKey: 'matching-key', + bucketingKey: 'bucketing-key', + flagSets: ['set_1', 'set_2']); + + expect(methodName, 'getTreatmentsByFlagSets'); + expect(methodArguments, { + 'flagSets': ['set_1', 'set_2'], + 'matchingKey': 'matching-key', + 'bucketingKey': 'bucketing-key', + 'attributes': {} + }); + }); + + test('getTreatmentsByFlagSets with attributes', () async { + _platform.getTreatmentsByFlagSets( + matchingKey: 'matching-key', + bucketingKey: 'bucketing-key', + flagSets: ['set_1', 'set_2'], + attributes: {'attr1': true}); + + expect(methodName, 'getTreatmentsByFlagSets'); + expect(methodArguments, { + 'flagSets': ['set_1', 'set_2'], + 'matchingKey': 'matching-key', + 'bucketingKey': 'bucketing-key', + 'attributes': {'attr1': true} + }); + }); + + test('getTreatmentsWithConfigByFlagSet without attributes', () async { + _platform.getTreatmentsWithConfigByFlagSet( + matchingKey: 'matching-key', + bucketingKey: 'bucketing-key', + flagSet: 'set_1'); + + expect(methodName, 'getTreatmentsWithConfigByFlagSet'); + expect(methodArguments, { + 'flagSet': 'set_1', + 'matchingKey': 'matching-key', + 'bucketingKey': 'bucketing-key', + 'attributes': {} + }); + }); + + test('getTreatmentsWithConfigByFlagSet with attributes', () async { + _platform.getTreatmentsWithConfigByFlagSet( + matchingKey: 'matching-key', + bucketingKey: 'bucketing-key', + flagSet: 'set_1', + attributes: {'attr1': true}); + + expect(methodName, 'getTreatmentsWithConfigByFlagSet'); + expect(methodArguments, { + 'flagSet': 'set_1', + 'matchingKey': 'matching-key', + 'bucketingKey': 'bucketing-key', + 'attributes': {'attr1': true} + }); + }); + + test('getTreatmentsWithConfigByFlagSets without attributes', () async { + _platform.getTreatmentsWithConfigByFlagSets( + matchingKey: 'matching-key', + bucketingKey: 'bucketing-key', + flagSets: ['set_1', 'set_2']); + + expect(methodName, 'getTreatmentsWithConfigByFlagSets'); + expect(methodArguments, { + 'flagSets': ['set_1', 'set_2'], + 'matchingKey': 'matching-key', + 'bucketingKey': 'bucketing-key', + 'attributes': {} + }); + }); + + test('getTreatmentsWithConfigByFlagSets with attributes', () async { + _platform.getTreatmentsWithConfigByFlagSets( + matchingKey: 'matching-key', + bucketingKey: 'bucketing-key', + flagSets: ['set_1', 'set_2'], + attributes: {'attr1': true}); + + expect(methodName, 'getTreatmentsWithConfigByFlagSets'); + expect(methodArguments, { + 'flagSets': ['set_1', 'set_2'], + 'matchingKey': 'matching-key', + 'bucketingKey': 'bucketing-key', + 'attributes': {'attr1': true} + }); + }); }); group('track', () {