From ead43837fb7a997c89fc9f1379f48944a2073f6b Mon Sep 17 00:00:00 2001 From: Rehan Date: Thu, 28 Nov 2024 16:00:52 +0500 Subject: [PATCH] pr suggestions --- lib/customer_io.dart | 16 ++--- .../customer_io_method_channel.dart | 18 ++--- .../customer_io_platform_interface.dart | 16 ++--- lib/extensions/method_channel_extensions.dart | 6 +- lib/messaging_in_app/method_channel.dart | 2 +- lib/messaging_in_app/platform_interface.dart | 2 +- test/customer_io_test.dart | 4 +- test/customer_io_test.mocks.dart | 66 ++++++++----------- 8 files changed, 60 insertions(+), 70 deletions(-) diff --git a/lib/customer_io.dart b/lib/customer_io.dart index cdfcb87..783c399 100644 --- a/lib/customer_io.dart +++ b/lib/customer_io.dart @@ -91,7 +91,7 @@ class CustomerIO { /// /// @param userId unique identifier for a profile /// @param traits (Optional) params to set profile attributes - Future identify( + void identify( {required String userId, Map traits = const {}}) { return _platform.identify( userId: userId, traits: traits.excludeNullValues()); @@ -101,7 +101,7 @@ class CustomerIO { /// /// If a profile exists, clearIdentify will stop identifying the profile. /// If no profile exists, request to clearIdentify will be ignored. - Future clearIdentify() { + void clearIdentify() { return _platform.clearIdentify(); } @@ -110,14 +110,14 @@ class CustomerIO { /// /// @param name event name to be tracked /// @param properties (Optional) params to be sent with event - Future track( + void track( {required String name, Map properties = const {}}) { return _platform.track( name: name, properties: properties.excludeNullValues()); } /// Track a push metric - Future trackMetric( + void trackMetric( {required String deliveryID, required String deviceToken, required MetricEvent event}) { @@ -127,7 +127,7 @@ class CustomerIO { /// Register a new device token with Customer.io, associated with the current active customer. If there /// is no active customer, this will fail to register the device - Future registerDeviceToken({required String deviceToken}) { + void registerDeviceToken({required String deviceToken}) { return _platform.registerDeviceToken(deviceToken: deviceToken); } @@ -135,7 +135,7 @@ class CustomerIO { /// /// @param name name of the screen user visited /// @param attributes (Optional) params to be sent with event - Future screen( + void screen( {required String title, Map properties = const {}}) { return _platform.screen( title: title, properties: properties.excludeNullValues()); @@ -145,7 +145,7 @@ class CustomerIO { /// such as app preferences, timezone etc /// /// @param attributes device attributes - Future setDeviceAttributes({required Map attributes}) { + void setDeviceAttributes({required Map attributes}) { return _platform.setDeviceAttributes(attributes: attributes); } @@ -153,7 +153,7 @@ class CustomerIO { /// user actions etc /// /// @param attributes additional attributes for a user profile - Future setProfileAttributes( + void setProfileAttributes( {required Map attributes}) { return _platform.setProfileAttributes( attributes: attributes.excludeNullValues()); diff --git a/lib/data_pipelines/customer_io_method_channel.dart b/lib/data_pipelines/customer_io_method_channel.dart index b5585c2..a0469ed 100644 --- a/lib/data_pipelines/customer_io_method_channel.dart +++ b/lib/data_pipelines/customer_io_method_channel.dart @@ -18,7 +18,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { /// To initialize the plugin @override Future initialize({required CustomerIOConfig config}) { - return methodChannel.invokeNativeMethodVoid( + return methodChannel.invokeNativeMethod( NativeMethods.initialize, config.toMap()); } @@ -27,7 +27,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { /// identifiers are attempted to be identified, then the last identified profile /// will be removed automatically. @override - Future identify( + void identify( {required String userId, Map traits = const {}}) { return methodChannel.invokeNativeMethodVoid(NativeMethods.identify, { NativeMethodParams.userId: userId, @@ -38,7 +38,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { /// To track user events like loggedIn, addedItemToCart etc. /// You may also track events with additional yet optional data. @override - Future track( + void track( {required String name, Map properties = const {}}) { return methodChannel.invokeNativeMethodVoid(NativeMethods.track, { NativeMethodParams.name: name, @@ -48,7 +48,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { /// Track a push metric @override - Future trackMetric( + void trackMetric( {required String deliveryID, required String deviceToken, required MetricEvent event}) { @@ -61,7 +61,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { /// Track screen events to record the screens a user visits @override - Future screen( + void screen( {required String title, Map properties = const {}}) { return methodChannel.invokeNativeMethodVoid(NativeMethods.screen, { NativeMethodParams.title: title, @@ -72,7 +72,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { /// Register a new device token with Customer.io, associated with the current active customer. If there /// is no active customer, this will fail to register the device @override - Future registerDeviceToken({required String deviceToken}) { + void registerDeviceToken({required String deviceToken}) { return methodChannel .invokeNativeMethodVoid(NativeMethods.registerDeviceToken, { NativeMethodParams.token: deviceToken, @@ -81,14 +81,14 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { /// Call this function to stop identifying a person. @override - Future clearIdentify() { + void clearIdentify() { return methodChannel.invokeNativeMethodVoid(NativeMethods.clearIdentify); } /// Set custom user profile information such as user preference, specific /// user actions etc @override - Future setProfileAttributes( + void setProfileAttributes( {required Map attributes}) { return methodChannel .invokeNativeMethodVoid(NativeMethods.setProfileAttributes, { @@ -99,7 +99,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { /// Use this function to send custom device attributes /// such as app preferences, timezone etc @override - Future setDeviceAttributes({required Map attributes}) { + void setDeviceAttributes({required Map attributes}) { return methodChannel .invokeNativeMethodVoid(NativeMethods.setDeviceAttributes, { NativeMethodParams.attributes: attributes, diff --git a/lib/data_pipelines/customer_io_platform_interface.dart b/lib/data_pipelines/customer_io_platform_interface.dart index a5c13d1..ad65102 100644 --- a/lib/data_pipelines/customer_io_platform_interface.dart +++ b/lib/data_pipelines/customer_io_platform_interface.dart @@ -33,41 +33,41 @@ abstract class CustomerIOPlatform extends PlatformInterface { throw UnimplementedError('initialize() has not been implemented.'); } - Future identify( + void identify( {required String userId, Map traits = const {}}) { throw UnimplementedError('identify() has not been implemented.'); } - Future clearIdentify() { + void clearIdentify() { throw UnimplementedError('clearIdentify() has not been implemented.'); } - Future track( + void track( {required String name, Map properties = const {}}) { throw UnimplementedError('track() has not been implemented.'); } - Future trackMetric( + void trackMetric( {required String deliveryID, required String deviceToken, required MetricEvent event}) { throw UnimplementedError('trackMetric() has not been implemented.'); } - Future registerDeviceToken({required String deviceToken}) { + void registerDeviceToken({required String deviceToken}) { throw UnimplementedError('registerDeviceToken() has not been implemented.'); } - Future screen( + void screen( {required String title, Map properties = const {}}) { throw UnimplementedError('screen() has not been implemented.'); } - Future setDeviceAttributes({required Map attributes}) { + void setDeviceAttributes({required Map attributes}) { throw UnimplementedError('setDeviceAttributes() has not been implemented.'); } - Future setProfileAttributes( + void setProfileAttributes( {required Map attributes}) { throw UnimplementedError( 'setProfileAttributes() has not been implemented.'); diff --git a/lib/extensions/method_channel_extensions.dart b/lib/extensions/method_channel_extensions.dart index 1f34531..67f9bd1 100644 --- a/lib/extensions/method_channel_extensions.dart +++ b/lib/extensions/method_channel_extensions.dart @@ -26,8 +26,8 @@ extension CustomerIOMethodChannelExtensions on MethodChannel { } /// Simplifies invoking a native method that doesn't return a value. - Future invokeNativeMethodVoid(String method, - [Map arguments = const {}]) async { - return await invokeNativeMethod(method, arguments); + void invokeNativeMethodVoid(String method, + [Map arguments = const {}]) { + invokeNativeMethod(method, arguments); } } diff --git a/lib/messaging_in_app/method_channel.dart b/lib/messaging_in_app/method_channel.dart index ece1ac0..1678b90 100644 --- a/lib/messaging_in_app/method_channel.dart +++ b/lib/messaging_in_app/method_channel.dart @@ -18,7 +18,7 @@ class CustomerIOMessagingInAppMethodChannel final _inAppEventStreamController = StreamController.broadcast(); @override - Future dismissMessage() { + void dismissMessage() { return methodChannel.invokeNativeMethodVoid(NativeMethods.dismissMessage); } diff --git a/lib/messaging_in_app/platform_interface.dart b/lib/messaging_in_app/platform_interface.dart index 7473562..d123ac0 100644 --- a/lib/messaging_in_app/platform_interface.dart +++ b/lib/messaging_in_app/platform_interface.dart @@ -27,7 +27,7 @@ abstract class CustomerIOMessagingInAppPlatform extends PlatformInterface { _instance = instance; } - Future dismissMessage() { + void dismissMessage() { throw UnimplementedError('dismissMessage() has not been implemented.'); } diff --git a/test/customer_io_test.dart b/test/customer_io_test.dart index 1af165c..667b40f 100644 --- a/test/customer_io_test.dart +++ b/test/customer_io_test.dart @@ -93,10 +93,10 @@ void main() { await CustomerIO.initialize(config: config); }); - test('identify() calls platform', () async { + test('identify() calls platform', () { const givenIdentifier = 'user@example.com'; final givenAttributes = {'name': 'John Doe'}; - await CustomerIO.instance.identify( + CustomerIO.instance.identify( userId: givenIdentifier, traits: givenAttributes, ); diff --git a/test/customer_io_test.mocks.dart b/test/customer_io_test.mocks.dart index 00cc042..2250179 100644 --- a/test/customer_io_test.mocks.dart +++ b/test/customer_io_test.mocks.dart @@ -26,12 +26,12 @@ import 'customer_io_test.dart' as _i3; class _FakeStreamSubscription_0 extends _i1.SmartFake implements _i2.StreamSubscription { _FakeStreamSubscription_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); } /// A class which mocks [TestCustomerIoPlatform]. @@ -55,7 +55,7 @@ class MockTestCustomerIoPlatform extends _i1.Mock returnValueForMissingStub: _i2.Future.value(), ) as _i2.Future); @override - _i2.Future identify({ + void identify({ required String? userId, Map? traits = const {}, }) => @@ -68,20 +68,18 @@ class MockTestCustomerIoPlatform extends _i1.Mock #traits: traits, }, ), - returnValue: _i2.Future.value(), - returnValueForMissingStub: _i2.Future.value(), + returnValueForMissingStub: null, ); @override - _i2.Future clearIdentify() => super.noSuchMethod( - Invocation.method( - #clearIdentify, - [], - ), - returnValue: _i2.Future.value(), - returnValueForMissingStub: _i2.Future.value(), - ); + void clearIdentify() => super.noSuchMethod( + Invocation.method( + #clearIdentify, + [], + ), + returnValueForMissingStub: null, + ); @override - _i2.Future track({ + void track({ required String? name, Map? properties = const {}, }) => @@ -94,11 +92,10 @@ class MockTestCustomerIoPlatform extends _i1.Mock #properties: properties, }, ), - returnValue: _i2.Future.value(), - returnValueForMissingStub: _i2.Future.value(), + returnValueForMissingStub: null, ); @override - _i2.Future trackMetric({ + void trackMetric({ required String? deliveryID, required String? deviceToken, required _i5.MetricEvent? event, @@ -113,22 +110,20 @@ class MockTestCustomerIoPlatform extends _i1.Mock #event: event, }, ), - returnValue: _i2.Future.value(), - returnValueForMissingStub: _i2.Future.value(), + returnValueForMissingStub: null, ); @override - _i2.Future registerDeviceToken({required String? deviceToken}) => + void registerDeviceToken({required String? deviceToken}) => super.noSuchMethod( Invocation.method( #registerDeviceToken, [], {#deviceToken: deviceToken}, ), - returnValue: _i2.Future.value(), - returnValueForMissingStub: _i2.Future.value(), + returnValueForMissingStub: null, ); @override - _i2.Future screen({ + void screen({ required String? title, Map? properties = const {}, }) => @@ -141,35 +136,30 @@ class MockTestCustomerIoPlatform extends _i1.Mock #properties: properties, }, ), - returnValue: _i2.Future.value(), - returnValueForMissingStub: _i2.Future.value(), + returnValueForMissingStub: null, ); @override - _i2.Future setDeviceAttributes( - {required Map? attributes}) => + void setDeviceAttributes({required Map? attributes}) => super.noSuchMethod( Invocation.method( #setDeviceAttributes, [], {#attributes: attributes}, ), - returnValue: _i2.Future.value(), - returnValueForMissingStub: _i2.Future.value(), + returnValueForMissingStub: null, ); @override - _i2.Future setProfileAttributes( - {required Map? attributes}) => + void setProfileAttributes({required Map? attributes}) => super.noSuchMethod( Invocation.method( #setProfileAttributes, [], {#attributes: attributes}, ), - returnValue: _i2.Future.value(), - returnValueForMissingStub: _i2.Future.value(), + returnValueForMissingStub: null, ); _i2.StreamSubscription subscribeToInAppEventListener( - void Function(_i6.InAppEvent)? onEvent) => + void Function(_i6.InAppEvent)? onEvent) => (super.noSuchMethod( Invocation.method( #subscribeToInAppEventListener,