From d69aa78ce896bf458658537aa672275bdb183bc9 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Mon, 22 May 2023 16:09:36 -0300 Subject: [PATCH] UC methods in platform --- .../lib/method_channel_platform.dart | 18 ++++++++++++ .../lib/splitio_platform_interface.dart | 8 +++++ .../test/method_channel_platform_test.dart | 29 +++++++++++++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/splitio_platform_interface/lib/method_channel_platform.dart b/splitio_platform_interface/lib/method_channel_platform.dart index b499305..8132d28 100644 --- a/splitio_platform_interface/lib/method_channel_platform.dart +++ b/splitio_platform_interface/lib/method_channel_platform.dart @@ -324,6 +324,24 @@ class MethodChannelPlatform extends SplitioPlatform { return _impressionsMethodCallHandler.stream(); } + @override + Future getUserConsent() async { + String invokeMethod = + (await _methodChannel.invokeMethod('getUserConsent')) as String; + if (invokeMethod == 'granted') { + return UserConsent.granted; + } else if (invokeMethod == 'declined') { + return UserConsent.declined; + } else { + return UserConsent.unknown; + } + } + + @override + Future setUserConsent(bool enabled) async { + await _methodChannel.invokeMethod('setUserConsent', {'value': enabled}); + } + String _buildMapKey(String matchingKey, String? bucketingKey) { return '${matchingKey}_$bucketingKey'; } diff --git a/splitio_platform_interface/lib/splitio_platform_interface.dart b/splitio_platform_interface/lib/splitio_platform_interface.dart index 729e001..3e71adb 100644 --- a/splitio_platform_interface/lib/splitio_platform_interface.dart +++ b/splitio_platform_interface/lib/splitio_platform_interface.dart @@ -47,6 +47,14 @@ abstract class _FactoryPlatform { Stream impressionsStream() { throw UnimplementedError(); } + + Future getUserConsent() { + throw UnimplementedError(); + } + + Future setUserConsent(bool enabled) { + throw UnimplementedError(); + } } abstract class _ClientPlatform { diff --git a/splitio_platform_interface/test/method_channel_platform_test.dart b/splitio_platform_interface/test/method_channel_platform_test.dart index 72cb4ed..21ed1e2 100644 --- a/splitio_platform_interface/test/method_channel_platform_test.dart +++ b/splitio_platform_interface/test/method_channel_platform_test.dart @@ -54,6 +54,8 @@ void main() { case 'removeAttribute': case 'clearAttributes': return true; + case 'getUserConsent': + return 'declined'; } return null; }); @@ -372,8 +374,8 @@ void main() { apiKey: 'api-key', matchingKey: 'matching-key', bucketingKey: 'bucketing-key', - sdkConfiguration: - SplitConfiguration(logLevel: SplitLogLevel.debug, streamingEnabled: false)); + sdkConfiguration: SplitConfiguration( + logLevel: SplitLogLevel.debug, streamingEnabled: false)); expect(methodName, 'init'); expect(methodArguments, { 'apiKey': 'api-key', @@ -514,4 +516,27 @@ void main() { 'attributes': {} }); }); + + group('userConsent', () { + test('get user consent', () async { + UserConsent userConsent = await _platform.getUserConsent(); + + expect(methodName, 'getUserConsent'); + expect(userConsent, UserConsent.declined); + }); + + test('set user consent enabled', () { + _platform.setUserConsent(true); + + expect(methodName, 'setUserConsent'); + expect(methodArguments, {'value': true}); + }); + + test('set user consent disabled', () { + _platform.setUserConsent(false); + + expect(methodName, 'setUserConsent'); + expect(methodArguments, {'value': false}); + }); + }); }