TF-3189 new option to copy a folder's subaddress

This commit is contained in:
Florent Azavant
2024-11-29 14:29:59 +01:00
committed by Dat H. Pham
parent 89d80fe142
commit f1ec1d7324
12 changed files with 181 additions and 7 deletions
@@ -36,6 +36,8 @@ import 'package:tmail_ui_user/features/login/domain/usecases/delete_authority_oi
import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart';
import 'package:tmail_ui_user/features/login/domain/usecases/get_authenticated_account_interactor.dart';
import 'package:tmail_ui_user/features/login/domain/usecases/update_account_cache_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/empty_folder_name_exception.dart';
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/invalid_mail_format_exception.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/create_new_default_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/create_new_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/delete_multiple_mailbox_interactor.dart';
@@ -580,4 +582,81 @@ void main() {
expect(spamId, isNull);
});
});
group('getSubaddress:test', () {
setUp(() {
getEmailsInMailboxInteractor = MockGetEmailsInMailboxInteractor();
when(emailReceiveManager.pendingSharedFileInfo).thenAnswer((_) => BehaviorSubject.seeded([]));
Get.put(mailboxDashboardController);
mailboxDashboardController.onReady();
mailboxController = MailboxController(
createNewMailboxInteractor,
deleteMultipleMailboxInteractor,
renameMailboxInteractor,
moveMailboxInteractor,
subscribeMailboxInteractor,
subscribeMultipleMailboxInteractor,
subaddressingInteractor,
createDefaultMailboxInteractor,
treeBuilder,
verifyNameInteractor,
getAllMailboxInteractor,
refreshAllMailboxInteractor);
mailboxController.onReady();
threadController = ThreadController(
getEmailsInMailboxInteractor,
refreshChangesEmailsInMailboxInteractor,
loadMoreEmailsInMailboxInteractor,
searchEmailInteractor,
searchMoreEmailInteractor,
getEmailByIdInteractor);
Get.put(threadController);
advancedFilterController = AdvancedFilterController();
mailboxDashboardController.sessionCurrent = testSession;
mailboxDashboardController.filterMessageOption.value = FilterMessageOption.all;
mailboxDashboardController.accountId.value = testAccountId;
});
test('should return subaddress with valid email and folder name', () {
const String userEmail = 'user@example.com';
const String folderName = 'folder';
final result = mailboxController.getSubaddress(userEmail, folderName);
expect(result, equals('user+folder@example.com'));
});
test('should throw an error if empty local part', () {
const userEmail = '@example.com';
const folderName = 'folder';
expect(() => mailboxController.getSubaddress(userEmail, folderName), throwsA(isA<InvalidMailFormatException>()));
});
test('should throw an error if empty folder name', () {
const userEmail = 'user@example.com';
const folderName = '';
expect(() => mailboxController.getSubaddress(userEmail, folderName), throwsA(isA<EmptyFolderNameException>()));
});
test('should throw an error if empty domain', () {
const userEmail = 'user@';
const folderName = 'folder';
expect(() => mailboxController.getSubaddress(userEmail, folderName), throwsA(isA<InvalidMailFormatException>()));
});
test('should throw an error if absent `@`', () {
const userEmail = 'invalid-email-format';
const folderName = 'folder';
expect(() => mailboxController.getSubaddress(userEmail, folderName), throwsA(isA<InvalidMailFormatException>()));
});
});
}