diff --git a/splitio_platform_interface/lib/split_result.dart b/splitio_platform_interface/lib/split_result.dart index 80b452b..f1c0896 100644 --- a/splitio_platform_interface/lib/split_result.dart +++ b/splitio_platform_interface/lib/split_result.dart @@ -13,8 +13,8 @@ class SplitResult { String toString() { return '{"treatment": "' + treatment + - '", config: "' + - (config ?? 'null') + - '"}'; + '", config: ' + + (config != null ? '"$config"' : 'null') + + '}'; } } diff --git a/splitio_platform_interface/lib/split_view.dart b/splitio_platform_interface/lib/split_view.dart index be05ae0..40451c5 100644 --- a/splitio_platform_interface/lib/split_view.dart +++ b/splitio_platform_interface/lib/split_view.dart @@ -7,9 +7,12 @@ class SplitView { List treatments = []; int changeNumber; Map configs = {}; + String defaultTreatment; + List sets = []; SplitView(this.name, this.trafficType, this.killed, this.treatments, - this.changeNumber, this.configs); + this.changeNumber, this.configs, + [this.defaultTreatment = '', this.sets = const []]); static SplitView? fromEntry(Map? entry) { if (entry == null || entry.isEmpty) { @@ -27,7 +30,9 @@ class SplitView { entry['killed'], (entry['treatments'] as List).map((el) => el as String).toList(), entry['changeNumber'], - mappedConfig); + mappedConfig, + entry['defaultTreatment'] ?? '', + entry['sets'] ?? []); } @override @@ -38,7 +43,9 @@ class SplitView { killed: $killed, treatments: ${treatments.toString()}, changeNumber: $changeNumber, - config: $configs + config: $configs, + defaultTreatment: $defaultTreatment, + sets: ${sets.toString()} }'''; } } diff --git a/splitio_platform_interface/test/split_result_test.dart b/splitio_platform_interface/test/split_result_test.dart new file mode 100644 index 0000000..a69928a --- /dev/null +++ b/splitio_platform_interface/test/split_result_test.dart @@ -0,0 +1,20 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:splitio_platform_interface/split_result.dart'; + +void main() { + test('result with config', () { + const result = SplitResult('on', 'config'); + + expect(result.treatment, 'on'); + expect(result.config, 'config'); + expect(result.toString(), '{"treatment": "on", config: "config"}'); + }); + + test('result with null config', () { + const result = SplitResult('on', null); + + expect(result.treatment, 'on'); + expect(result.config, null); + expect(result.toString(), '{"treatment": "on", config: null}'); + }); +} diff --git a/splitio_platform_interface/test/split_view_test.dart b/splitio_platform_interface/test/split_view_test.dart index 0268b42..9a5aee1 100644 --- a/splitio_platform_interface/test/split_view_test.dart +++ b/splitio_platform_interface/test/split_view_test.dart @@ -22,6 +22,8 @@ void main() { 'configs': {'yes': '{"abc"}', 'no': '"wasd"'}, 'changeNumber': 156246, 'trafficType': 'default', + 'defaultTreatment': 'on', + 'sets': ['set1', 'set2'], }); expect(splitView?.name, 'my_split'); @@ -30,5 +32,7 @@ void main() { expect(splitView?.configs, {'yes': '{"abc"}', 'no': '"wasd"'}); expect(splitView?.changeNumber, 156246); expect(splitView?.trafficType, 'default'); + expect(splitView?.defaultTreatment, 'on'); + expect(splitView?.sets, ['set1', 'set2']); }); }