Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion splitio_platform_interface/lib/method_channel_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class MethodChannelPlatform extends SplitioPlatform {
Map<String, Object?> 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) {
Expand Down Expand Up @@ -165,6 +167,70 @@ class MethodChannelPlatform extends SplitioPlatform {
{for (var item in splitNames) item: _controlResult};
}

@override
Future<Map<String, String>> getTreatmentsByFlagSet(
{required String matchingKey,
required String? bucketingKey,
required String flagSet,
Map<String, dynamic> attributes = const {}}) async {
Map? treatments = await methodChannel.invokeMapMethod(
'getTreatmentsByFlagSet',
_buildParameters(matchingKey, bucketingKey,
{'flagSet': flagSet, 'attributes': attributes}));

return treatments
?.map((key, value) => MapEntry<String, String>(key, value)) ??
{};
}

@override
Future<Map<String, String>> getTreatmentsByFlagSets(
{required String matchingKey,
required String? bucketingKey,
required List<String> flagSets,
Map<String, dynamic> attributes = const {}}) async {
Map? treatments = await methodChannel.invokeMapMethod(
'getTreatmentsByFlagSets',
_buildParameters(matchingKey, bucketingKey,
{'flagSets': flagSets, 'attributes': attributes}));

return treatments
?.map((key, value) => MapEntry<String, String>(key, value)) ??
{};
}

@override
Future<Map<String, SplitResult>> getTreatmentsWithConfigByFlagSet(
{required String matchingKey,
required String? bucketingKey,
required String flagSet,
Map<String, dynamic> 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<Map<String, SplitResult>> getTreatmentsWithConfigByFlagSets(
{required String matchingKey,
required String? bucketingKey,
required List<String> flagSets,
Map<String, dynamic> 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<bool> removeAttribute(
{required String matchingKey,
Expand Down
32 changes: 32 additions & 0 deletions splitio_platform_interface/lib/splitio_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ abstract class _ClientPlatform {
throw UnimplementedError();
}

Future<Map<String, String>> getTreatmentsByFlagSet(
{required String matchingKey,
required String? bucketingKey,
required String flagSet,
Map<String, dynamic> attributes = const {}}) {
throw UnimplementedError();
}

Future<Map<String, String>> getTreatmentsByFlagSets(
{required String matchingKey,
required String? bucketingKey,
required List<String> flagSets,
Map<String, dynamic> attributes = const {}}) {
throw UnimplementedError();
}

Future<Map<String, SplitResult>> getTreatmentsWithConfigByFlagSet(
{required String matchingKey,
required String? bucketingKey,
required String flagSet,
Map<String, dynamic> attributes = const {}}) {
throw UnimplementedError();
}

Future<Map<String, SplitResult>> getTreatmentsWithConfigByFlagSets(
{required String matchingKey,
required String? bucketingKey,
required List<String> flagSets,
Map<String, dynamic> attributes = const {}}) {
throw UnimplementedError();
}

Future<Map<String, dynamic>> getAllAttributes(
{required String matchingKey, required String? bucketingKey}) {
throw UnimplementedError();
Expand Down
128 changes: 128 additions & 0 deletions splitio_platform_interface/test/method_channel_platform_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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', () {
Expand Down