@@ -5,21 +5,24 @@ import 'package:flutter_test/flutter_test.dart';
55
66void main () {
77 group ('toWithingsObject' , () {
8- test ('should correctly convert data to WithingsObject' , () {
8+ test ('should correctly convert data to WithingsObject 1 ' , () {
99 final Map <String , dynamic > data = {
10- 'date' : DateTime .parse ('2019-03-01T07:38:14' ).millisecondsSinceEpoch,
10+ 'date' :
11+ (DateTime .parse ('2019-03-01T07:38:14' ).millisecondsSinceEpoch ~ /
12+ 1000 )
13+ .toString (),
1114 'measures' : [
12- {'type' : 76 , 'value' : 25.91 , 'unit' : 0 },
13- {'type' : 1 , 'value' : 70000 , 'unit' : - 3 },
14- {'type' : 5 , 'value' : 15000 , 'unit' : - 3 },
15- {'type' : 6 , 'value' : 55000 , 'unit' : - 3 },
16- {'type' : 8 , 'value' : 21 , 'unit' : 0 },
15+ {'type' : 1 , 'value' : 70000 , 'unit' : - 3 }, // Weight = 70.0
16+ {'type' : 4 , 'value' : 1643 , 'unit' : - 3 }, // Height = 1.643
17+ {'type' : 5 , 'value' : 55000 , 'unit' : - 3 }, // Fat-Free Mass = 55.0
18+ {'type' : 6 , 'value' : 21 , 'unit' : 0 }, // Fat Ratio = 21%
19+ {'type' : 8 , 'value' : 15000 , 'unit' : - 3 }, // Fat Mass = 15.0
1720 ],
1821 };
1922
2023 final expected = WithingsObject (
2124 date: DateTime (2019 , 3 , 1 , 7 , 38 , 14 ),
22- bmi: 25.91 ,
25+ bmi: 25.93 ,
2326 weightInKg: 70.0 ,
2427 fatInKg: 15.0 ,
2528 leanInKg: 55.0 ,
@@ -29,15 +32,74 @@ void main() {
2932 final result = toWithingsObject (data);
3033
3134 expect (result, isA <WithingsObject >());
32- expect (result.date, equals (expected.date));
35+
36+ expect (result.date.year, equals (expected.date.year));
37+ expect (result.date.month, equals (expected.date.month));
38+ expect (result.date.day, equals (expected.date.day));
39+
3340 expect (result.weightInKg, equals (expected.weightInKg));
3441 expect (result.fatInKg, equals (expected.fatInKg));
3542 expect (result.leanInKg, equals (expected.leanInKg));
3643 expect (result.fatInPercentage, equals (expected.fatInPercentage));
3744 expect (result.bmi, equals (expected.bmi));
3845
3946 expect (result.metrics, isA <Metrics >());
40- expect (result.metrics.date, equals (expected.metrics.date));
47+
48+ expect (result.metrics.date.year, equals (expected.metrics.date.year));
49+ expect (result.metrics.date.month, equals (expected.metrics.date.month));
50+ expect (result.metrics.date.day, equals (expected.metrics.date.day));
51+
52+ expect (result.metrics.weightInKg, equals (expected.metrics.weightInKg));
53+ expect (result.metrics.fatInKg, equals (expected.metrics.fatInKg));
54+ expect (result.metrics.leanInKg, equals (expected.metrics.leanInKg));
55+ expect (
56+ result.metrics.fatInPercentage,
57+ equals (expected.metrics.fatInPercentage),
58+ );
59+ expect (result.metrics.bmi, equals (expected.metrics.bmi));
60+ });
61+
62+ test ('should correctly convert data to WithingsObject 2' , () {
63+ final Map <String , dynamic > data = {
64+ 'date' : "1684496400" , // May 19, 2023
65+ 'measures' : [
66+ {'type' : 1 , 'value' : 70000 , 'unit' : - 3 },
67+ {'type' : 4 , 'value' : 1750 , 'unit' : - 2 },
68+ {'type' : 5 , 'value' : 15000 , 'unit' : - 3 },
69+ {'type' : 6 , 'value' : 200 , 'unit' : - 1 },
70+ {'type' : 8 , 'value' : 14000 , 'unit' : - 3 },
71+ ],
72+ };
73+
74+ final expected = WithingsObject (
75+ date: DateTime (2023 , 5 , 19 , 7 , 0 , 0 ),
76+ bmi: 0.23 ,
77+ weightInKg: 70.0 ,
78+ fatInKg: 14.0 ,
79+ leanInKg: 15.0 ,
80+ fatInPercentage: 20.0 ,
81+ );
82+
83+ final result = toWithingsObject (data);
84+
85+ expect (result, isA <WithingsObject >());
86+
87+ expect (result.date.year, equals (expected.date.year));
88+ expect (result.date.month, equals (expected.date.month));
89+ expect (result.date.day, equals (expected.date.day));
90+
91+ expect (result.weightInKg, equals (expected.weightInKg));
92+ expect (result.fatInKg, equals (expected.fatInKg));
93+ expect (result.leanInKg, equals (expected.leanInKg));
94+ expect (result.fatInPercentage, equals (expected.fatInPercentage));
95+ expect (result.bmi, equals (expected.bmi));
96+
97+ expect (result.metrics, isA <Metrics >());
98+
99+ expect (result.metrics.date.year, equals (expected.metrics.date.year));
100+ expect (result.metrics.date.month, equals (expected.metrics.date.month));
101+ expect (result.metrics.date.day, equals (expected.metrics.date.day));
102+
41103 expect (result.metrics.weightInKg, equals (expected.metrics.weightInKg));
42104 expect (result.metrics.fatInKg, equals (expected.metrics.fatInKg));
43105 expect (result.metrics.leanInKg, equals (expected.metrics.leanInKg));
@@ -50,7 +112,10 @@ void main() {
50112
51113 test ('should throw an exception if a required measurement is missing' , () {
52114 final data = {
53- 'date' : DateTime .parse ('2019-03-01T07:38:14' ).millisecondsSinceEpoch,
115+ 'date' :
116+ DateTime .parse (
117+ '2019-03-01T07:38:14' ,
118+ ).millisecondsSinceEpoch.toString (),
54119 'measures' : [
55120 {'type' : 1 , 'value' : 70000 , 'unit' : - 3 },
56121 {'type' : 5 , 'value' : 15000 , 'unit' : - 3 },
0 commit comments