Skip to content

Commit

Permalink
chore(pana): perform changes from pana test
Browse files Browse the repository at this point in the history
SUITEDEV-34999

Co-authored-by: megamegax <megamegax@users.noreply.github.com>
LordAndras and megamegax committed Jan 17, 2024
1 parent b82b754 commit 3bf6e81
Showing 7 changed files with 108 additions and 112 deletions.
7 changes: 2 additions & 5 deletions lib/model/emarsys_config.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:flutter/foundation.dart';

enum ConsoleLogLevels { BASIC, DEBUG, WARN, ERROR, INFO, TRACE }

class EmarsysConfig {
@@ -25,9 +23,8 @@ class EmarsysConfig {
androidVerboseConsoleLoggingEnabled,
'androidSharedSecret': androidSharedSecret,
'androidSharedPackageNames': androidSharedPackageNames,
'iOSEnabledConsoleLogLevels': iOSEnabledConsoleLogLevels
?.map((logLevel) => describeEnum(logLevel))
.toList()
'iOSEnabledConsoleLogLevels':
iOSEnabledConsoleLogLevels?.map((logLevel) => logLevel.name).toList()
};
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ version: 2.2.0
homepage: https://github.com/emartech/flutter-plugin-for-sap-emarsys-customer-engagement

environment:
sdk: '>=2.14.0 <4.0.0'
sdk: '>=2.15.0 <4.0.0'
flutter: ">=1.20.0"

dependencies:
7 changes: 2 additions & 5 deletions test/geofence_test.dart
Original file line number Diff line number Diff line change
@@ -87,9 +87,7 @@ void main() {
}
});


