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
8 changes: 8 additions & 0 deletions splitio/lib/splitio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class Splitio {
return _platform.split(splitName: splitName);
}

Future<UserConsent> getUserConsent() async {
return _platform.getUserConsent();
}

Future<void> setUserConsent(bool enabled) async {
return _platform.setUserConsent(enabled);
}

Future<void> _init() {
return _platform.init(
apiKey: _sdkKey,
Expand Down
12 changes: 9 additions & 3 deletions splitio/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ flutter:
dependencies:
flutter:
sdk: flutter
splitio_android: ^0.1.3
splitio_ios: ^0.1.3
splitio_platform_interface: ^1.1.0
# splitio_android: ^0.1.3
splitio_android:
path: ../splitio_android
# splitio_ios: ^0.1.3
splitio_ios:
path: ../splitio_ios
# splitio_platform_interface: ^1.1.0
splitio_platform_interface:
path: ../splitio_platform_interface

dev_dependencies:
flutter_test:
Expand Down
15 changes: 15 additions & 0 deletions splitio/test/splitio_platform_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,19 @@ class SplitioPlatformStub

return Future.value(true);
}

@override
Future<UserConsent> getUserConsent() {
methodName = 'getUserConsent';

return Future.value(UserConsent.granted);
}

@override
Future<void> setUserConsent(bool enabled) {
methodName = 'setUserConsent';
methodArguments['value'] = enabled;

return Future.value(null);
}
}
22 changes: 22 additions & 0 deletions splitio/test/splitio_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,26 @@ void main() {
expect(_platform.methodArguments, {'splitName': 'my_split'});
});
});

