From 47aa273bc84c5a0ff7d7ac4daf3441dfe8072fab Mon Sep 17 00:00:00 2001 From: Xinyi Ye Date: Thu, 4 Apr 2024 11:08:33 -0700 Subject: [PATCH] lint --- analysis_options.yaml | 9 + lib/amplitude.dart | 6 +- lib/configuration.dart | 2 +- lib/constants.dart | 6 +- lib/events/group_identify_event.dart | 2 +- lib/events/identify.dart | 1 + lib/events/identify_event.dart | 2 +- lib/events/revenue.dart | 14 +- lib/events/revenue_event.dart | 2 +- lib/identify.dart | 10 + lib/tracking_options.dart | 38 +-- test/amplitude_test.dart | 298 ++++++++++---------- test/events/base_event_test.dart | 82 +++--- test/events/grouop_identify_event_test.dart | 6 +- test/events/identify_event_test.dart | 6 +- test/events/identify_test.dart | 64 ++--- test/events/ingestion_metadata_test.dart | 10 +- test/events/plan_test.dart | 14 +- test/events/revenue_event_test.dart | 6 +- test/events/revenue_test.dart | 22 +- test/tracking_options_test.dart | 46 +-- 21 files changed, 333 insertions(+), 313 deletions(-) create mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..feed259 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,9 @@ +include: package:lints/recommended.yaml + +analyzer: + exclude: [lib/amplitude_web.dart, lib/web/amplitude_js.dart] # Uncomment when web is supported + +linter: + rules: + - prefer_single_quotes + - prefer_relative_imports \ No newline at end of file diff --git a/lib/amplitude.dart b/lib/amplitude.dart index 1ea4aba..c7a749d 100644 --- a/lib/amplitude.dart +++ b/lib/amplitude.dart @@ -30,7 +30,7 @@ class Amplitude { /// await amplitude.isBuilt; /// ``` Amplitude(this.configuration, [MethodChannel? methodChannel]) { - _channel = methodChannel ?? this._channel; + _channel = methodChannel ?? _channel; isBuilt = _init(); } @@ -116,7 +116,7 @@ class Amplitude { String groupType, String groupName, Identify identify, [EventOptions? options]) async { final event = GroupIdentifyEvent(); - final group = Map(); + final group = {}; group[groupType] = groupName; event.groups = group; event.groupProperties = identify.properties; @@ -142,7 +142,7 @@ class Amplitude { /// Note: This will also set groupType: groupName as a user property. Future setGroup(String groupType, dynamic groupName, [EventOptions? options]) async { - if (!(groupName is String) && !(groupName is List)) { + if (groupName is! String && groupName is! List) { // TODO(xinyi): log warn that groupName should be either a string or an array of string. return; } diff --git a/lib/configuration.dart b/lib/configuration.dart index 99308c8..053d7f4 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -97,7 +97,7 @@ class Configuration { 'appVersion': appVersion, // This field doesn't belong to Configuration // Pass it for FlutterLibraryPlugin - 'library': "${Constants.packageName}/${Constants.packageVersion}" + 'library': '${Constants.packageName}/${Constants.packageVersion}' }; } } diff --git a/lib/constants.dart b/lib/constants.dart index e03d0e0..4601fbc 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -1,9 +1,9 @@ class Constants { static const packageName = 'amplitude-flutter'; static const packageVersion = '4.0.0-beta.2'; - static const identify_event = '\$identify'; - static const group_identify_event = '\$groupidentify'; - static const revenue_event = 'revenue_amount'; + static const identifyEvent = '\$identify'; + static const groupIdentifyEvent = '\$groupidentify'; + static const revenueEvent = 'revenue_amount'; static const flushQueueSize = 30; static const flushIntervalMillis = 30 * 1000; // 30 seconds diff --git a/lib/events/group_identify_event.dart b/lib/events/group_identify_event.dart index b9ba780..94891c6 100644 --- a/lib/events/group_identify_event.dart +++ b/lib/events/group_identify_event.dart @@ -2,5 +2,5 @@ import '../constants.dart'; import 'base_event.dart'; class GroupIdentifyEvent extends BaseEvent { - GroupIdentifyEvent() : super(eventType: Constants.group_identify_event); + GroupIdentifyEvent() : super(eventType: Constants.groupIdentifyEvent); } diff --git a/lib/events/identify.dart b/lib/events/identify.dart index a57cc1a..09c6f6c 100644 --- a/lib/events/identify.dart +++ b/lib/events/identify.dart @@ -100,5 +100,6 @@ class Identify { propertySet.add(property); } + // ignore: constant_identifier_names static const UNSET_VALUE = '-'; } diff --git a/lib/events/identify_event.dart b/lib/events/identify_event.dart index 56f07d4..6f91f48 100644 --- a/lib/events/identify_event.dart +++ b/lib/events/identify_event.dart @@ -2,5 +2,5 @@ import '../constants.dart'; import 'base_event.dart'; class IdentifyEvent extends BaseEvent { - IdentifyEvent() : super(eventType: Constants.identify_event); + IdentifyEvent() : super(eventType: Constants.identifyEvent); } diff --git a/lib/events/revenue.dart b/lib/events/revenue.dart index c536c5f..a63ddc4 100644 --- a/lib/events/revenue.dart +++ b/lib/events/revenue.dart @@ -1,13 +1,13 @@ import 'revenue_event.dart'; class RevenueConstants { - static const String revenueProductId = "\$productId"; - static const String revenueQuantity = "\$quantity"; - static const String revenuePrice = "\$price"; - static const String revenueType = "\$revenueType"; - static const String revenueReceipt = "\$receipt"; - static const String revenueReceiptSig = "\$receiptSig"; - static const String revenue = "\$revenue"; + static const String revenueProductId = '\$productId'; + static const String revenueQuantity = '\$quantity'; + static const String revenuePrice = '\$price'; + static const String revenueType = '\$revenueType'; + static const String revenueReceipt = '\$receipt'; + static const String revenueReceiptSig = '\$receiptSig'; + static const String revenue = '\$revenue'; } class Revenue { diff --git a/lib/events/revenue_event.dart b/lib/events/revenue_event.dart index 3dad5fa..c6850c8 100644 --- a/lib/events/revenue_event.dart +++ b/lib/events/revenue_event.dart @@ -2,5 +2,5 @@ import '../constants.dart'; import 'base_event.dart'; class RevenueEvent extends BaseEvent { - RevenueEvent() : super(eventType: Constants.revenue_event); + RevenueEvent() : super(eventType: Constants.revenueEvent); } diff --git a/lib/identify.dart b/lib/identify.dart index a3112ec..0cc30a6 100644 --- a/lib/identify.dart +++ b/lib/identify.dart @@ -3,15 +3,25 @@ import 'package:flutter/foundation.dart'; class Identify { Identify() : payload = {}; + // ignore: constant_identifier_names static const String OP_SET = r'$set'; + // ignore: constant_identifier_names static const String OP_SET_ONCE = r'$setOnce'; + // ignore: constant_identifier_names static const String OP_ADD = r'$add'; + // ignore: constant_identifier_names static const String OP_APPEND = r'$append'; + // ignore: constant_identifier_names static const String OP_UNSET = r'$unset'; + // ignore: constant_identifier_names static const String OP_PREPEND = r'$prepend'; + // ignore: constant_identifier_names static const String OP_PREINSERT = r'$preInsert'; + // ignore: constant_identifier_names static const String OP_POSTINSERT = r'$postInsert'; + // ignore: constant_identifier_names static const String OP_REMOVE = r'$remove'; + // ignore: constant_identifier_names static const String OP_CLEAR_ALL = r'$clearAll'; final Map payload; diff --git a/lib/tracking_options.dart b/lib/tracking_options.dart index 250f584..59cca20 100644 --- a/lib/tracking_options.dart +++ b/lib/tracking_options.dart @@ -67,25 +67,25 @@ class TrackingOptions { Map toMap() { return { - "ipAddress": ipAddress, - "language": language, - "platform": platform, - "region": region, - "dma": dma, - "country": country, - "city": city, - "carrier": carrier, - "deviceModel": deviceModel, - "deviceManufacturer": deviceManufacturer, - "osVersion": osVersion, - "osName": osName, - "versionName": versionName, - "adid": adid, - "appSetId": appSetId, - "deviceBrand": deviceBrand, - "latLag": latLag, - "apiLevel": apiLevel, - "idfv": idfv, + 'ipAddress': ipAddress, + 'language': language, + 'platform': platform, + 'region': region, + 'dma': dma, + 'country': country, + 'city': city, + 'carrier': carrier, + 'deviceModel': deviceModel, + 'deviceManufacturer': deviceManufacturer, + 'osVersion': osVersion, + 'osName': osName, + 'versionName': versionName, + 'adid': adid, + 'appSetId': appSetId, + 'deviceBrand': deviceBrand, + 'latLag': latLag, + 'apiLevel': apiLevel, + 'idfv': idfv, }; } } diff --git a/test/amplitude_test.dart b/test/amplitude_test.dart index 80913dd..8fcdd36 100644 --- a/test/amplitude_test.dart +++ b/test/amplitude_test.dart @@ -22,226 +22,226 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); late MockMethodChannel mockChannel; late Amplitude amplitude; - final testApiKey = "test-api-key"; - final testUserId = "test user id"; - final testDeviceId = "test device id"; - final testProperty = "property"; - final testValue = "value"; - final testGroupType = "group type"; - final testGroupName = "group name"; + final testApiKey = 'test-api-key'; + final testUserId = 'test user id'; + final testDeviceId = 'test device id'; + final testProperty = 'property'; + final testValue = 'value'; + final testGroupType = 'group type'; + final testGroupName = 'group name'; final testConfiguration = Configuration(apiKey: testApiKey); final testConfigurationMap = { - "apiKey": testApiKey, - "flushQueueSize": 30, - "flushIntervalMillis": 30000, - "instanceName": Constants.defaultInstanceName, - "optOut": false, - "logLevel": LogLevel.warn.name, - "minIdLength": null, - "partnerId": null, - "flushMaxRetries": 5, - "useBatch": false, - "serverZone": ServerZone.us.name, - "serverUrl": null, - "minTimeBetweenSessionsMillis": 5 * 60 * 1000, - "defaultTracking": { - "sessions": true, - "appLifecycles": false, - "screenViews": false, - "deepLinks": false, - "attribution": true, - "pageViews": true, - "formInteractions": true, - "fileDownloads": true, + 'apiKey': testApiKey, + 'flushQueueSize': 30, + 'flushIntervalMillis': 30000, + 'instanceName': Constants.defaultInstanceName, + 'optOut': false, + 'logLevel': LogLevel.warn.name, + 'minIdLength': null, + 'partnerId': null, + 'flushMaxRetries': 5, + 'useBatch': false, + 'serverZone': ServerZone.us.name, + 'serverUrl': null, + 'minTimeBetweenSessionsMillis': 5 * 60 * 1000, + 'defaultTracking': { + 'sessions': true, + 'appLifecycles': false, + 'screenViews': false, + 'deepLinks': false, + 'attribution': true, + 'pageViews': true, + 'formInteractions': true, + 'fileDownloads': true, }, - "trackingOptions": { - "ipAddress": true, - "language": true, - "platform": true, - "region": true, - "dma": true, - "country": true, - "city": true, - "carrier": true, - "deviceModel": true, - "deviceManufacturer": true, - "osVersion": true, - "osName": true, - "versionName": true, - "adid": true, - "appSetId": true, - "deviceBrand": true, - "latLag": true, - "apiLevel": true, - "idfv": true, + 'trackingOptions': { + 'ipAddress': true, + 'language': true, + 'platform': true, + 'region': true, + 'dma': true, + 'country': true, + 'city': true, + 'carrier': true, + 'deviceModel': true, + 'deviceManufacturer': true, + 'osVersion': true, + 'osName': true, + 'versionName': true, + 'adid': true, + 'appSetId': true, + 'deviceBrand': true, + 'latLag': true, + 'apiLevel': true, + 'idfv': true, }, - "enableCoppaControl": false, - "flushEventsOnClose": true, - "identifyBatchIntervalMillis": 30 * 1000, - "migrateLegacyData": true, - "locationListening": true, - "useAdvertisingIdForDeviceId": false, - "useAppSetIdForDeviceId": false, - "appVersion": null, + 'enableCoppaControl': false, + 'flushEventsOnClose': true, + 'identifyBatchIntervalMillis': 30 * 1000, + 'migrateLegacyData': true, + 'locationListening': true, + 'useAdvertisingIdForDeviceId': false, + 'useAppSetIdForDeviceId': false, + 'appVersion': null, // This field doesn't belong to Configuration // Pass it for FlutterLibraryPlugin - "library": "${Constants.packageName}/${Constants.packageVersion}" + 'library': '${Constants.packageName}/${Constants.packageVersion}' }; - final testEvent = BaseEvent(eventType: "testEvent"); + final testEvent = BaseEvent(eventType: 'testEvent'); final testEventMap = { - "event_type": "testEvent", - "attempts": 0, + 'event_type': 'testEvent', + 'attempts': 0, }; final testPrice = 3.99; final testQuantity = 3; - final testProductId = "com.company.productId"; + final testProductId = 'com.company.productId'; setUp(() async { mockChannel = MockMethodChannel(); - when(mockChannel.invokeListMethod("init", any)) + when(mockChannel.invokeListMethod('init', any)) .thenAnswer((_) async => null); amplitude = Amplitude(testConfiguration, mockChannel); await amplitude.isBuilt; }); - test("Should init and track call MethodChannel", () async { - when(mockChannel.invokeMethod("track", any)).thenAnswer((_) async => null); + test('Should init and track call MethodChannel', () async { + when(mockChannel.invokeMethod('track', any)).thenAnswer((_) async => null); 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); + test('Should track with event options calls MethodChannel', () async { + when(mockChannel.invokeMethod('track', any)).thenAnswer((_) async => null); await amplitude.track(testEvent, EventOptions(userId: testUserId)); - final expectedEventMap = new Map.from(testEventMap); - expectedEventMap["user_id"] = testUserId; - verify(mockChannel.invokeMethod("track", expectedEventMap)).called(1); + final expectedEventMap = Map.from(testEventMap); + expectedEventMap['user_id'] = testUserId; + verify(mockChannel.invokeMethod('track', expectedEventMap)).called(1); }); - test("Should identify calls MethodChannel", () async { - when(mockChannel.invokeMethod("identify", any)) + test('Should identify calls MethodChannel', () async { + when(mockChannel.invokeMethod('identify', any)) .thenAnswer((_) async => null); 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} + final testIdentifyMap = Map.from(testEventMap); + testIdentifyMap['event_type'] = Constants.identifyEvent; + 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 { - when(mockChannel.invokeMethod("identify", any)) + test('Should identify calls setUserId in MethodChannel', () async { + when(mockChannel.invokeMethod('identify', any)) .thenAnswer((_) async => null); - when(mockChannel.invokeMethod("setUserId", any)) + when(mockChannel.invokeMethod('setUserId', any)) .thenAnswer((_) async => null); final identify = Identify()..set(testProperty, testValue); await amplitude.identify(identify, EventOptions(userId: testUserId)); - final testIdentifyMap = new Map.from(testEventMap); - testIdentifyMap["user_id"] = testUserId; - testIdentifyMap["event_type"] = Constants.identify_event; - testIdentifyMap["user_properties"] = { - "\$set": {testProperty: testValue} + final testIdentifyMap = Map.from(testEventMap); + testIdentifyMap['user_id'] = testUserId; + testIdentifyMap['event_type'] = Constants.identifyEvent; + testIdentifyMap['user_properties'] = { + '\$set': {testProperty: testValue} }; - verify(mockChannel.invokeMethod("setUserId", {"setUserId": testUserId})) + 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 { - when(mockChannel.invokeMethod("identify", any)) + test('Should identify calls setDeviceId in MethodChannel', () async { + when(mockChannel.invokeMethod('identify', any)) .thenAnswer((_) async => null); - when(mockChannel.invokeMethod("setDeviceId", any)) + when(mockChannel.invokeMethod('setDeviceId', any)) .thenAnswer((_) async => null); final identify = Identify()..set(testProperty, testValue); await amplitude.identify(identify, EventOptions(deviceId: testDeviceId)); - final testIdentifyMap = new Map.from(testEventMap); - testIdentifyMap["device_id"] = testDeviceId; - testIdentifyMap["event_type"] = Constants.identify_event; - testIdentifyMap["user_properties"] = { - "\$set": {testProperty: testValue} + final testIdentifyMap = Map.from(testEventMap); + testIdentifyMap['device_id'] = testDeviceId; + testIdentifyMap['event_type'] = Constants.identifyEvent; + testIdentifyMap['user_properties'] = { + '\$set': {testProperty: testValue} }; verify(mockChannel - .invokeMethod("setDeviceId", {"setDeviceId": testDeviceId})).called(1); - verify(mockChannel.invokeMethod("identify", testIdentifyMap)).called(1); + .invokeMethod('setDeviceId', {'setDeviceId': testDeviceId})).called(1); + verify(mockChannel.invokeMethod('identify', testIdentifyMap)).called(1); }); - test("Should groupIdentify calls MethodChannel", () async { - when(mockChannel.invokeMethod("groupIdentify", any)) + test('Should groupIdentify calls MethodChannel', () async { + when(mockChannel.invokeMethod('groupIdentify', any)) .thenAnswer((_) async => null); 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; - testIdentifyMap["groups"] = {testGroupType: testGroupName}; - testIdentifyMap["group_properties"] = { - "\$set": {testProperty: testValue} + final testIdentifyMap = Map.from(testEventMap); + testIdentifyMap['event_type'] = Constants.groupIdentifyEvent; + testIdentifyMap['groups'] = {testGroupType: testGroupName}; + testIdentifyMap['group_properties'] = { + '\$set': {testProperty: testValue} }; - verify(mockChannel.invokeMethod("groupIdentify", testIdentifyMap)) + verify(mockChannel.invokeMethod('groupIdentify', testIdentifyMap)) .called(1); }); - test("Should groupIdentify with event options calls MethodChannel", () async { - when(mockChannel.invokeMethod("groupIdentify", any)) + test('Should groupIdentify with event options calls MethodChannel', () async { + when(mockChannel.invokeMethod('groupIdentify', any)) .thenAnswer((_) async => null); 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; - testIdentifyMap["user_id"] = testUserId; - testIdentifyMap["groups"] = {testGroupType: testGroupName}; - testIdentifyMap["group_properties"] = { - "\$set": {testProperty: testValue} + final testIdentifyMap = Map.from(testEventMap); + testIdentifyMap['event_type'] = Constants.groupIdentifyEvent; + testIdentifyMap['user_id'] = testUserId; + testIdentifyMap['groups'] = {testGroupType: testGroupName}; + 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); + test('Should setGroup calls MethodChannel', () async { + when(mockChannel.invokeMethod('track', any)).thenAnswer((_) async => null); await amplitude.setGroup(testGroupType, testGroupName); - final testIdentifyMap = new Map.from(testEventMap); - testIdentifyMap["event_type"] = Constants.identify_event; - testIdentifyMap["groups"] = {testGroupType: testGroupName}; - testIdentifyMap["user_properties"] = { - "\$set": {testGroupType: testGroupName} + final testIdentifyMap = Map.from(testEventMap); + testIdentifyMap['event_type'] = Constants.identifyEvent; + testIdentifyMap['groups'] = {testGroupType: testGroupName}; + testIdentifyMap['user_properties'] = { + '\$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); + test('Should setGroup with event options calls MethodChannel', () async { + when(mockChannel.invokeMethod('track', any)).thenAnswer((_) async => null); await amplitude.setGroup( testGroupType, testGroupName, EventOptions(userId: testUserId)); - final testIdentifyMap = new Map.from(testEventMap); - testIdentifyMap["event_type"] = Constants.identify_event; - testIdentifyMap["groups"] = {testGroupType: testGroupName}; - testIdentifyMap["user_properties"] = { - "\$set": {testGroupType: testGroupName} + final testIdentifyMap = Map.from(testEventMap); + testIdentifyMap['event_type'] = Constants.identifyEvent; + testIdentifyMap['groups'] = {testGroupType: testGroupName}; + testIdentifyMap['user_properties'] = { + '\$set': {testGroupType: testGroupName} }; - testIdentifyMap["user_id"] = testUserId; + testIdentifyMap['user_id'] = testUserId; - verify(mockChannel.invokeMethod("setGroup", testIdentifyMap)).called(1); + verify(mockChannel.invokeMethod('setGroup', testIdentifyMap)).called(1); }); test('Should revenue calls MethodChannel', () async { @@ -254,14 +254,14 @@ void main() { ..productId = testProductId; await amplitude.revenue(revenue); - final testRevenueMap = new Map.from(testEventMap); - testRevenueMap["event_type"] = Constants.revenue_event; - testRevenueMap["event_properties"] = {}; - testRevenueMap["event_properties"][RevenueConstants.revenuePrice] = + final testRevenueMap = Map.from(testEventMap); + testRevenueMap['event_type'] = Constants.revenueEvent; + testRevenueMap['event_properties'] = {}; + testRevenueMap['event_properties'][RevenueConstants.revenuePrice] = testPrice; - testRevenueMap["event_properties"][RevenueConstants.revenueQuantity] = + testRevenueMap['event_properties'][RevenueConstants.revenueQuantity] = testQuantity; - testRevenueMap["event_properties"][RevenueConstants.revenueProductId] = + testRevenueMap['event_properties'][RevenueConstants.revenueProductId] = testProductId; verify(mockChannel.invokeMethod('revenue', testRevenueMap)).called(1); @@ -277,15 +277,15 @@ void main() { ..productId = testProductId; 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] = + final testRevenueMap = Map.from(testEventMap); + testRevenueMap['user_id'] = testUserId; + testRevenueMap['event_type'] = Constants.revenueEvent; + testRevenueMap['event_properties'] = {}; + testRevenueMap['event_properties'][RevenueConstants.revenuePrice] = testPrice; - testRevenueMap["event_properties"][RevenueConstants.revenueQuantity] = + testRevenueMap['event_properties'][RevenueConstants.revenueQuantity] = testQuantity; - testRevenueMap["event_properties"][RevenueConstants.revenueProductId] = + testRevenueMap['event_properties'][RevenueConstants.revenueProductId] = testProductId; verify(mockChannel.invokeMethod('revenue', testRevenueMap)).called(1); @@ -297,7 +297,7 @@ void main() { amplitude.setUserId(testUserId); - verify(mockChannel.invokeMethod('setUserId', {"setUserId": testUserId})) + verify(mockChannel.invokeMethod('setUserId', {'setUserId': testUserId})) .called(1); }); @@ -308,7 +308,7 @@ void main() { amplitude.setDeviceId(testDeviceId); verify(mockChannel - .invokeMethod('setDeviceId', {"setDeviceId": testDeviceId})).called(1); + .invokeMethod('setDeviceId', {'setDeviceId': testDeviceId})).called(1); }); test('Should setDeviceId calls MethodChannel', () async { @@ -318,7 +318,7 @@ void main() { amplitude.setDeviceId(testDeviceId); verify(mockChannel - .invokeMethod('setDeviceId', {"setDeviceId": testDeviceId})).called(1); + .invokeMethod('setDeviceId', {'setDeviceId': testDeviceId})).called(1); }); test('Should reset calls MethodChannel', () async { diff --git a/test/events/base_event_test.dart b/test/events/base_event_test.dart index ed0a9aa..76f2dc8 100644 --- a/test/events/base_event_test.dart +++ b/test/events/base_event_test.dart @@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('BaseEvent', () { test('Should init with default values', () { - final testEventType = "test-event-type"; + final testEventType = 'test-event-type'; final event = BaseEvent(eventType: testEventType); expect(event.eventType, testEventType); @@ -18,16 +18,16 @@ void main() { }); test('Should init with custom values', () { - final testEventType = "test-event-type"; + final testEventType = 'test-event-type'; final testEventProperties = { - "test-event-property-key": "test-event-property-value" + 'test-event-property-key': 'test-event-property-value' }; final testUserProperties = { - "test-user-property-key": "test-user-property-value" + 'test-user-property-key': 'test-user-property-value' }; - final testGroups = {"test-group-key": "test-group-value"}; + final testGroups = {'test-group-key': 'test-group-value'}; final testGroupProperties = { - "test-group-property-key": "test-group-property-value" + 'test-group-property-key': 'test-group-property-value' }; final event = BaseEvent( eventType: testEventType, @@ -45,45 +45,45 @@ void main() { }); test('Should toMap() return a correct map with custom values', () { - final eventType = "test_event"; - final userId = "test_user"; - final deviceId = "test_device"; + final eventType = 'test_event'; + final userId = 'test_user'; + final deviceId = 'test_device'; final timestamp = 1234567890; final eventId = 1; final sessionId = 2; - final insertId = "insert_id"; + final insertId = 'insert_id'; final locationLat = 37.7749; final locationLng = -122.4194; - final appVersion = "1.0.0"; - final versionName = "version_name"; - final platform = "Flutter"; - final osName = "iOS"; - final osVersion = "14.4"; - final deviceBrand = "Apple"; - final deviceManufacturer = "Apple"; - final deviceModel = "iPhone12,1"; - final carrier = "T-Mobile"; - final country = "USA"; - final region = "CA"; - final city = "San Francisco"; - final dma = "dma_code"; - final idfa = "idfa_value"; - final idfv = "idfv_value"; - final adid = "adid_value"; - final appSetId = "app_set_id"; - final androidId = "android_id"; - final language = "en"; - final library = "amplitude-flutter"; - final ip = "192.168.1.1"; - final plan = Plan(branch: "test_branch", source: "test_source", version: "test_version", versionId: "test_user_id"); - final ingestionMetadata = IngestionMetadata(sourceName: "source_name", sourceVersion: "source_version"); + final appVersion = '1.0.0'; + final versionName = 'version_name'; + final platform = 'Flutter'; + final osName = 'iOS'; + final osVersion = '14.4'; + final deviceBrand = 'Apple'; + final deviceManufacturer = 'Apple'; + final deviceModel = 'iPhone12,1'; + final carrier = 'T-Mobile'; + final country = 'USA'; + final region = 'CA'; + final city = 'San Francisco'; + final dma = 'dma_code'; + final idfa = 'idfa_value'; + final idfv = 'idfv_value'; + final adid = 'adid_value'; + final appSetId = 'app_set_id'; + final androidId = 'android_id'; + final language = 'en'; + final library = 'amplitude-flutter'; + final ip = '192.168.1.1'; + final plan = Plan(branch: 'test_branch', source: 'test_source', version: 'test_version', versionId: 'test_user_id'); + final ingestionMetadata = IngestionMetadata(sourceName: 'source_name', sourceVersion: 'source_version'); final revenue = 9.99; final price = 9.99; final quantity = 1; - final productId = "product_id"; - final revenueType = "purchase"; - final extra = {"extra_key": "extra_value"}; - final partnerId = "partner_id"; + final productId = 'product_id'; + final revenueType = 'purchase'; + final extra = {'extra_key': 'extra_value'}; + final partnerId = 'partner_id'; final event = BaseEvent( userId: userId, @@ -174,10 +174,10 @@ void main() { }); test('Should mergeEventOptions() merge event options', () { - final originalUserId = "original_user"; - final newUserId = "new_user"; - final deviceId = "device_id"; - final eventType = "event_type"; + final originalUserId = 'original_user'; + final newUserId = 'new_user'; + final deviceId = 'device_id'; + final eventType = 'event_type'; final originalEvent = BaseEvent(userId: originalUserId, deviceId: deviceId, eventType: eventType); final newOptions = EventOptions(userId: newUserId); diff --git a/test/events/grouop_identify_event_test.dart b/test/events/grouop_identify_event_test.dart index adf6551..551afd7 100644 --- a/test/events/grouop_identify_event_test.dart +++ b/test/events/grouop_identify_event_test.dart @@ -3,11 +3,11 @@ import 'package:amplitude_flutter/events/group_identify_event.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - group("GroupIdentifyEvent", () { - test("should init with default values", () { + group('GroupIdentifyEvent', () { + test('should init with default values', () { final groupIdentifyEvent = GroupIdentifyEvent(); - expect(groupIdentifyEvent.eventType, Constants.group_identify_event); + expect(groupIdentifyEvent.eventType, Constants.groupIdentifyEvent); }); }); } diff --git a/test/events/identify_event_test.dart b/test/events/identify_event_test.dart index f34b997..35a5e93 100644 --- a/test/events/identify_event_test.dart +++ b/test/events/identify_event_test.dart @@ -3,11 +3,11 @@ import 'package:amplitude_flutter/events/identify_event.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - group("IdentifyEvent", () { - test("should init with default values", () { + group('IdentifyEvent', () { + test('should init with default values', () { final identifyEvent = IdentifyEvent(); - expect(identifyEvent.eventType, Constants.identify_event); + expect(identifyEvent.eventType, Constants.identifyEvent); }); }); } diff --git a/test/events/identify_test.dart b/test/events/identify_test.dart index 79c6ed2..d2f2192 100644 --- a/test/events/identify_test.dart +++ b/test/events/identify_test.dart @@ -2,21 +2,21 @@ import 'package:test/test.dart'; import 'package:amplitude_flutter/events/identify.dart'; void main() { - final String testProperty = "test-property"; - final String testValue = "test-value"; + final String testProperty = 'test-property'; + final String testValue = 'test-value'; group('IdentifyOperation', () { test('Operation types should be correct', () { - expect(IdentifyOperation.set.operationType, "\$set"); - expect(IdentifyOperation.setOnce.operationType, "\$setOnce"); - expect(IdentifyOperation.add.operationType, "\$add"); - expect(IdentifyOperation.append.operationType, "\$append"); - expect(IdentifyOperation.clearAll.operationType, "\$clearAll"); - expect(IdentifyOperation.prepend.operationType, "\$prepend"); - expect(IdentifyOperation.unset.operationType, "\$unset"); - expect(IdentifyOperation.preInsert.operationType, "\$preInsert"); - expect(IdentifyOperation.postInsert.operationType, "\$postInsert"); - expect(IdentifyOperation.remove.operationType, "\$remove"); + expect(IdentifyOperation.set.operationType, '\$set'); + expect(IdentifyOperation.setOnce.operationType, '\$setOnce'); + expect(IdentifyOperation.add.operationType, '\$add'); + expect(IdentifyOperation.append.operationType, '\$append'); + expect(IdentifyOperation.clearAll.operationType, '\$clearAll'); + expect(IdentifyOperation.prepend.operationType, '\$prepend'); + expect(IdentifyOperation.unset.operationType, '\$unset'); + expect(IdentifyOperation.preInsert.operationType, '\$preInsert'); + expect(IdentifyOperation.postInsert.operationType, '\$postInsert'); + expect(IdentifyOperation.remove.operationType, '\$remove'); }); }); @@ -25,8 +25,8 @@ void main() { final identify = Identify(); identify.set(testProperty, testValue); - expect(identify.properties.containsKey("\$set"), isTrue); - expect(identify.properties["\$set"][testProperty], testValue); + expect(identify.properties.containsKey('\$set'), isTrue); + expect(identify.properties['\$set'][testProperty], testValue); expect(identify.propertySet.contains(testProperty), isTrue); }); @@ -34,8 +34,8 @@ void main() { final identify = Identify(); identify.setOnce(testProperty, testValue); - expect(identify.properties.containsKey("\$setOnce"), isTrue); - expect(identify.properties["\$setOnce"][testProperty], testValue); + expect(identify.properties.containsKey('\$setOnce'), isTrue); + expect(identify.properties['\$setOnce'][testProperty], testValue); expect(identify.propertySet.contains(testProperty), isTrue); }); @@ -43,8 +43,8 @@ void main() { final identify = Identify(); identify.add(testProperty, testValue); - expect(identify.properties.containsKey("\$add"), isTrue); - expect(identify.properties["\$add"][testProperty], testValue); + expect(identify.properties.containsKey('\$add'), isTrue); + expect(identify.properties['\$add'][testProperty], testValue); expect(identify.propertySet.contains(testProperty), isTrue); }); @@ -52,8 +52,8 @@ void main() { final identify = Identify(); identify.append(testProperty, testValue); - expect(identify.properties.containsKey("\$append"), isTrue); - expect(identify.properties["\$append"][testProperty], testValue); + expect(identify.properties.containsKey('\$append'), isTrue); + expect(identify.properties['\$append'][testProperty], testValue); expect(identify.propertySet.contains(testProperty), isTrue); }); @@ -61,8 +61,8 @@ void main() { final identify = Identify(); identify.prepend(testProperty, testValue); - expect(identify.properties.containsKey("\$prepend"), isTrue); - expect(identify.properties["\$prepend"][testProperty], testValue); + expect(identify.properties.containsKey('\$prepend'), isTrue); + expect(identify.properties['\$prepend'][testProperty], testValue); expect(identify.propertySet.contains(testProperty), isTrue); }); @@ -70,8 +70,8 @@ void main() { final identify = Identify(); identify.preInsert(testProperty, testValue); - expect(identify.properties.containsKey("\$preInsert"), isTrue); - expect(identify.properties["\$preInsert"][testProperty], testValue); + expect(identify.properties.containsKey('\$preInsert'), isTrue); + expect(identify.properties['\$preInsert'][testProperty], testValue); expect(identify.propertySet.contains(testProperty), isTrue); }); @@ -79,8 +79,8 @@ void main() { final identify = Identify(); identify.remove(testProperty, testValue); - expect(identify.properties.containsKey("\$remove"), isTrue); - expect(identify.properties["\$remove"][testProperty], testValue); + expect(identify.properties.containsKey('\$remove'), isTrue); + expect(identify.properties['\$remove'][testProperty], testValue); expect(identify.propertySet.contains(testProperty), isTrue); }); @@ -88,9 +88,9 @@ void main() { final identify = Identify(); identify.unset(testProperty); - expect(identify.properties.containsKey("\$unset"), isTrue); + expect(identify.properties.containsKey('\$unset'), isTrue); expect( - identify.properties["\$unset"][testProperty], Identify.UNSET_VALUE); + identify.properties['\$unset'][testProperty], Identify.UNSET_VALUE); expect(identify.propertySet.contains(testProperty), isTrue); }); @@ -101,16 +101,16 @@ void main() { // After clearAll, properties should be cleared except for the clearAll operation itself expect(identify.properties.length, 1); - expect(identify.properties.containsKey("\$clearAll"), isTrue); + expect(identify.properties.containsKey('\$clearAll'), isTrue); // Attempt to set another property after clearAll should be ignored identify.set(testProperty, testValue); - expect(identify.properties.containsKey("\$set"), isFalse); + expect(identify.properties.containsKey('\$set'), isFalse); }); test('Should not proceed when property is empty', () { final identify = Identify(); - identify.set("", testValue); + identify.set('', testValue); expect(identify.properties.length, 0); }); @@ -126,7 +126,7 @@ void main() { () { final identify = Identify(); identify.set(testProperty, testValue); - identify.set(testProperty, "new Value"); + identify.set(testProperty, 'new Value'); expect(identify.properties.length, 1); expect(identify.propertySet.length, 1); expect(identify.properties[IdentifyOperation.set.operationType], diff --git a/test/events/ingestion_metadata_test.dart b/test/events/ingestion_metadata_test.dart index f78d3e8..ba36972 100644 --- a/test/events/ingestion_metadata_test.dart +++ b/test/events/ingestion_metadata_test.dart @@ -2,18 +2,18 @@ import 'package:amplitude_flutter/events/ingestion_metadata.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - final testSourceName = "test-source-name"; - final testSourceVersion = "test-source-version"; + final testSourceName = 'test-source-name'; + final testSourceVersion = 'test-source-version'; - group("IngestionMetadata", () { - test("Should init with default values", () { + group('IngestionMetadata', () { + test('Should init with default values', () { final ingestionMetadata = IngestionMetadata(); expect(ingestionMetadata.sourceName, isNull); expect(ingestionMetadata.sourceVersion, isNull); }); - test("Should init with custom values", () { + test('Should init with custom values', () { final ingestionMetadata = IngestionMetadata( sourceName: testSourceName, sourceVersion: testSourceVersion, diff --git a/test/events/plan_test.dart b/test/events/plan_test.dart index 508157b..2e7b403 100644 --- a/test/events/plan_test.dart +++ b/test/events/plan_test.dart @@ -2,13 +2,13 @@ import 'package:amplitude_flutter/events/plan.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - final testBranch = "test-branch"; - final testSource = "test-source"; - final testVersion = "test-version"; - final testVersionId = "test-version-id"; + final testBranch = 'test-branch'; + final testSource = 'test-source'; + final testVersion = 'test-version'; + final testVersionId = 'test-version-id'; - group("Plan", () { - test("Should init with default values", () { + group('Plan', () { + test('Should init with default values', () { final plan = Plan(); expect(plan.branch, isNull); @@ -17,7 +17,7 @@ void main() { expect(plan.versionId, isNull); }); - test("Should init with custom values", () { + test('Should init with custom values', () { final plan = Plan( branch: testBranch, source: testSource, diff --git a/test/events/revenue_event_test.dart b/test/events/revenue_event_test.dart index f5ee702..01cbcb9 100644 --- a/test/events/revenue_event_test.dart +++ b/test/events/revenue_event_test.dart @@ -3,11 +3,11 @@ import 'package:amplitude_flutter/events/revenue_event.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - group("RevenueEvent", () { - test("should init with default values", () { + group('RevenueEvent', () { + test('should init with default values', () { final revenueEvent = RevenueEvent(); - expect(revenueEvent.eventType, Constants.revenue_event); + expect(revenueEvent.eventType, Constants.revenueEvent); }); }); } diff --git a/test/events/revenue_test.dart b/test/events/revenue_test.dart index 4341ec6..664320f 100644 --- a/test/events/revenue_test.dart +++ b/test/events/revenue_test.dart @@ -5,11 +5,11 @@ void main() { final int testQuantity = 2; final double testPrice = 9.99; final double testRevenue = 19.98; - final String testProductId = "test_product"; - final String testRevenueType = "test_type"; - final String testReceipt = "test_receipt"; - final String testReceiptSig = "test_receiptSig"; - final Map testProperties = {"custom_property": "custom_value"}; + final String testProductId = 'test_product'; + final String testRevenueType = 'test_type'; + final String testReceipt = 'test_receipt'; + final String testReceiptSig = 'test_receiptSig'; + final Map testProperties = {'custom_property': 'custom_value'}; Revenue createTestRevenue() { return Revenue() @@ -23,8 +23,8 @@ void main() { ..properties = testProperties; } - group("Revenue", () { - test("should create a Revenue instance with default values", () { + group('Revenue', () { + test('should create a Revenue instance with default values', () { final revenue = Revenue(); expect(revenue.quantity, 1); expect(revenue.price, isNull); @@ -36,7 +36,7 @@ void main() { expect(revenue.properties, isNull); }); - test("should correctly assign properties", () { + test('should correctly assign properties', () { final revenue = createTestRevenue(); expect(revenue.quantity, testQuantity); expect(revenue.price, testPrice); @@ -48,7 +48,7 @@ void main() { expect(revenue.properties, testProperties); }); - test("toRevenueEvent should correctly convert to RevenueEvent", () { + test('toRevenueEvent should correctly convert to RevenueEvent', () { final revenue = createTestRevenue(); final event = revenue.toRevenueEvent(); @@ -63,12 +63,12 @@ void main() { expect(event.eventProperties![RevenueConstants.revenue], testRevenue); }); - test("isValid should return true when price is not null", () { + test('isValid should return true when price is not null', () { final revenue = createTestRevenue(); expect(revenue.isValid(), isTrue); }); - test("isValid should return false when price is null", () { + test('isValid should return false when price is null', () { final revenue = Revenue(); expect(revenue.isValid(), isFalse); }); diff --git a/test/tracking_options_test.dart b/test/tracking_options_test.dart index a7d2211..507bb26 100644 --- a/test/tracking_options_test.dart +++ b/test/tracking_options_test.dart @@ -2,8 +2,8 @@ import 'package:test/test.dart'; import 'package:amplitude_flutter/tracking_options.dart'; void main() { - group("TrackingOptions", () { - test("Should have all tracking enabled by default", () { + group('TrackingOptions', () { + test('Should have all tracking enabled by default', () { final trackingOptions = TrackingOptions(); expect(trackingOptions.ipAddress, true); expect(trackingOptions.language, true); @@ -26,7 +26,7 @@ void main() { expect(trackingOptions.idfv, true); }); - test("Should init with custom options", () { + test('Should init with custom options', () { final trackingOptions = TrackingOptions(ipAddress: false, country: false, city: true); expect(trackingOptions.ipAddress, false); @@ -50,28 +50,28 @@ void main() { expect(trackingOptions.idfv, true); }); - test("Should toMap correctly", () { + test('Should toMap correctly', () { final trackingOptions = TrackingOptions(); expect(trackingOptions.toMap(), { - "ipAddress": true, - "language": true, - "platform": true, - "region": true, - "dma": true, - "country": true, - "city": true, - "carrier": true, - "deviceModel": true, - "deviceManufacturer": true, - "osVersion": true, - "osName": true, - "versionName": true, - "adid": true, - "appSetId": true, - "deviceBrand": true, - "latLag": true, - "apiLevel": true, - "idfv": true, + 'ipAddress': true, + 'language': true, + 'platform': true, + 'region': true, + 'dma': true, + 'country': true, + 'city': true, + 'carrier': true, + 'deviceModel': true, + 'deviceManufacturer': true, + 'osVersion': true, + 'osName': true, + 'versionName': true, + 'adid': true, + 'appSetId': true, + 'deviceBrand': true, + 'latLag': true, + 'apiLevel': true, + 'idfv': true, }); }); });