test('registeredGeofences should delegate to the Platform',
() async {
test('registeredGeofences should delegate to the Platform', () async {
MethodCall? actualMethodCall;
channel.setMockMethodCallHandler((MethodCall methodCall) async {
actualMethodCall = methodCall;
@@ -101,8 +99,7 @@ void main() {

expect(actualMethodCall != null, true);
if (actualMethodCall != null) {
expect(
actualMethodCall!.method, 'geofence.registeredGeofences');
expect(actualMethodCall!.method, 'geofence.registeredGeofences');
}
});
}
158 changes: 77 additions & 81 deletions test/mapper/geofence_mapper_test.dart
Original file line number Diff line number Diff line change
@@ -1,97 +1,93 @@

import 'package:emarsys_sdk/mappers/geofence_mapper.dart';
import 'package:emarsys_sdk/model/geofence_model.dart';
import 'package:emarsys_sdk/model/geofence_trigger.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:emarsys_sdk/model/geofence_model.dart';
import 'package:emarsys_sdk/model/geofence_trigger.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
final GeofenceMapper mapper = GeofenceMapper();

void main() {
final GeofenceMapper mapper = GeofenceMapper();
test('map should not crash when inputList is empty', () async {
final List<Map<String, String>> emptyList = [];
final List<GeofenceModel> result = mapper.map(emptyList);

test('map should not crash when inputList is empty', () async {
final List<Map<String, String>> emptyList = [];
final List<GeofenceModel> result = mapper.map(emptyList);
expect(result.length, 0);
});

expect(result.length, 0);
});

test('map should not crash when inputList contains null', () async {
final List<Map<String,dynamic>?> emptyList = [null];
final List<GeofenceModel> result = mapper.map(emptyList);
test('map should not crash when inputList contains null', () async {
final List<Map<String, dynamic>?> emptyList = [null];
final List<GeofenceModel> result = mapper.map(emptyList);

expect(result.length, 0);
});
expect(result.length, 0);
});

test('map should not crash when inputList contains emptyMap', () async {
final List<Map<String, String>> emptyList = [{}];
final List<GeofenceModel> result = mapper.map(emptyList);
test('map should not crash when inputList contains emptyMap', () async {
final List<Map<String, String>> emptyList = [{}];
final List<GeofenceModel> result = mapper.map(emptyList);

expect(result.length, 0);
});
expect(result.length, 0);
});

test('map should return with correct result', () async {
Map<String, Object> fullMessageMap = {
"id": "testId",
"lat": 12.34,
"lon": 56.78,
"radius": 30.0,
"waitInterval": 90.12
};
fullMessageMap["triggers"] = [
{
"id": "trigger1",
"type": "Type1",
"loiteringDelay": 123,
"action": {
"actionKey1": "actionValue1",
"actionKey12": "actionValue12",
"actionKey13": 123
}
},
{
"id": "trigger2",
"type": "Type2",
"loiteringDelay": 456,
"action": {
"actionKey2": "actionValue2",
"actionKey22": "actionValue22",
"actionKey23": 456
}
test('map should return with correct result', () async {
Map<String, Object> fullMessageMap = {
"id": "testId",
"lat": 12.34,
"lon": 56.78,
"radius": 30.0,
"waitInterval": 90.12
};
fullMessageMap["triggers"] = [
{
"id": "trigger1",
"type": "Type1",
"loiteringDelay": 123,
"action": {
"actionKey1": "actionValue1",
"actionKey12": "actionValue12",
"actionKey13": 123
}
},
{
"id": "trigger2",
"type": "Type2",
"loiteringDelay": 456,
"action": {
"actionKey2": "actionValue2",
"actionKey22": "actionValue22",
"actionKey23": 456
}
];
}
];

GeofenceTrigger trigger1 = GeofenceTrigger(
GeofenceTrigger trigger1 = GeofenceTrigger(
id: "trigger1",
type: "Type1",
loiteringDelay: 123,
action: {
"actionKey1": "actionValue1",
"actionKey12": "actionValue12",
"actionKey13": 123
}
);
type: "Type1",
loiteringDelay: 123,
action: {
"actionKey1": "actionValue1",
"actionKey12": "actionValue12",
"actionKey13": 123
});

GeofenceTrigger trigger2 = GeofenceTrigger(
GeofenceTrigger trigger2 = GeofenceTrigger(
id: "trigger2",
type: "Type2",
loiteringDelay: 456,
action: {
"actionKey2": "actionValue2",
"actionKey22": "actionValue22",
"actionKey23": 456
}
);
type: "Type2",
loiteringDelay: 456,
action: {
"actionKey2": "actionValue2",
"actionKey22": "actionValue22",
"actionKey23": 456
});

GeofenceModel expectedMessage = GeofenceModel(
id: "testId",
lat: 12.34,
lon: 56.78,
radius: 30.0,
waitInterval: 90.12,
triggers:[trigger1, trigger2]
);
GeofenceModel expectedMessage = GeofenceModel(
id: "testId",
lat: 12.34,
lon: 56.78,
radius: 30.0,
waitInterval: 90.12,
triggers: [trigger1, trigger2]);

List<GeofenceModel> result = mapper.map([fullMessageMap]);
List<GeofenceModel> result = mapper.map([fullMessageMap]);

expect(result[0], expectedMessage);
});
}
expect(result[0], expectedMessage);
});
}
24 changes: 16 additions & 8 deletions test/mapper/logic_mapper_test.dart
Original file line number Diff line number Diff line change
@@ -7,15 +7,17 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
final LogicMapper mapper = LogicMapper(CartItemListMapper());

test('map with search logic should return a map with correct name and data', () async {
test('map with search logic should return a map with correct name and data',
() async {
final Logic testLogic = RecommendationLogic.search(searchTerm: "abc123");
final Map<String, dynamic> result = mapper.map(testLogic);

expect(result["name"], "SEARCH");
expect(result["data"]["searchTerm"], "abc123");
});

test('map with cart logic should return a map with correct name and data', () async {
test('map with cart logic should return a map with correct name and data',
() async {
List<CartItem> testItems = [
PredictCartItem(itemId: "id1", price: 1, quantity: 1),
PredictCartItem(itemId: "id2", price: 2, quantity: 2)
@@ -33,7 +35,8 @@ void main() {
expect(result["data"]["cartItems"][1]["quantity"], 2);
});

test('map with category logic should return a map with correct name and data', () async {
test('map with category logic should return a map with correct name and data',
() async {
final Logic testLogic =
RecommendationLogic.category(categoryPath: "abc123");
final Map<String, dynamic> result = mapper.map(testLogic);
@@ -42,7 +45,8 @@ void main() {
expect(result["data"]["categoryPath"], "abc123");
});

test('map with alsoBought logic should return a map with correct name and data',
test(
'map with alsoBought logic should return a map with correct name and data',
() async {
final Logic testLogic = RecommendationLogic.alsoBought(itemId: "abc123");
final Map<String, dynamic> result = mapper.map(testLogic);
@@ -51,23 +55,26 @@ void main() {
expect(result["data"]["itemId"], "abc123");
});

test('map with popular logic should return a map with correct name and data', () async {
test('map with popular logic should return a map with correct name and data',
() async {
final Logic testLogic = RecommendationLogic.popular(categoryPath: "abc123");
final Map<String, dynamic> result = mapper.map(testLogic);

expect(result["name"], "POPULAR");
expect(result["data"]["categoryPath"], "abc123");
});

test('map with related logic should return a map with correct name and data', () async {
test('map with related logic should return a map with correct name and data',
() async {
final Logic testLogic = RecommendationLogic.related(itemId: "abc123");
final Map<String, dynamic> result = mapper.map(testLogic);

expect(result["name"], "RELATED");
expect(result["data"]["itemId"], "abc123");
});

test('map with personal logic should return a map with correct name and variants',
test(
'map with personal logic should return a map with correct name and variants',
() async {
final Logic testLogic =
RecommendationLogic.personal(variants: ["variant1", "variant2"]);
@@ -77,7 +84,8 @@ void main() {
expect(result["variants"], ["variant1", "variant2"]);
});

test('map with home logic should return a map with correct name and variants', () async {
test('map with home logic should return a map with correct name and variants',
() async {
final Logic testLogic =
RecommendationLogic.home(variants: ["variant1", "variant2"]);
final Map<String, dynamic> result = mapper.map(testLogic);
14 changes: 7 additions & 7 deletions test/predict/recommendation_filter_test.dart
Original file line number Diff line number Diff line change
@@ -24,20 +24,20 @@ void main() {
});

test('inValue should create RecommendationFilter', () async {
var result =
RecommendationFilter.include("testField").inValues(["testValue1","testValue2"]);
var result = RecommendationFilter.include("testField")
.inValues(["testValue1", "testValue2"]);
expect(result.comparison, Comparison.IN);
expect(result.field, "testField");
expect(result.filterType, FilterType.INCLUDE);
expect(result.values, ["testValue1","testValue2"]);
});
expect(result.values, ["testValue1", "testValue2"]);
});

test('overlapsValues should create RecommendationFilter', () async {
var result =
RecommendationFilter.include("testField").overlapsValues(["testValue1","testValue2"]);
var result = RecommendationFilter.include("testField")
.overlapsValues(["testValue1", "testValue2"]);
expect(result.comparison, Comparison.OVERLAPS);
expect(result.field, "testField");
expect(result.filterType, FilterType.INCLUDE);
expect(result.values, ["testValue1","testValue2"]);
expect(result.values, ["testValue1", "testValue2"]);
});
}
8 changes: 3 additions & 5 deletions test/predict_test.dart
Original file line number Diff line number Diff line change
@@ -156,15 +156,13 @@ void main() {
final List<TestCartItem> items = [];
channel.setMockMethodCallHandler((MethodCall methodCall) async {
throw PlatformException(
code: '42',
message: 'Items list should not be empty!'
);
code: '42', message: 'Items list should not be empty!');
});

expect(
Emarsys.predict.trackPurchase(orderId, items),
throwsA(isA<PlatformException>().having(
(error) => error.message, 'message', 'Items list should not be empty!')));
throwsA(isA<PlatformException>().having((error) => error.message,
'message', 'Items list should not be empty!')));
});

test('recommendProducts with only Logic should delegate to the Platform',

0 comments on commit 3bf6e81

Please sign in to comment.