v1.0.12 customer properties and membership
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:workouttest_util/model/cache.dart';
|
||||
import 'package:workouttest_util/model/customer.dart';
|
||||
import 'package:workouttest_util/model/property.dart';
|
||||
import 'package:workouttest_util/repository/customer_repository.dart';
|
||||
import 'dart:collection';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
main() {
|
||||
setUp(() {
|
||||
String propertyJson = '''
|
||||
[
|
||||
{
|
||||
"propertyId": 1,
|
||||
"propertyName": "Weight",
|
||||
"propertyUnit": "kg",
|
||||
"translations": [
|
||||
{
|
||||
"translationId": 11,
|
||||
"languageCode": "hu",
|
||||
"propertyName": "Tömeg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"propertyId": 2,
|
||||
"propertyName": "Height",
|
||||
"propertyUnit": "cm",
|
||||
"translations": [
|
||||
{
|
||||
"translationId": 12,
|
||||
"languageCode": "hu",
|
||||
"propertyName": "Magasság"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"propertyId": 3,
|
||||
"propertyName": "Chest",
|
||||
"propertyUnit": "cm",
|
||||
"translations": [
|
||||
{
|
||||
"translationId": 13,
|
||||
"languageCode": "hu",
|
||||
"propertyName": "Mell"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
''';
|
||||
Iterable json = jsonDecode(propertyJson);
|
||||
final List<Property> properties = json.map((property) => Property.fromJson(property)).toList();
|
||||
Cache().setProperties(properties);
|
||||
});
|
||||
|
||||
group('customer', () {
|
||||
test('decode from json successful', () async {
|
||||
String json = '''{
|
||||
"name": "",
|
||||
"firstname": "Andi",
|
||||
"email": "mr@aitrainer.app",
|
||||
"age": 0,
|
||||
"sex": "m",
|
||||
"active": "Y",
|
||||
"dateAdd": "2023-02-25 11:19:30",
|
||||
"dataPolicyAllowed": 1,
|
||||
"password": "2a10O5HXhhb29LC8pNiv1uBIoOFRGOmDMtdeMJtVkfhzAjB/ejrO9D486",
|
||||
"birthYear": 1974,
|
||||
"goal": "health_keep",
|
||||
"fitnessLevel": "intermediate",
|
||||
"firebaseUid": "ih74dupj2ncyROAaeyK8oAXYOWk2",
|
||||
"emailSubscription": 0,
|
||||
"firebaseRegToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjE1YzJiNDBhYTJmMzIyNzk4NjY2YTZiMzMyYWFhMDNhNjc3MzAxOWIiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZGlldDR5b3UtY2I1NDAiLCJhdWQiOiJkaWV0NHlvdS1jYjU0MCIsImF1dGhfdGltZSI6MTY3NzMyMDM3MSwidXNlcl9pZCI6ImloNzRkdXBqMm5jeVJPQWFleUs4b0FYWU9XazIiLCJzdWIiOiJpaDc0ZHVwajJuY3lST0FhZXlLOG9BWFlPV2syIiwiaWF0IjoxNjc3MzIwMzcxLCJleHAiOjE2NzczMjM5NzEsImVtYWlsIjoibXJAYWl0cmFpbmVyLmFwcCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJtckBhaXRyYWluZXIuYXBwIl19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifX0.yds_4NSc1m7U7q6y1jdHy61Z1Y_4weOWfC_mbvzQsGLqsuOuP_SM6OvhqQOjywAWGhvm709mydm9nWdhhPNDNTcC5pn8Xl770GYoMF_8tLPae8Mrw-9ppFvXNHXg0kKpl2uIirjMhZM19fq4HBLJPAReQ8-8FCHfodXRd5TH5EWSZnZ-TzdwvKaitfjn_-2w4tA1WepH4XhCwP908NG-U6IUwBOsi_aoQpQwSJWL9HwW1pTsYSE0DubfKOmsMBH3WaVkkJfcL1IOGBR4TK-vimkfmP2VnU3F88GF583b1FKw-JZ6ovOBy4jHnL02k_yAQksMwHXeaSGMwulWdjxqHQ",
|
||||
"customerId": 56,
|
||||
"properties": [
|
||||
{
|
||||
"customerPropertyId": 3,
|
||||
"propertyId": 1,
|
||||
"propertyValue": 66.0,
|
||||
"dateAdd": "2023-02-25 11:19:30",
|
||||
"goal": false
|
||||
},
|
||||
{
|
||||
"customerPropertyId": 4,
|
||||
"propertyId": 2,
|
||||
"propertyValue": 178.0,
|
||||
"dateAdd": "2023-02-25 11:19:30",
|
||||
"goal": false
|
||||
}
|
||||
],
|
||||
"memberships": [
|
||||
{
|
||||
"id": 2,
|
||||
"membershipId": 2,
|
||||
"startDate": "2023-02-25 11:19:30"
|
||||
}
|
||||
]
|
||||
}''';
|
||||
|
||||
Customer customer = Customer.fromJson(jsonDecode(json));
|
||||
expect(customer.customerId, 56);
|
||||
expect(customer.customerProperties.length, 2);
|
||||
expect(customer.customerProperties[0].propertyValue, 66);
|
||||
expect(customer.customerProperties[1].propertyId, 2);
|
||||
expect(customer.memberships.length, 1);
|
||||
expect(customer.memberships[0].membershipId, 2);
|
||||
Cache().userLoggedIn = customer;
|
||||
CustomerRepository repository = CustomerRepository();
|
||||
repository.initCustomerProperties();
|
||||
|
||||
customer = Cache().userLoggedIn!;
|
||||
expect(customer.properties.length, 2);
|
||||
expect(customer.getProperty("Weight"), 66);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user