From 26adc98d402efa7b3ae79c40cb8ff7c64aaf3fb6 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Wed, 8 Nov 2023 14:42:55 -0300 Subject: [PATCH 1/3] Add missing platform tests --- .github/workflows/test.yml | 4 + .../test/splitio_android_test.dart | 138 +++++++++++++++- splitio_ios/test/splitio_ios_test.dart | 155 ++++++++++++++++++ 3 files changed, 293 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a503a2a..b8eb93c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,3 +21,7 @@ jobs: run: cd splitio/; flutter pub get - name: Run flutter test run: cd splitio/; flutter test + - name: Run flutter splitio_android test + run: cd splitio_android/; flutter test + - name: Run flutter splitio_ios test + run: cd splitio_ios/; flutter test diff --git a/splitio_android/test/splitio_android_test.dart b/splitio_android/test/splitio_android_test.dart index 7cc1f68..554d4cd 100644 --- a/splitio_android/test/splitio_android_test.dart +++ b/splitio_android/test/splitio_android_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} @@ -54,6 +58,8 @@ void main() { case 'removeAttribute': case 'clearAttributes': return true; + case 'getUserConsent': + return 'declined'; } return null; }); @@ -183,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', () { @@ -349,7 +479,7 @@ void main() { expect(methodArguments, { 'apiKey': 'api-key', 'matchingKey': 'matching-key', - 'sdkConfiguration': {} + 'sdkConfiguration': {'readyTimeout': 10} }); }); @@ -363,7 +493,7 @@ void main() { 'apiKey': 'api-key', 'matchingKey': 'matching-key', 'bucketingKey': 'bucketing-key', - 'sdkConfiguration': {} + 'sdkConfiguration': {'readyTimeout': 10} }); }); @@ -527,14 +657,14 @@ void main() { _platform.setUserConsent(true); expect(methodName, 'setUserConsent'); - expect(methodArguments, {'enabled': true}); + expect(methodArguments, {'value': true}); }); test('set user consent disabled', () { _platform.setUserConsent(false); expect(methodName, 'setUserConsent'); - expect(methodArguments, {'enabled': false}); + expect(methodArguments, {'value': false}); }); }); } diff --git a/splitio_ios/test/splitio_ios_test.dart b/splitio_ios/test/splitio_ios_test.dart index d037cb3..52f3f68 100644 --- a/splitio_ios/test/splitio_ios_test.dart +++ b/splitio_ios/test/splitio_ios_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} @@ -54,6 +58,8 @@ void main() { case 'removeAttribute': case 'clearAttributes': return true; + case 'getUserConsent': + return 'declined'; } return null; }); @@ -183,6 +189,131 @@ 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', () { @@ -514,4 +645,28 @@ 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}); + }); + }); } From 7e0c2a205396d3c385806e4417397405f308246f Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Wed, 8 Nov 2023 14:47:07 -0300 Subject: [PATCH 2/3] Fix tests --- splitio_ios/test/splitio_ios_test.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/splitio_ios/test/splitio_ios_test.dart b/splitio_ios/test/splitio_ios_test.dart index 52f3f68..ab04f62 100644 --- a/splitio_ios/test/splitio_ios_test.dart +++ b/splitio_ios/test/splitio_ios_test.dart @@ -480,7 +480,7 @@ void main() { expect(methodArguments, { 'apiKey': 'api-key', 'matchingKey': 'matching-key', - 'sdkConfiguration': {} + 'sdkConfiguration': {'readyTimeout': 10} }); }); @@ -494,7 +494,7 @@ void main() { 'apiKey': 'api-key', 'matchingKey': 'matching-key', 'bucketingKey': 'bucketing-key', - 'sdkConfiguration': {} + 'sdkConfiguration': {'readyTimeout': 10} }); }); @@ -504,13 +504,13 @@ void main() { matchingKey: 'matching-key', bucketingKey: 'bucketing-key', sdkConfiguration: - SplitConfiguration(logLevel: SplitLogLevel.warning, streamingEnabled: false)); + SplitConfiguration(logLevel: SplitLogLevel.error, streamingEnabled: false, readyTimeout: 1)); expect(methodName, 'init'); expect(methodArguments, { 'apiKey': 'api-key', 'matchingKey': 'matching-key', 'bucketingKey': 'bucketing-key', - 'sdkConfiguration': {'logLevel': 'warning', 'streamingEnabled': false}, + 'sdkConfiguration': {'logLevel': 'error', 'streamingEnabled': false, 'readyTimeout': 1}, }); }); }); From b682f6c3429c3940c6d7249ec90071ca1409b2c3 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Wed, 8 Nov 2023 16:25:52 -0300 Subject: [PATCH 3/3] Retrigger checks