TF-2298 Write unit test to check token expired time
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit 3fc44a33c509e186a3bc5d2434169f44dcfe4169)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
import 'package:flutter_date_range_picker/flutter_date_range_picker.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
@@ -7,37 +8,36 @@ import 'package:jmap_dart_client/jmap/push/type_state.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/presentation/utils/fcm_utils.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
final expectStateChange1 = StateChange(
|
||||
'StateChange',
|
||||
{
|
||||
AccountId(Id('a3123')): TypeState({
|
||||
'Email': 'd35ecb040aab',
|
||||
'EmailDelivery': '428d565f2440',
|
||||
'CalendarEvent': '87accfac587a'
|
||||
}),
|
||||
AccountId(Id('a43461d')): TypeState({
|
||||
'Mailbox': '0af7a512ce70',
|
||||
'CalendarEvent': '7a4297cecd76'
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
final expectStateChange2 = StateChange(
|
||||
'StateChange',
|
||||
{
|
||||
AccountId(Id('a3123')): TypeState({
|
||||
'EmailDelivery': '428d565f2440',
|
||||
'CalendarEvent': '87accfac587a'
|
||||
}),
|
||||
AccountId(Id('a43461d')): TypeState({
|
||||
'Mailbox': '0af7a512ce70',
|
||||
'CalendarEvent': '7a4297cecd76'
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
group('decodeFirebaseDataMessageToStateChange test', () {
|
||||
final expectStateChange1 = StateChange(
|
||||
'StateChange',
|
||||
{
|
||||
AccountId(Id('a3123')): TypeState({
|
||||
'Email': 'd35ecb040aab',
|
||||
'EmailDelivery': '428d565f2440',
|
||||
'CalendarEvent': '87accfac587a'
|
||||
}),
|
||||
AccountId(Id('a43461d')): TypeState({
|
||||
'Mailbox': '0af7a512ce70',
|
||||
'CalendarEvent': '7a4297cecd76'
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
final expectStateChange2 = StateChange(
|
||||
'StateChange',
|
||||
{
|
||||
AccountId(Id('a3123')): TypeState({
|
||||
'EmailDelivery': '428d565f2440',
|
||||
'CalendarEvent': '87accfac587a'
|
||||
}),
|
||||
AccountId(Id('a43461d')): TypeState({
|
||||
'Mailbox': '0af7a512ce70',
|
||||
'CalendarEvent': '7a4297cecd76'
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
test('should return StateChange when parse from firebase data message with key/value is not empty', () {
|
||||
|
||||
final dataMessage = {
|
||||
@@ -92,4 +92,56 @@ void main() {
|
||||
expect(stateChange, equals(expectStateChange2));
|
||||
});
|
||||
});
|
||||
|
||||
group('checkExpirationTimeWithinGivenPeriod test', () {
|
||||
final DateFormat dateFormat = DateFormat('dd/MM/yyyy HH:mm:ss');
|
||||
|
||||
test('should return true when currentTime is before expiredTime and within offsetTime = 5m & limitOffsetTime = 10m', () {
|
||||
final currentTime = dateFormat.parse("19/12/2023 10:00:00");
|
||||
final expiredTime = dateFormat.parse("19/12/2023 10:05:00");
|
||||
final result = FcmUtils.instance.checkExpirationTimeWithinGivenPeriod(
|
||||
expiredTime: expiredTime,
|
||||
currentTime: currentTime,
|
||||
limitOffsetTime: 10,
|
||||
offsetTimeUnit: OffsetTimeUnit.minute,
|
||||
);
|
||||
expect(result, isTrue);
|
||||
});
|
||||
|
||||
test('should return true when currentTime is before expiredTime and within offsetTime = 10m & limitOffsetTime = 10m', () {
|
||||
final currentTime = dateFormat.parse("19/12/2023 10:00:00");
|
||||
final expiredTime = dateFormat.parse("19/12/2023 10:10:00");
|
||||
final result = FcmUtils.instance.checkExpirationTimeWithinGivenPeriod(
|
||||
expiredTime: expiredTime,
|
||||
currentTime: currentTime,
|
||||
limitOffsetTime: 10,
|
||||
offsetTimeUnit: OffsetTimeUnit.minute,
|
||||
);
|
||||
expect(result, isTrue);
|
||||
});
|
||||
|
||||
test('should return false when currentTime is before expiredTime and within offsetTime = 15m & limitOffsetTime = 10m', () {
|
||||
final currentTime = dateFormat.parse("19/12/2023 10:00:00");
|
||||
final expiredTime = dateFormat.parse("19/12/2023 10:15:00");
|
||||
final result = FcmUtils.instance.checkExpirationTimeWithinGivenPeriod(
|
||||
expiredTime: expiredTime,
|
||||
currentTime: currentTime,
|
||||
limitOffsetTime: 10,
|
||||
offsetTimeUnit: OffsetTimeUnit.minute,
|
||||
);
|
||||
expect(result, isFalse);
|
||||
});
|
||||
|
||||
test('should return true when currentTime is after expiredTime', () {
|
||||
final currentTime = dateFormat.parse("19/12/2023 10:10:00");
|
||||
final expiredTime = dateFormat.parse("19/12/2023 10:00:00");
|
||||
final result = FcmUtils.instance.checkExpirationTimeWithinGivenPeriod(
|
||||
expiredTime: expiredTime,
|
||||
currentTime: currentTime,
|
||||
limitOffsetTime: 10,
|
||||
offsetTimeUnit: OffsetTimeUnit.minute,
|
||||
);
|
||||
expect(result, isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user