refactor: share low-risk UI and tracker helpers
This commit is contained in:
@@ -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});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user