diff --git a/example/lib/event_form.dart b/example/lib/event_form.dart index 92c9327..e5c15d6 100644 --- a/example/lib/event_form.dart +++ b/example/lib/event_form.dart @@ -14,7 +14,7 @@ class _EventFormState extends State { void onPress() { AppState.of(context) - ..analytics.track(event: BaseEvent(eventType: _controller.text)) + ..analytics.track(BaseEvent(eventType: _controller.text)) ..setMessage('Event sent.'); } diff --git a/example/lib/group_form.dart b/example/lib/group_form.dart index 5890b77..ac671e1 100644 --- a/example/lib/group_form.dart +++ b/example/lib/group_form.dart @@ -11,7 +11,7 @@ class _GroupFormState extends State { void onPress() { if (groupType.text.isNotEmpty && groupValue.text.isNotEmpty) { AppState.of(context) - ..analytics.setGroup(groupType: groupType.text, groupName: groupValue.text) + ..analytics.setGroup(groupType.text, groupValue.text) ..setMessage('Group set.'); } } diff --git a/example/lib/group_identify_form.dart b/example/lib/group_identify_form.dart index 3c1b2d8..787dd3f 100644 --- a/example/lib/group_identify_form.dart +++ b/example/lib/group_identify_form.dart @@ -15,10 +15,10 @@ class _GroupIdentifyFormState extends State { groupPropertyKey.text.isNotEmpty && groupPropertyValue.text.isNotEmpty) { final Identify identify = Identify() - ..set(property: groupPropertyKey.text, value: groupPropertyValue.text); + ..set(groupPropertyKey.text, groupPropertyValue.text); AppState.of(context) - ..analytics.groupIdentify(groupType: groupType.text, groupName: groupValue.text, identify: identify) + ..analytics.groupIdentify(groupType.text, groupValue.text, identify) ..setMessage('Group Identify sent.'); } } diff --git a/example/lib/identify_form.dart b/example/lib/identify_form.dart index 1362c46..e30736c 100644 --- a/example/lib/identify_form.dart +++ b/example/lib/identify_form.dart @@ -11,17 +11,17 @@ class IdentifyForm extends StatefulWidget { class _IdentifyFormState extends State { void onPress() { final Identify identify = Identify() - ..set(property: 'identify_test', value: 'identify sent at ${DateTime + ..set('identify_test', 'identify sent at ${DateTime .now() .millisecondsSinceEpoch}') - ..add(property: "identify_count", value: 1); + ..add('identify_count', 1); if (userPropKey.isNotEmpty && userPropValue.isNotEmpty) { - identify.set(property: userPropKey, value: userPropValue); + identify.set(userPropKey, userPropValue); } AppState.of(context) - ..analytics.identify(identify: identify) + ..analytics.identify(identify) ..setMessage('Identify sent.'); } diff --git a/example/lib/revenue_form.dart b/example/lib/revenue_form.dart index a20ca64..4ab4214 100644 --- a/example/lib/revenue_form.dart +++ b/example/lib/revenue_form.dart @@ -24,7 +24,7 @@ class _RevenueFormState extends State { ..quantity = int.tryParse(quantity.text)! .. productId = productId.text; AppState.of(context) - ..analytics.revenue(revenue: revenue) + ..analytics.revenue(revenue) ..setMessage('Revenue Sent.'); } } diff --git a/lib/amplitude.dart b/lib/amplitude.dart index 7c1d5d2..1ea4aba 100644 --- a/lib/amplitude.dart +++ b/lib/amplitude.dart @@ -1,21 +1,22 @@ import 'dart:async'; -import 'package:amplitude_flutter/events/event_options.dart'; -import 'package:amplitude_flutter/events/identify_event.dart'; -import 'package:amplitude_flutter/events/identify.dart'; -import 'package:amplitude_flutter/events/revenue.dart'; import 'package:flutter/services.dart'; -import 'package:amplitude_flutter/configuration.dart'; -import 'package:amplitude_flutter/events/base_event.dart'; -import 'package:amplitude_flutter/events/group_identify_event.dart'; +import 'events/event_options.dart'; +import 'events/identify_event.dart'; +import 'events/identify.dart'; +import 'events/revenue.dart'; +import 'configuration.dart'; +import 'events/base_event.dart'; +import 'events/group_identify_event.dart'; class Amplitude { Configuration configuration; - MethodChannel _channel = const MethodChannel("amplitude_flutter"); + MethodChannel _channel = const MethodChannel('amplitude_flutter'); + /// Whether the Amplitude instance has been successfully initialized /// /// ``` - /// var amplitude = Amplitude(Configuration(apiKey: "apiKey")); + /// var amplitude = Amplitude(Configuration(apiKey: 'apiKey')); /// // If care about init complete /// await amplitude.isBuilt; /// ``` @@ -24,11 +25,11 @@ class Amplitude { /// Returns an Amplitude instance /// /// ``` - /// var amplitude = Amplitude(Configuration(apiKey: "apiKey")); + /// final amplitude = Amplitude(Configuration(apiKey: 'apiKey')); /// // If care about init complete /// await amplitude.isBuilt; /// ``` - Amplitude(this.configuration, [MethodChannel? methodChannel]){ + Amplitude(this.configuration, [MethodChannel? methodChannel]) { _channel = methodChannel ?? this._channel; isBuilt = _init(); } @@ -36,10 +37,10 @@ class Amplitude { /// Private method to initialize and return a Future Future _init() async { try { - await _channel.invokeMethod("init", configuration.toMap()); + await _channel.invokeMethod('init', configuration.toMap()); return true; // Initialization successful } catch (e) { - print("Error initializing Amplitude: $e"); + print('Error initializing Amplitude: $e'); return false; // Initialization failed } } @@ -48,15 +49,19 @@ class Amplitude { /// /// Uploads are batched to occur every 30 events or every 30 seconds /// (whichever comes first), as well as on app close. - Future track({ - required BaseEvent event, + /// + /// ``` + /// amplitude.track(BaseEvent(eventType: 'Button Clicked')) + /// ``` + Future track( + BaseEvent event, [ EventOptions? options, - }) async { + ]) async { if (options != null) { event.mergeEventOptions(options); } - return await _channel.invokeMethod("track", event.toMap()); + return await _channel.invokeMethod('track', event.toMap()); } /// Updates user properties using operations provided via Identify API. @@ -70,10 +75,9 @@ class Amplitude { /// final Identify identify = Identify() /// ..set('gender','male') /// ..add('karma', 1); - /// Amplitude.getInstance.identify(identify); + /// amplitude.identify(identify); /// ``` - Future identify( - {required Identify identify, EventOptions? options}) async { + Future identify(Identify identify, [EventOptions? options]) async { final event = IdentifyEvent(); event.userProperties = identify.properties; @@ -89,7 +93,7 @@ class Amplitude { } } - return await _channel.invokeMethod("identify", event.toMap()); + return await _channel.invokeMethod('identify', event.toMap()); } /// Updates the properties of particular groups. @@ -105,14 +109,12 @@ class Amplitude { /// Example: if you wanted to set a key-value pair as a group property to the enterprise group with group type to be plan, you would do: /// ``` /// final groupIdentifyEvent = Identify() - /// ..set(property: 'key1', value: 'value1'); - /// amplitude.groupIdentify(groupType: "plan", groupName: "enterprise", identify: identify); + /// ..set('key1', 'value1'); + /// amplitude.groupIdentify('plan', 'enterprise', identify); /// ``` Future groupIdentify( - {required String groupType, - required String groupName, - required Identify identify, - EventOptions? options}) async { + String groupType, String groupName, Identify identify, + [EventOptions? options]) async { final event = GroupIdentifyEvent(); final group = Map(); group[groupType] = groupName; @@ -122,29 +124,30 @@ class Amplitude { event.mergeEventOptions(options); } - return await _channel.invokeMethod( - "groupIdentify", event.toMap()); + return await _channel.invokeMethod('groupIdentify', event.toMap()); } /// Adds a user to a group or groups. You need to specify a groupType and groupName(s). /// /// For example you can group people by their organization. In this case, - /// groupType is "orgId", and groupName would be the actual ID(s). + /// groupType is 'orgId', and groupName would be the actual ID(s). /// groupName can be a string or an array of strings to indicate a user in multiple groups. /// + /// ``` + /// amplitude.setGroup('orgId', '15'); + /// ``` + /// /// You can also call setGroup multiple times with different groupTypes to track /// multiple types of groups (up to 5 per app). /// Note: This will also set groupType: groupName as a user property. - Future setGroup( - {required String groupType, - required dynamic groupName, - EventOptions? options}) async { + Future setGroup(String groupType, dynamic groupName, + [EventOptions? options]) async { if (!(groupName is String) && !(groupName is List)) { // TODO(xinyi): log warn that groupName should be either a string or an array of string. return; } - final identify = Identify().set(property: groupType, value: groupName); + final identify = Identify().set(groupType, groupName); final event = IdentifyEvent() ..groups = {groupType: groupName} ..userProperties = identify.properties; @@ -153,7 +156,7 @@ class Amplitude { event.mergeEventOptions(options); } - return await _channel.invokeMethod("setGroup", event.toMap()); + return await _channel.invokeMethod('setGroup', event.toMap()); } /// Tracks revenue generated by a user. @@ -163,15 +166,12 @@ class Amplitude { /// final revenue = Revenue() /// ..price = 3.99 /// ..quantity = 3 - /// ..productId = "com.company.productId"; - /// amplitude.revenue(revenue: revenue); + /// ..productId = 'com.company.productId'; + /// amplitude.revenue(revenue); /// ``` - Future revenue({ - required Revenue revenue, - EventOptions? options, - }) async { + Future revenue(Revenue revenue, [EventOptions? options]) async { if (!revenue.isValid()) { - // TODO(xinyi): logger.warn("Invalid revenue object, missing required fields") + // TODO(xinyi): logger.warn('Invalid revenue object, missing required fields') return; } final event = revenue.toRevenueEvent(); @@ -179,39 +179,47 @@ class Amplitude { event.mergeEventOptions(options); } - return await _channel.invokeMethod("revenue", event.toMap()); + return await _channel.invokeMethod('revenue', event.toMap()); } /// Set a custom user Id. /// /// If your app has its own login system that you want to track users with, /// you can set the userId. + /// + /// ``` + /// amplitude.setUserId('user Id'); + /// ``` Future setUserId(String? userId) async { Map properties = {}; - properties["setUserId"] = userId; + properties['setUserId'] = userId; - return await _channel.invokeMethod("setUserId", properties); + return await _channel.invokeMethod('setUserId', properties); } /// Sets a custom device ID. /// /// Make sure the value is sufficiently unique. Amplitude recommends using a UUID. + /// + /// ``` + /// amplitude.setDeviceId('device Id'); + /// ``` Future setDeviceId(String deviceId) async { Map properties = {}; - properties["setDeviceId"] = deviceId; + properties['setDeviceId'] = deviceId; - return await _channel.invokeMethod("setDeviceId", properties); + return await _channel.invokeMethod('setDeviceId', properties); } - /// Resets userId to "null" and deviceId to a random UUID. + /// Resets userId to 'null' and deviceId to a random UUID. /// /// Note different devices on different platforms should have different device Ids. Future reset() async { - return await _channel.invokeMethod("reset"); + return await _channel.invokeMethod('reset'); } /// Flush events in storage. Future flush() async { - await await _channel.invokeMethod("flush"); + await await _channel.invokeMethod('flush'); } } diff --git a/lib/events/base_event.dart b/lib/events/base_event.dart index da027be..b70b233 100644 --- a/lib/events/base_event.dart +++ b/lib/events/base_event.dart @@ -1,4 +1,4 @@ -import 'package:amplitude_flutter/events/plan.dart'; +import 'plan.dart'; import 'event_options.dart'; import 'ingestion_metadata.dart'; diff --git a/lib/events/event_options.dart b/lib/events/event_options.dart index 42a794a..c6bc818 100644 --- a/lib/events/event_options.dart +++ b/lib/events/event_options.dart @@ -1,7 +1,6 @@ import 'dart:core'; -import 'package:amplitude_flutter/events/plan.dart'; - +import 'plan.dart'; import 'ingestion_metadata.dart'; /// Keys for event arguments diff --git a/lib/events/group_identify_event.dart b/lib/events/group_identify_event.dart index d78f000..b9ba780 100644 --- a/lib/events/group_identify_event.dart +++ b/lib/events/group_identify_event.dart @@ -1,4 +1,4 @@ -import 'package:amplitude_flutter/constants.dart'; +import '../constants.dart'; import 'base_event.dart'; class GroupIdentifyEvent extends BaseEvent { diff --git a/lib/events/identify.dart b/lib/events/identify.dart index 43905cc..a57cc1a 100644 --- a/lib/events/identify.dart +++ b/lib/events/identify.dart @@ -3,65 +3,65 @@ class IdentifyOperation { const IdentifyOperation._(this.operationType); - static const IdentifyOperation set = IdentifyOperation._("\$set"); - static const IdentifyOperation setOnce = IdentifyOperation._("\$setOnce"); - static const IdentifyOperation add = IdentifyOperation._("\$add"); - static const IdentifyOperation append = IdentifyOperation._("\$append"); - static const IdentifyOperation clearAll = IdentifyOperation._("\$clearAll"); - static const IdentifyOperation prepend = IdentifyOperation._("\$prepend"); - static const IdentifyOperation unset = IdentifyOperation._("\$unset"); - static const IdentifyOperation preInsert = IdentifyOperation._("\$preInsert"); - static const IdentifyOperation postInsert = IdentifyOperation._("\$postInsert"); - static const IdentifyOperation remove = IdentifyOperation._("\$remove"); + static const IdentifyOperation set = IdentifyOperation._('\$set'); + static const IdentifyOperation setOnce = IdentifyOperation._('\$setOnce'); + static const IdentifyOperation add = IdentifyOperation._('\$add'); + static const IdentifyOperation append = IdentifyOperation._('\$append'); + static const IdentifyOperation clearAll = IdentifyOperation._('\$clearAll'); + static const IdentifyOperation prepend = IdentifyOperation._('\$prepend'); + static const IdentifyOperation unset = IdentifyOperation._('\$unset'); + static const IdentifyOperation preInsert = IdentifyOperation._('\$preInsert'); + static const IdentifyOperation postInsert = IdentifyOperation._('\$postInsert'); + static const IdentifyOperation remove = IdentifyOperation._('\$remove'); } class Identify { Set propertySet = {}; Map properties = {}; - Identify set({required String property, required dynamic value}) { + Identify set(String property, dynamic value) { // TODO(xinyi): data type check _setUserProperty(IdentifyOperation.set, property, value); return this; } - Identify setOnce({required String property, required dynamic value}) { + Identify setOnce(String property, dynamic value) { // TODO(xinyi): data type check _setUserProperty(IdentifyOperation.setOnce, property, value); return this; } - Identify add({required String property, required dynamic value}) { + Identify add(String property, dynamic value) { // TODO(xinyi): data type check _setUserProperty(IdentifyOperation.add, property, value); return this; } - Identify append({required String property, required dynamic value}) { + Identify append(String property, dynamic value) { // TODO(xinyi): data type check _setUserProperty(IdentifyOperation.append, property, value); return this; } - Identify prepend({required String property, required dynamic value}) { + Identify prepend(String property, dynamic value) { // TODO(xinyi): data type check _setUserProperty(IdentifyOperation.prepend, property, value); return this; } - Identify preInsert({required String property, required dynamic value}) { + Identify preInsert(String property, dynamic value) { // TODO(xinyi): data type check _setUserProperty(IdentifyOperation.preInsert, property, value); return this; } - Identify remove({required String property, required dynamic value}) { + Identify remove(String property, dynamic value) { // TODO(xinyi): data type check _setUserProperty(IdentifyOperation.remove, property, value); return this; } - Identify unset({required String property}) { + Identify unset(String property) { _setUserProperty(IdentifyOperation.unset, property, Identify.UNSET_VALUE); return this; } @@ -75,22 +75,22 @@ class Identify { void _setUserProperty(IdentifyOperation operation, String property, dynamic value) { if (property.isEmpty) { // TODO(xinyi): add logs - // log.warning("Attempting to perform operation ${operation.operationType} with a null or empty string property, ignoring"); + // log.warning('Attempting to perform operation ${operation.operationType} with a null or empty string property, ignoring'); return; } if (value == null) { // TODO(xinyi): add logs - // log.warning("Attempting to perform operation ${operation.operationType} with null value for property $property, ignoring"); + // log.warning('Attempting to perform operation ${operation.operationType} with null value for property $property, ignoring'); return; } if (properties.containsKey(IdentifyOperation.clearAll.operationType)) { // TODO(xinyi): add logs - // log.warning("This Identify already contains a \$clearAll operation, ignoring operation ${operation.operationType}"); + // log.warning('This Identify already contains a \$clearAll operation, ignoring operation ${operation.operationType}'); return; } if (propertySet.contains(property)) { // TODO(xinyi): add logs - // log.warning("Already used property $property in previous operation, ignoring operation ${operation.operationType}"); + // log.warning('Already used property $property in previous operation, ignoring operation ${operation.operationType}'); return; } if (!properties.containsKey(operation.operationType)) { @@ -100,5 +100,5 @@ class Identify { propertySet.add(property); } - static const UNSET_VALUE = "-"; + static const UNSET_VALUE = '-'; } diff --git a/lib/events/identify_event.dart b/lib/events/identify_event.dart index 1e1b41b..56f07d4 100644 --- a/lib/events/identify_event.dart +++ b/lib/events/identify_event.dart @@ -1,5 +1,5 @@ -import 'package:amplitude_flutter/constants.dart'; -import 'package:amplitude_flutter/events/base_event.dart'; +import '../constants.dart'; +import 'base_event.dart'; class IdentifyEvent extends BaseEvent { IdentifyEvent() : super(eventType: Constants.identify_event); diff --git a/lib/events/revenue.dart b/lib/events/revenue.dart index 7594992..c536c5f 100644 --- a/lib/events/revenue.dart +++ b/lib/events/revenue.dart @@ -1,4 +1,4 @@ -import 'package:amplitude_flutter/events/revenue_event.dart'; +import 'revenue_event.dart'; class RevenueConstants { static const String revenueProductId = "\$productId"; diff --git a/lib/events/revenue_event.dart b/lib/events/revenue_event.dart index c29e6d5..3dad5fa 100644 --- a/lib/events/revenue_event.dart +++ b/lib/events/revenue_event.dart @@ -1,5 +1,5 @@ -import 'package:amplitude_flutter/constants.dart'; -import 'package:amplitude_flutter/events/base_event.dart'; +import '../constants.dart'; +import 'base_event.dart'; class RevenueEvent extends BaseEvent { RevenueEvent() : super(eventType: Constants.revenue_event); diff --git a/test/amplitude_test.dart b/test/amplitude_test.dart index c112510..80913dd 100644 --- a/test/amplitude_test.dart +++ b/test/amplitude_test.dart @@ -106,39 +106,34 @@ void main() { test("Should init and track call MethodChannel", () async { when(mockChannel.invokeMethod("track", any)).thenAnswer((_) async => null); - await amplitude.track(event: testEvent); + await amplitude.track(testEvent); - verify(mockChannel.invokeMethod("init", testConfigurationMap)) - .called(1); - verify(mockChannel.invokeMethod("track", testEventMap)) - .called(1); + verify(mockChannel.invokeMethod("init", testConfigurationMap)).called(1); + verify(mockChannel.invokeMethod("track", testEventMap)).called(1); }); test("Should track with event options calls MethodChannel", () async { when(mockChannel.invokeMethod("track", any)).thenAnswer((_) async => null); - await amplitude.track( - event: testEvent, options: EventOptions(userId: testUserId)); + await amplitude.track(testEvent, EventOptions(userId: testUserId)); final expectedEventMap = new Map.from(testEventMap); expectedEventMap["user_id"] = testUserId; - verify(mockChannel.invokeMethod("track", expectedEventMap)) - .called(1); + verify(mockChannel.invokeMethod("track", expectedEventMap)).called(1); }); test("Should identify calls MethodChannel", () async { when(mockChannel.invokeMethod("identify", any)) .thenAnswer((_) async => null); - final identify = Identify()..set(property: testProperty, value: testValue); - await amplitude.identify(identify: identify); + final identify = Identify()..set(testProperty, testValue); + await amplitude.identify(identify); final testIdentifyMap = new Map.from(testEventMap); testIdentifyMap["event_type"] = Constants.identify_event; testIdentifyMap["user_properties"] = { "\$set": {testProperty: testValue} }; - verify(mockChannel.invokeMethod("identify", testIdentifyMap)) - .called(1); + verify(mockChannel.invokeMethod("identify", testIdentifyMap)).called(1); }); test("Should identify calls setUserId in MethodChannel", () async { @@ -147,9 +142,8 @@ void main() { when(mockChannel.invokeMethod("setUserId", any)) .thenAnswer((_) async => null); - final identify = Identify()..set(property: testProperty, value: testValue); - await amplitude.identify( - identify: identify, options: EventOptions(userId: testUserId)); + final identify = Identify()..set(testProperty, testValue); + await amplitude.identify(identify, EventOptions(userId: testUserId)); final testIdentifyMap = new Map.from(testEventMap); testIdentifyMap["user_id"] = testUserId; @@ -159,8 +153,7 @@ void main() { }; verify(mockChannel.invokeMethod("setUserId", {"setUserId": testUserId})) .called(1); - verify(mockChannel.invokeMethod("identify", testIdentifyMap)) - .called(1); + verify(mockChannel.invokeMethod("identify", testIdentifyMap)).called(1); }); test("Should identify calls setDeviceId in MethodChannel", () async { @@ -169,9 +162,8 @@ void main() { when(mockChannel.invokeMethod("setDeviceId", any)) .thenAnswer((_) async => null); - final identify = Identify()..set(property: testProperty, value: testValue); - await amplitude.identify( - identify: identify, options: EventOptions(deviceId: testDeviceId)); + final identify = Identify()..set(testProperty, testValue); + await amplitude.identify(identify, EventOptions(deviceId: testDeviceId)); final testIdentifyMap = new Map.from(testEventMap); testIdentifyMap["device_id"] = testDeviceId; @@ -179,22 +171,17 @@ void main() { testIdentifyMap["user_properties"] = { "\$set": {testProperty: testValue} }; - verify(mockChannel.invokeMethod("setDeviceId", {"setDeviceId": testDeviceId})) - .called(1); - verify(mockChannel.invokeMethod("identify", testIdentifyMap)) - .called(1); + verify(mockChannel + .invokeMethod("setDeviceId", {"setDeviceId": testDeviceId})).called(1); + verify(mockChannel.invokeMethod("identify", testIdentifyMap)).called(1); }); test("Should groupIdentify calls MethodChannel", () async { when(mockChannel.invokeMethod("groupIdentify", any)) .thenAnswer((_) async => null); - final groupIdentify = Identify() - ..set(property: testProperty, value: testValue); - await amplitude.groupIdentify( - groupType: testGroupType, - groupName: testGroupName, - identify: groupIdentify); + final groupIdentify = Identify()..set(testProperty, testValue); + await amplitude.groupIdentify(testGroupType, testGroupName, groupIdentify); final testIdentifyMap = new Map.from(testEventMap); testIdentifyMap["event_type"] = Constants.group_identify_event; @@ -202,8 +189,7 @@ void main() { testIdentifyMap["group_properties"] = { "\$set": {testProperty: testValue} }; - verify(mockChannel.invokeMethod( - "groupIdentify", testIdentifyMap)) + verify(mockChannel.invokeMethod("groupIdentify", testIdentifyMap)) .called(1); }); @@ -211,13 +197,9 @@ void main() { when(mockChannel.invokeMethod("groupIdentify", any)) .thenAnswer((_) async => null); - final groupIdentify = Identify() - ..set(property: testProperty, value: testValue); - await amplitude.groupIdentify( - groupType: testGroupType, - groupName: testGroupName, - identify: groupIdentify, - options: EventOptions(userId: testUserId)); + final groupIdentify = Identify()..set(testProperty, testValue); + await amplitude.groupIdentify(testGroupType, testGroupName, groupIdentify, + EventOptions(userId: testUserId)); final testIdentifyMap = new Map.from(testEventMap); testIdentifyMap["event_type"] = Constants.group_identify_event; @@ -226,16 +208,14 @@ void main() { testIdentifyMap["group_properties"] = { "\$set": {testProperty: testValue} }; - verify(mockChannel.invokeMethod( - "groupIdentify",(testIdentifyMap))) + verify(mockChannel.invokeMethod("groupIdentify", (testIdentifyMap))) .called(1); }); test("Should setGroup calls MethodChannel", () async { when(mockChannel.invokeMethod("track", any)).thenAnswer((_) async => null); - await amplitude.setGroup( - groupType: testGroupType, groupName: testGroupName); + await amplitude.setGroup(testGroupType, testGroupName); final testIdentifyMap = new Map.from(testEventMap); testIdentifyMap["event_type"] = Constants.identify_event; @@ -244,17 +224,14 @@ void main() { "\$set": {testGroupType: testGroupName} }; - verify(mockChannel.invokeMethod("setGroup", testIdentifyMap)) - .called(1); + verify(mockChannel.invokeMethod("setGroup", testIdentifyMap)).called(1); }); test("Should setGroup with event options calls MethodChannel", () async { when(mockChannel.invokeMethod("track", any)).thenAnswer((_) async => null); await amplitude.setGroup( - groupType: testGroupType, - groupName: testGroupName, - options: EventOptions(userId: testUserId)); + testGroupType, testGroupName, EventOptions(userId: testUserId)); final testIdentifyMap = new Map.from(testEventMap); testIdentifyMap["event_type"] = Constants.identify_event; @@ -264,8 +241,7 @@ void main() { }; testIdentifyMap["user_id"] = testUserId; - verify(mockChannel.invokeMethod("setGroup", testIdentifyMap)) - .called(1); + verify(mockChannel.invokeMethod("setGroup", testIdentifyMap)).called(1); }); test('Should revenue calls MethodChannel', () async { @@ -276,14 +252,17 @@ void main() { ..price = testPrice ..quantity = testQuantity ..productId = testProductId; - await amplitude.revenue(revenue: revenue); - + await amplitude.revenue(revenue); + final testRevenueMap = new Map.from(testEventMap); testRevenueMap["event_type"] = Constants.revenue_event; testRevenueMap["event_properties"] = {}; - testRevenueMap["event_properties"][RevenueConstants.revenuePrice] = testPrice; - testRevenueMap["event_properties"][RevenueConstants.revenueQuantity] = testQuantity; - testRevenueMap["event_properties"][RevenueConstants.revenueProductId] = testProductId; + testRevenueMap["event_properties"][RevenueConstants.revenuePrice] = + testPrice; + testRevenueMap["event_properties"][RevenueConstants.revenueQuantity] = + testQuantity; + testRevenueMap["event_properties"][RevenueConstants.revenueProductId] = + testProductId; verify(mockChannel.invokeMethod('revenue', testRevenueMap)).called(1); }); @@ -296,15 +275,18 @@ void main() { ..price = testPrice ..quantity = testQuantity ..productId = testProductId; - await amplitude.revenue(revenue: revenue, options: EventOptions(userId: testUserId)); + await amplitude.revenue(revenue, EventOptions(userId: testUserId)); final testRevenueMap = new Map.from(testEventMap); testRevenueMap["user_id"] = testUserId; testRevenueMap["event_type"] = Constants.revenue_event; testRevenueMap["event_properties"] = {}; - testRevenueMap["event_properties"][RevenueConstants.revenuePrice] = testPrice; - testRevenueMap["event_properties"][RevenueConstants.revenueQuantity] = testQuantity; - testRevenueMap["event_properties"][RevenueConstants.revenueProductId] = testProductId; + testRevenueMap["event_properties"][RevenueConstants.revenuePrice] = + testPrice; + testRevenueMap["event_properties"][RevenueConstants.revenueQuantity] = + testQuantity; + testRevenueMap["event_properties"][RevenueConstants.revenueProductId] = + testProductId; verify(mockChannel.invokeMethod('revenue', testRevenueMap)).called(1); }); @@ -315,7 +297,8 @@ void main() { amplitude.setUserId(testUserId); - verify(mockChannel.invokeMethod('setUserId', {"setUserId": testUserId})).called(1); + verify(mockChannel.invokeMethod('setUserId', {"setUserId": testUserId})) + .called(1); }); test('Should setDeviceId calls MethodChannel', () async { @@ -324,7 +307,8 @@ void main() { amplitude.setDeviceId(testDeviceId); - verify(mockChannel.invokeMethod('setDeviceId', {"setDeviceId": testDeviceId})).called(1); + verify(mockChannel + .invokeMethod('setDeviceId', {"setDeviceId": testDeviceId})).called(1); }); test('Should setDeviceId calls MethodChannel', () async { @@ -333,12 +317,12 @@ void main() { amplitude.setDeviceId(testDeviceId); - verify(mockChannel.invokeMethod('setDeviceId', {"setDeviceId": testDeviceId})).called(1); + verify(mockChannel + .invokeMethod('setDeviceId', {"setDeviceId": testDeviceId})).called(1); }); test('Should reset calls MethodChannel', () async { - when(mockChannel.invokeMethod('reset', any)) - .thenAnswer((_) async => null); + when(mockChannel.invokeMethod('reset', any)).thenAnswer((_) async => null); amplitude.reset(); @@ -346,8 +330,7 @@ void main() { }); test('Should flush calls MethodChannel', () async { - when(mockChannel.invokeMethod('flush', any)) - .thenAnswer((_) async => null); + when(mockChannel.invokeMethod('flush', any)).thenAnswer((_) async => null); amplitude.flush(); diff --git a/test/events/identify_test.dart b/test/events/identify_test.dart index 8e12c50..79c6ed2 100644 --- a/test/events/identify_test.dart +++ b/test/events/identify_test.dart @@ -23,7 +23,7 @@ void main() { group('Identify', () { test('Should set() correctly', () { final identify = Identify(); - identify.set(property: testProperty, value: testValue); + identify.set(testProperty, testValue); expect(identify.properties.containsKey("\$set"), isTrue); expect(identify.properties["\$set"][testProperty], testValue); @@ -32,7 +32,7 @@ void main() { test('Should setOnce() correctly', () { final identify = Identify(); - identify.setOnce(property: testProperty, value: testValue); + identify.setOnce(testProperty, testValue); expect(identify.properties.containsKey("\$setOnce"), isTrue); expect(identify.properties["\$setOnce"][testProperty], testValue); @@ -41,7 +41,7 @@ void main() { test('Should add() correctly', () { final identify = Identify(); - identify.add(property: testProperty, value: testValue); + identify.add(testProperty, testValue); expect(identify.properties.containsKey("\$add"), isTrue); expect(identify.properties["\$add"][testProperty], testValue); @@ -50,7 +50,7 @@ void main() { test('Should append() correctly', () { final identify = Identify(); - identify.append(property: testProperty, value: testValue); + identify.append(testProperty, testValue); expect(identify.properties.containsKey("\$append"), isTrue); expect(identify.properties["\$append"][testProperty], testValue); @@ -59,7 +59,7 @@ void main() { test('Should prepend() correctly', () { final identify = Identify(); - identify.prepend(property: testProperty, value: testValue); + identify.prepend(testProperty, testValue); expect(identify.properties.containsKey("\$prepend"), isTrue); expect(identify.properties["\$prepend"][testProperty], testValue); @@ -68,7 +68,7 @@ void main() { test('Should preInsert() correctly', () { final identify = Identify(); - identify.preInsert(property: testProperty, value: testValue); + identify.preInsert(testProperty, testValue); expect(identify.properties.containsKey("\$preInsert"), isTrue); expect(identify.properties["\$preInsert"][testProperty], testValue); @@ -77,7 +77,7 @@ void main() { test('Should remove() correctly', () { final identify = Identify(); - identify.remove(property: testProperty, value: testValue); + identify.remove(testProperty, testValue); expect(identify.properties.containsKey("\$remove"), isTrue); expect(identify.properties["\$remove"][testProperty], testValue); @@ -86,16 +86,17 @@ void main() { test('Should unset() correctly', () { final identify = Identify(); - identify.unset(property: testProperty); + identify.unset(testProperty); expect(identify.properties.containsKey("\$unset"), isTrue); - expect(identify.properties["\$unset"][testProperty], Identify.UNSET_VALUE); + expect( + identify.properties["\$unset"][testProperty], Identify.UNSET_VALUE); expect(identify.propertySet.contains(testProperty), isTrue); }); test('Should clearAll() clear properties and block further updates', () { final identify = Identify(); - identify.set(property: testProperty, value: testValue); + identify.set(testProperty, testValue); identify.clearAll(); // After clearAll, properties should be cleared except for the clearAll operation itself @@ -103,31 +104,33 @@ void main() { expect(identify.properties.containsKey("\$clearAll"), isTrue); // Attempt to set another property after clearAll should be ignored - identify.set(property: testProperty, value: testValue); + identify.set(testProperty, testValue); expect(identify.properties.containsKey("\$set"), isFalse); }); test('Should not proceed when property is empty', () { final identify = Identify(); - identify.set(property: "", value: testValue); + identify.set("", testValue); expect(identify.properties.length, 0); }); test('Should not proceed when value is null', () { final identify = Identify(); - identify.set(property: testProperty, value: null); + identify.set(testProperty, null); expect(identify.properties.length, 0); }); - test('Should ignore operation when property exists in previous operation', () { + test('Should ignore operation when property exists in previous operation', + () { final identify = Identify(); - identify.set(property: testProperty, value: testValue); - identify.set(property: testProperty, value: "new Value"); + identify.set(testProperty, testValue); + identify.set(testProperty, "new Value"); expect(identify.properties.length, 1); expect(identify.propertySet.length, 1); - expect(identify.properties[IdentifyOperation.set.operationType], {testProperty: testValue}); + expect(identify.properties[IdentifyOperation.set.operationType], + {testProperty: testValue}); }); }); }