TF-2613 Add validate same domain method & unit test
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:core/utils/app_logger.dart';
|
||||||
|
import 'package:get/get_utils/src/get_utils/get_utils.dart';
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
@@ -58,7 +60,7 @@ class EmailUtils {
|
|||||||
(failure) {
|
(failure) {
|
||||||
return failure is DownloadAttachmentForWebFailure
|
return failure is DownloadAttachmentForWebFailure
|
||||||
|| failure is ViewAttachmentForWebFailure;
|
|| failure is ViewAttachmentForWebFailure;
|
||||||
},
|
},
|
||||||
(success) {
|
(success) {
|
||||||
return success is DownloadAttachmentForWebSuccess
|
return success is DownloadAttachmentForWebSuccess
|
||||||
|| success is ViewAttachmentForWebSuccess
|
|| success is ViewAttachmentForWebSuccess
|
||||||
@@ -66,4 +68,13 @@ class EmailUtils {
|
|||||||
|| success is IdleViewAttachmentForWeb;
|
|| success is IdleViewAttachmentForWeb;
|
||||||
}) ?? false;
|
}) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isSameDomain({
|
||||||
|
required String emailAddress,
|
||||||
|
required String serverDomain
|
||||||
|
}) {
|
||||||
|
log('EmailUtils::isSameDomain: emailAddress = $emailAddress | serverDomain = $serverDomain');
|
||||||
|
return GetUtils.isEmail(emailAddress) &&
|
||||||
|
emailAddress.split('@').last.toLowerCase() == serverDomain.toLowerCase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('EmailUtils', () {
|
||||||
|
test('isSameDomain should return true when email is from the same domain as server', () {
|
||||||
|
String emailAddress = 'user@example.com';
|
||||||
|
String serverDomain = 'example.com';
|
||||||
|
|
||||||
|
bool result = EmailUtils.isSameDomain(emailAddress: emailAddress, serverDomain: serverDomain);
|
||||||
|
|
||||||
|
expect(result, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isSameDomain should return false when email is not from the same domain as server', () {
|
||||||
|
String emailAddress = 'user@example.com';
|
||||||
|
String serverDomain = 'example2.com';
|
||||||
|
|
||||||
|
bool result = EmailUtils.isSameDomain(emailAddress: emailAddress, serverDomain: serverDomain);
|
||||||
|
|
||||||
|
expect(result, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isSameDomain should return false when email is invalid', () {
|
||||||
|
String emailAddress = 'invalid_email';
|
||||||
|
String serverDomain = 'example.com';
|
||||||
|
|
||||||
|
bool result = EmailUtils.isSameDomain(emailAddress: emailAddress, serverDomain: serverDomain);
|
||||||
|
|
||||||
|
expect(result, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user