group('userConsent', () {
test('get user consent', () async {
var splitio = Splitio('api-key', 'matching-key');
splitio.getUserConsent();

expect(_platform.methodName, 'getUserConsent');
});

test('set user consent', () async {
var splitio = Splitio('api-key', 'matching-key');
splitio.setUserConsent(true);

expect(_platform.methodName, 'setUserConsent');
expect(_platform.methodArguments, {
'matchingKey': 'matching-key',
'apiKey': 'api-key',
'sdkConfiguration': {},
'value': true,
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static class Method {
static final String SPLIT_NAMES = "splitNames";
static final String SPLIT = "split";
static final String IMPRESSION_LOG = "impressionLog";
static final String GET_USER_CONSENT = "getUserConsent";
static final String SET_USER_CONSENT = "setUserConsent";
}

static class Argument {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import static io.split.splitio.Constants.Method.GET_TREATMENTS;
import static io.split.splitio.Constants.Method.GET_TREATMENTS_WITH_CONFIG;
import static io.split.splitio.Constants.Method.GET_TREATMENT_WITH_CONFIG;
import static io.split.splitio.Constants.Method.GET_USER_CONSENT;
import static io.split.splitio.Constants.Method.INIT;
import static io.split.splitio.Constants.Method.REMOVE_ATTRIBUTE;
import static io.split.splitio.Constants.Method.SET_ATTRIBUTE;
import static io.split.splitio.Constants.Method.SET_ATTRIBUTES;
import static io.split.splitio.Constants.Method.SET_USER_CONSENT;
import static io.split.splitio.Constants.Method.SPLIT;
import static io.split.splitio.Constants.Method.SPLITS;
import static io.split.splitio.Constants.Method.SPLIT_NAMES;
Expand Down Expand Up @@ -195,6 +197,13 @@ public void onMethodCall(String methodName, Object arguments, @NonNull MethodCha
case SPLIT:
result.success(getSplitViewAsMap(mSplitWrapper.split(mArgumentParser.getStringArgument(SPLIT_NAME, arguments))));
break;
case GET_USER_CONSENT:
result.success(mSplitWrapper.getUserConsent());
break;
case SET_USER_CONSENT:
mSplitWrapper.setUserConsent(mArgumentParser.getBooleanArgument(VALUE, arguments));
result.success(null);
break;
default:
result.notImplemented();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ interface SplitWrapper extends EvaluationWrapper, AttributesWrapper {

@Nullable
SplitView split(String splitName);

String getUserConsent();

void setUserConsent(boolean enabled);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.split.android.client.SplitResult;
import io.split.android.client.api.Key;
import io.split.android.client.api.SplitView;
import io.split.android.client.shared.UserConsent;
import io.split.android.client.utils.ConcurrentSet;
import io.split.android.grammar.Treatments;

Expand Down Expand Up @@ -222,4 +223,21 @@ public List<SplitView> splits() {
public SplitView split(String splitName) {
return mSplitFactory.manager().split(splitName);
}

@Override
public String getUserConsent() {
UserConsent userConsent = mSplitFactory.getUserConsent();
if (userConsent == UserConsent.GRANTED) {
return "granted";
} else if (userConsent == UserConsent.DECLINED) {
return "declined";
} else {
return "unknown";
}
}

@Override
public void setUserConsent(boolean enabled) {
mSplitFactory.setUserConsent(enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,33 @@ public void initialization() {
eq("bucketing-key"),
argThat(splitClientConfig -> splitClientConfig.impressionListener() != null && !splitClientConfig.streamingEnabled()));
}

@Test
public void getUserConsent() {
when(mSplitWrapper.getUserConsent()).thenReturn("granted");
mMethodParser.onMethodCall("getUserConsent", Collections.emptyMap(), mResult);

verify(mResult).success("granted");
verify(mSplitWrapper).getUserConsent();
}

@Test
public void setUserConsentEnabled() {
when(mArgumentParser.getBooleanArgument("value", Collections.singletonMap("value", true))).thenReturn(true);
when(mArgumentParser.getBooleanArgument("value", Collections.singletonMap("value", false))).thenReturn(false);
mMethodParser.onMethodCall("setUserConsent", Collections.singletonMap("value", true), mResult);

verify(mResult).success(null);
verify(mSplitWrapper).setUserConsent(true);
}

@Test
public void setUserConsentDisabled() {
when(mArgumentParser.getBooleanArgument("value", Collections.singletonMap("value", true))).thenReturn(true);
when(mArgumentParser.getBooleanArgument("value", Collections.singletonMap("value", false))).thenReturn(false);
mMethodParser.onMethodCall("setUserConsent", Collections.singletonMap("value", false), mResult);

verify(mResult).success(null);
verify(mSplitWrapper).setUserConsent(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.split.android.client.SplitFactory;
import io.split.android.client.SplitManager;
import io.split.android.client.api.Key;
import io.split.android.client.shared.UserConsent;

public class SplitWrapperImplTest {

Expand Down Expand Up @@ -277,4 +278,19 @@ public void testSplit() {

verify(managerMock).split("my_split");
}

@Test
public void testGetUserConsent() {
when(mSplitFactory.getUserConsent()).thenReturn(UserConsent.DECLINED);
String userConsent = mSplitWrapper.getUserConsent();

verify(mSplitFactory).getUserConsent();
assertEquals("declined", userConsent);
}

@Test
public void testSetUserConsent() {
mSplitWrapper.setUserConsent(true);
verify(mSplitFactory).setUserConsent(true);
}
}
4 changes: 3 additions & 1 deletion splitio_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ flutter:
dependencies:
flutter:
sdk: flutter
splitio_platform_interface: ^1.1.0
# splitio_platform_interface: ^1.1.0
splitio_platform_interface:
path: ../splitio_platform_interface

dev_dependencies:
flutter_test:
Expand Down
23 changes: 23 additions & 0 deletions splitio_android/test/splitio_android_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,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, {'enabled': true});
});

test('set user consent disabled', () {
_platform.setUserConsent(false);

expect(methodName, 'setUserConsent');
expect(methodArguments, {'enabled': false});
});
});
}
35 changes: 35 additions & 0 deletions splitio_ios/example/ios/SplitTests/SplitMethodParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,28 @@ class SplitMethodParserTests: XCTestCase {
XCTAssert(providerHelper.splitClientConfigValue?.impressionListener != nil)
XCTAssert(providerHelper.splitClientConfigValue?.streamingEnabled == false)
}

func testGetUserConsent() {
methodParser?.onMethodCall(methodName: "getUserConsent", arguments: [], result: { (_: Any?) in })

guard let wrapper = splitWrapper as? SplitWrapperStub else {
XCTFail()
return
}

XCTAssert(wrapper.userConsent == "unknown")
}

func testSetUserConsent() {
methodParser?.onMethodCall(methodName: "setUserConsent", arguments: [], result: { (_: Any?) in })

guard let wrapper = splitWrapper as? SplitWrapperStub else {
XCTFail()
return
}

XCTAssert(wrapper.userConsent == "declined")
}
}

class SplitWrapperStub: SplitWrapper {
Expand All @@ -316,6 +338,7 @@ class SplitWrapperStub: SplitWrapper {
var attributeNameValue: String = ""
var splitsCalled = false
var splitNamesCalled = false
var userConsent = "unknown"

func getClient(matchingKey: String, bucketingKey: String?) -> SplitClient? {
matchingKeyValue = matchingKey
Expand Down Expand Up @@ -440,6 +463,18 @@ class SplitWrapperStub: SplitWrapper {
splitNameValue = splitName
return nil
}

func getUserConsent() -> String {
return userConsent
}

func setUserConsent(enabled: Bool) {
if (enabled) {
userConsent = "granted"
} else {
userConsent = "declined"
}
}
}

class SplitProviderHelperStub: SplitProviderHelper {
Expand Down
20 changes: 20 additions & 0 deletions splitio_ios/example/ios/SplitTests/SplitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ class SplitTests: XCTestCase {
let split = splitWrapper.split(splitName: "my-split")
XCTAssert(manager.splitNameValue == "my-split")
}

func testGetUserConsent() {
let manager = SplitManagerStub()
let factoryProvider = SplitFactoryProviderStub(manager: manager)
splitWrapper = DefaultSplitWrapper(splitFactoryProvider: factoryProvider)
let userConsent = splitWrapper.getUserConsent()
XCTAssert(userConsent == "unknown")
}

func testSetUserConsent() {
let manager = SplitManagerStub()
let factoryProvider = SplitFactoryProviderStub(manager: manager)
splitWrapper = DefaultSplitWrapper(splitFactoryProvider: factoryProvider)
splitWrapper.setUserConsent(enabled: true)
let grantedUserConsent = splitWrapper.getUserConsent()
splitWrapper.setUserConsent(enabled: false)
let declinedUserConsent = splitWrapper.getUserConsent()
XCTAssert(grantedUserConsent == "granted")
XCTAssert(declinedUserConsent == "declined")
}
}

class SplitFactoryProviderStub: SplitFactoryProvider {
Expand Down
2 changes: 2 additions & 0 deletions splitio_ios/ios/Classes/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum Method: String {
case splits = "splits"
case split = "split"
case impressionLog = "impressionLog"
case getUserConsent = "getUserConsent"
case setUserConsent = "setUserConsent"
}

enum Argument: String {
Expand Down
6 changes: 6 additions & 0 deletions splitio_ios/ios/Classes/SplitMethodParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ class DefaultSplitMethodParser: SplitMethodParser {
case .split:
result(SplitView.asMap(splitView: splitWrapper?.split(splitName: argumentParser.getStringArgument(argumentName: .splitName, arguments: arguments) ?? "")))
break
case .getUserConsent:
result(splitWrapper?.getUserConsent())
break
case .setUserConsent:
splitWrapper?.setUserConsent(enabled: argumentParser.getBooleanArgument(argumentName: .value, arguments: arguments))
result(nil)
default:
result(FlutterMethodNotImplemented)
break
Expand Down
26 changes: 26 additions & 0 deletions splitio_ios/ios/Classes/SplitWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ protocol SplitWrapper: EvaluationWrapper, AttributesWrapper {
func splits() -> [SplitView]

func split(splitName: String) -> SplitView?

func getUserConsent() -> String

func setUserConsent(enabled: Bool)
}

protocol EvaluationWrapper {
Expand Down Expand Up @@ -227,4 +231,26 @@ class DefaultSplitWrapper: SplitWrapper {
return nil
}
}

func getUserConsent() -> String {
if let splitFactory = splitFactory {
let userConsent: UserConsent = splitFactory.userConsent

if (userConsent == .granted) {
return "granted"
} else if (userConsent == .declined) {
return "declined"
} else {
return "unknown"
}
} else {
return "unknown"
}
}

func setUserConsent(enabled: Bool) {
if let splitFactory = splitFactory {
splitFactory.setUserConsent(enabled: enabled)
}
}
}
Loading