refactor: share low-risk UI and tracker helpers

This commit is contained in:
edde746
2026-05-02 01:58:50 +02:00
parent 646832c6b1
commit 50bc245677
18 changed files with 270 additions and 265 deletions
@@ -0,0 +1,26 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/services/trackers/tracker_session_utils.dart';
void main() {
group('tracker token expiry helpers', () {
test('detects expired token', () {
expect(isTrackerTokenExpired(100, nowSeconds: 100), isTrue);
expect(isTrackerTokenExpired(101, nowSeconds: 100), isFalse);
});
test('detects refresh window', () {
expect(trackerTokenNeedsRefresh(400, nowSeconds: 100), isTrue);
expect(trackerTokenNeedsRefresh(401, nowSeconds: 100), isFalse);
expect(trackerTokenNeedsRefresh(110, refreshWindowSeconds: 10, nowSeconds: 100), isTrue);
});
});
group('tracker session json codec', () {
test('round-trips through provided factory', () {
final encoded = encodeTrackerSessionJson({'access_token': 'abc', 'created_at': 123});
final decoded = decodeTrackerSessionJson(encoded, (json) => json);
expect(decoded, {'access_token': 'abc', 'created_at': 123});
});
});
}
+25
View File
@@ -60,6 +60,31 @@ void main() {
});
});
group('flexibleBoolNullable', () {
test('returns bool as-is', () {
expect(flexibleBoolNullable(true), isTrue);
expect(flexibleBoolNullable(false), isFalse);
});
test('maps 1 to true, other ints to false', () {
expect(flexibleBoolNullable(1), isTrue);
expect(flexibleBoolNullable(0), isFalse);
expect(flexibleBoolNullable(2), isFalse);
});
test("maps '1' string to true, other strings to false", () {
expect(flexibleBoolNullable('1'), isTrue);
expect(flexibleBoolNullable('0'), isFalse);
expect(flexibleBoolNullable('true'), isFalse);
});
test('returns null for null and unsupported types', () {
expect(flexibleBoolNullable(null), isNull);
expect(flexibleBoolNullable(1.0), isNull);
expect(flexibleBoolNullable(<String, Object>{}), isNull);
});
});
group('flexibleDouble', () {
test('parses num as double', () {
expect(flexibleDouble(1.5), 1.5);