|
|
|
1
|
+import 'package:doublefeel_flutter/core/result/app_result.dart';
|
|
1
|
import 'package:doublefeel_flutter/core/services/health_raw_data_core_service.dart';
|
2
|
import 'package:doublefeel_flutter/core/services/health_raw_data_core_service.dart';
|
|
2
|
import 'package:doublefeel_flutter/data/datasource/health/health_local_data_convert.dart';
|
3
|
import 'package:doublefeel_flutter/data/datasource/health/health_local_data_convert.dart';
|
|
|
|
4
|
+import 'package:doublefeel_flutter/data/datasource/health/health_local_datasource.dart';
|
|
3
|
import 'package:doublefeel_flutter/data/models/enums/app_enums.dart';
|
5
|
import 'package:doublefeel_flutter/data/models/enums/app_enums.dart';
|
|
4
|
import 'package:doublefeel_flutter/pigeon/health_kit_api.g.dart';
|
6
|
import 'package:doublefeel_flutter/pigeon/health_kit_api.g.dart';
|
|
5
|
import 'package:doublefeel_flutter/pigeon/health_kit_raw_data_api.g.dart';
|
7
|
import 'package:doublefeel_flutter/pigeon/health_kit_raw_data_api.g.dart';
|
|
@@ -411,6 +413,38 @@ void main() { |
|
@@ -411,6 +413,38 @@ void main() { |
|
411
|
expect(api.sleepUploadCallCount, 1);
|
413
|
expect(api.sleepUploadCallCount, 1);
|
|
412
|
expect(rows.sleepRows.single['uploaded'], 1);
|
414
|
expect(rows.sleepRows.single['uploaded'], 1);
|
|
413
|
});
|
415
|
});
|
|
|
|
416
|
+
|
|
|
|
417
|
+ test('local data source returns earliest local hr start time', () async {
|
|
|
|
418
|
+ const base = 1800000000;
|
|
|
|
419
|
+ final api = _FakeHealthKitRawDataHostApi();
|
|
|
|
420
|
+ final store = _MemoryHealthRawStressLocalStore();
|
|
|
|
421
|
+ final service = HealthRawDataCoreService(
|
|
|
|
422
|
+ healthApi: _FakeHealthKitHostApi(),
|
|
|
|
423
|
+ rawDataApi: api,
|
|
|
|
424
|
+ localStore: store,
|
|
|
|
425
|
+ userIdProvider: () => 42,
|
|
|
|
426
|
+ uploadResultsAfterCalculation: false,
|
|
|
|
427
|
+ );
|
|
|
|
428
|
+ await store.upsertResult(
|
|
|
|
429
|
+ HealthRawStressCalculationResult(
|
|
|
|
430
|
+ userId: 42,
|
|
|
|
431
|
+ hrvStressPoints: const <HealthRawHrvStressPoint>[],
|
|
|
|
432
|
+ realtimeStressPoints: [
|
|
|
|
433
|
+ _realtimeStressPoint(base + 200),
|
|
|
|
434
|
+ _realtimeStressPoint(base + 100),
|
|
|
|
435
|
+ ],
|
|
|
|
436
|
+ dailyStressPoints: const <HealthRawDailyStressPoint>[],
|
|
|
|
437
|
+ ),
|
|
|
|
438
|
+ );
|
|
|
|
439
|
+
|
|
|
|
440
|
+ final result = await LocalHealthDataSource(coreService: service)
|
|
|
|
441
|
+ .getHealthDataEverUploaded();
|
|
|
|
442
|
+
|
|
|
|
443
|
+ expect(result, isA<AppSuccess>());
|
|
|
|
444
|
+ final data = (result as AppSuccess).data;
|
|
|
|
445
|
+ expect(data.flag, isTrue);
|
|
|
|
446
|
+ expect(data.startTime, base + 100);
|
|
|
|
447
|
+ });
|
|
414
|
}
|
448
|
}
|
|
415
|
|
449
|
|
|
416
|
HealthKitRawDataPoint _point(
|
450
|
HealthKitRawDataPoint _point(
|
|
@@ -427,6 +461,17 @@ HealthKitRawDataPoint _point( |
|
@@ -427,6 +461,17 @@ HealthKitRawDataPoint _point( |
|
427
|
);
|
461
|
);
|
|
428
|
}
|
462
|
}
|
|
429
|
|
463
|
|
|
|
|
464
|
+HealthRawRealtimeStressPoint _realtimeStressPoint(int time) {
|
|
|
|
465
|
+ return HealthRawRealtimeStressPoint(
|
|
|
|
466
|
+ userId: 42,
|
|
|
|
467
|
+ rawEndTime: time,
|
|
|
|
468
|
+ rawHr: 70,
|
|
|
|
469
|
+ result: 30,
|
|
|
|
470
|
+ sourceStartTime: time,
|
|
|
|
471
|
+ sourceEndTime: time,
|
|
|
|
472
|
+ );
|
|
|
|
473
|
+}
|
|
|
|
474
|
+
|
|
430
|
class _FakeHealthKitRawDataHostApi extends HealthKitRawDataHostApi {
|
475
|
class _FakeHealthKitRawDataHostApi extends HealthKitRawDataHostApi {
|
|
431
|
final Map<int, List<HealthKitRawDataPoint>> _pointsByType = {};
|
476
|
final Map<int, List<HealthKitRawDataPoint>> _pointsByType = {};
|
|
432
|
final List<HealthKitRawWorkoutDataPoint> _workoutPoints = [];
|
477
|
final List<HealthKitRawWorkoutDataPoint> _workoutPoints = [];
|
|
@@ -436,6 +481,7 @@ class _FakeHealthKitRawDataHostApi extends HealthKitRawDataHostApi { |
|
@@ -436,6 +481,7 @@ class _FakeHealthKitRawDataHostApi extends HealthKitRawDataHostApi { |
|
436
|
var workoutCallCount = 0;
|
481
|
var workoutCallCount = 0;
|
|
437
|
var sleepUploadCallCount = 0;
|
482
|
var sleepUploadCallCount = 0;
|
|
438
|
var sleepUploadUntil = 0;
|
483
|
var sleepUploadUntil = 0;
|
|
|
|
484
|
+ var hasData = true;
|
|
439
|
|
485
|
|
|
440
|
void setPoints(int dataType, List<HealthKitRawDataPoint> points) {
|
486
|
void setPoints(int dataType, List<HealthKitRawDataPoint> points) {
|
|
441
|
_pointsByType[dataType] = points;
|
487
|
_pointsByType[dataType] = points;
|
|
@@ -458,6 +504,9 @@ class _FakeHealthKitRawDataHostApi extends HealthKitRawDataHostApi { |
|
@@ -458,6 +504,9 @@ class _FakeHealthKitRawDataHostApi extends HealthKitRawDataHostApi { |
|
458
|
}
|
504
|
}
|
|
459
|
|
505
|
|
|
460
|
@override
|
506
|
@override
|
|
|
|
507
|
+ Future<bool> hasHealthData() async => hasData;
|
|
|
|
508
|
+
|
|
|
|
509
|
+ @override
|
|
461
|
Future<List<HealthKitRawDataPoint>> getHealthKitRawData(
|
510
|
Future<List<HealthKitRawDataPoint>> getHealthKitRawData(
|
|
462
|
int dataType,
|
511
|
int dataType,
|
|
463
|
int startTime,
|
512
|
int startTime,
|
|
@@ -777,6 +826,13 @@ class _MemoryHealthRawStressLocalStore extends HealthRawStressLocalStore { |
|
@@ -777,6 +826,13 @@ class _MemoryHealthRawStressLocalStore extends HealthRawStressLocalStore { |
|
777
|
}
|
826
|
}
|
|
778
|
|
827
|
|
|
779
|
@override
|
828
|
@override
|
|
|
|
829
|
+ Future<int?> earliestRealtimeRawEndTime(int userId) async {
|
|
|
|
830
|
+ final points = _realtime[userId];
|
|
|
|
831
|
+ if (points == null || points.isEmpty) return null;
|
|
|
|
832
|
+ return points.first.rawEndTime;
|
|
|
|
833
|
+ }
|
|
|
|
834
|
+
|
|
|
|
835
|
+ @override
|
|
780
|
Future<int?> latestSleepResultTime(int userId) async {
|
836
|
Future<int?> latestSleepResultTime(int userId) async {
|
|
781
|
final results = _sleep[userId];
|
837
|
final results = _sleep[userId];
|
|
782
|
if (results == null || results.isEmpty) return null;
|
838
|
if (results == null || results.isEmpty) return null;
|