TF-3035 Unit test draft with identity
This commit is contained in:
+114
@@ -0,0 +1,114 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:model/email/email_action_type.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/domain/usecases/create_new_and_save_email_to_drafts_interactor.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
|
||||||
|
|
||||||
|
import '../../../../fixtures/account_fixtures.dart';
|
||||||
|
import '../../../../fixtures/session_fixtures.dart';
|
||||||
|
import 'create_new_and_save_email_to_drafts_interactor_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([
|
||||||
|
MockSpec<EmailRepository>(),
|
||||||
|
MockSpec<MailboxRepository>(),
|
||||||
|
MockSpec<ComposerRepository>(),
|
||||||
|
])
|
||||||
|
void main() {
|
||||||
|
late MockEmailRepository emailRepository;
|
||||||
|
late MockMailboxRepository mailboxRepository;
|
||||||
|
late MockComposerRepository composerRepository;
|
||||||
|
late CreateNewAndSaveEmailToDraftsInteractor createNewAndSaveEmailToDraftsInteractor;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
emailRepository = MockEmailRepository();
|
||||||
|
mailboxRepository = MockMailboxRepository();
|
||||||
|
composerRepository = MockComposerRepository();
|
||||||
|
createNewAndSaveEmailToDraftsInteractor = CreateNewAndSaveEmailToDraftsInteractor(
|
||||||
|
emailRepository,
|
||||||
|
mailboxRepository,
|
||||||
|
composerRepository);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('create new and save email to drafts interactor test:', () {
|
||||||
|
test(
|
||||||
|
'should call generateEmail from composerRepository with withIdentityHeader is true '
|
||||||
|
'when execute is called '
|
||||||
|
'and draftsEmailId != null',
|
||||||
|
() async {
|
||||||
|
// arrange
|
||||||
|
final createEmailRequest = CreateEmailRequest(
|
||||||
|
session: SessionFixtures.aliceSession,
|
||||||
|
accountId: AccountFixtures.aliceAccountId,
|
||||||
|
emailActionType: EmailActionType.editDraft,
|
||||||
|
subject: 'subject',
|
||||||
|
emailContent: 'emailContent',
|
||||||
|
fromSender: {},
|
||||||
|
toRecipients: {},
|
||||||
|
ccRecipients: {},
|
||||||
|
bccRecipients: {},
|
||||||
|
draftsEmailId: EmailId(Id('some-id'))
|
||||||
|
);
|
||||||
|
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader')))
|
||||||
|
.thenAnswer((_) async => Email());
|
||||||
|
when(emailRepository.updateEmailDrafts(any, any, any, any))
|
||||||
|
.thenAnswer((_) async => Email());
|
||||||
|
|
||||||
|
// act
|
||||||
|
createNewAndSaveEmailToDraftsInteractor
|
||||||
|
.execute(createEmailRequest: createEmailRequest)
|
||||||
|
.last;
|
||||||
|
await untilCalled(composerRepository.generateEmail(
|
||||||
|
any,
|
||||||
|
withIdentityHeader: anyNamed('withIdentityHeader')));
|
||||||
|
|
||||||
|
// assert
|
||||||
|
verify(composerRepository.generateEmail(
|
||||||
|
createEmailRequest,
|
||||||
|
withIdentityHeader: true)
|
||||||
|
).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'should call generateEmail from composerRepository with withIdentityHeader is true '
|
||||||
|
'when execute is called '
|
||||||
|
'and draftsEmailId == null',
|
||||||
|
() async {
|
||||||
|
// arrange
|
||||||
|
final createEmailRequest = CreateEmailRequest(
|
||||||
|
session: SessionFixtures.aliceSession,
|
||||||
|
accountId: AccountFixtures.aliceAccountId,
|
||||||
|
emailActionType: EmailActionType.editDraft,
|
||||||
|
subject: 'subject',
|
||||||
|
emailContent: 'emailContent',
|
||||||
|
fromSender: {},
|
||||||
|
toRecipients: {},
|
||||||
|
ccRecipients: {},
|
||||||
|
bccRecipients: {},
|
||||||
|
);
|
||||||
|
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader')))
|
||||||
|
.thenAnswer((_) async => Email());
|
||||||
|
when(emailRepository.saveEmailAsDrafts(any, any, any))
|
||||||
|
.thenAnswer((_) async => Email());
|
||||||
|
|
||||||
|
// act
|
||||||
|
createNewAndSaveEmailToDraftsInteractor
|
||||||
|
.execute(createEmailRequest: createEmailRequest)
|
||||||
|
.last;
|
||||||
|
await untilCalled(composerRepository.generateEmail(
|
||||||
|
any,
|
||||||
|
withIdentityHeader: anyNamed('withIdentityHeader')));
|
||||||
|
|
||||||
|
// assert
|
||||||
|
verify(composerRepository.generateEmail(
|
||||||
|
createEmailRequest,
|
||||||
|
withIdentityHeader: true)
|
||||||
|
).called(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:model/email/email_action_type.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/domain/usecases/create_new_and_send_email_interactor.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
|
||||||
|
|
||||||
|
import '../../../../fixtures/account_fixtures.dart';
|
||||||
|
import '../../../../fixtures/session_fixtures.dart';
|
||||||
|
import 'create_new_and_send_email_interactor_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([
|
||||||
|
MockSpec<EmailRepository>(),
|
||||||
|
MockSpec<MailboxRepository>(),
|
||||||
|
MockSpec<ComposerRepository>(),
|
||||||
|
])
|
||||||
|
void main() {
|
||||||
|
final emailRepository = MockEmailRepository();
|
||||||
|
final mailboxRepository = MockMailboxRepository();
|
||||||
|
final composerRepository = MockComposerRepository();
|
||||||
|
final createNewAndSendEmailInteractor = CreateNewAndSendEmailInteractor(
|
||||||
|
emailRepository,
|
||||||
|
mailboxRepository,
|
||||||
|
composerRepository);
|
||||||
|
group('create new and send email interactor test:', () {
|
||||||
|
test(
|
||||||
|
'should call generateEmail from composerRepository with withIdentityHeader is false '
|
||||||
|
'when execute is called',
|
||||||
|
() async {
|
||||||
|
// arrange
|
||||||
|
final createEmailRequest = CreateEmailRequest(
|
||||||
|
session: SessionFixtures.aliceSession,
|
||||||
|
accountId: AccountFixtures.aliceAccountId,
|
||||||
|
emailActionType: EmailActionType.editDraft,
|
||||||
|
subject: 'subject',
|
||||||
|
emailContent: 'emailContent',
|
||||||
|
fromSender: {},
|
||||||
|
toRecipients: {},
|
||||||
|
ccRecipients: {},
|
||||||
|
bccRecipients: {},
|
||||||
|
);
|
||||||
|
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader')))
|
||||||
|
.thenAnswer((_) async => Email());
|
||||||
|
|
||||||
|
// act
|
||||||
|
createNewAndSendEmailInteractor
|
||||||
|
.execute(createEmailRequest: createEmailRequest)
|
||||||
|
.last;
|
||||||
|
await untilCalled(composerRepository.generateEmail(
|
||||||
|
any,
|
||||||
|
withIdentityHeader: anyNamed('withIdentityHeader')));
|
||||||
|
|
||||||
|
// assert
|
||||||
|
verify(composerRepository.generateEmail(
|
||||||
|
createEmailRequest,
|
||||||
|
withIdentityHeader: false)
|
||||||
|
).called(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
|
||||||
|
import 'package:model/model.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/presentation/extensions/create_email_request_extension.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.dart';
|
||||||
|
|
||||||
|
import '../../../../fixtures/account_fixtures.dart';
|
||||||
|
import '../../../../fixtures/session_fixtures.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
final createEmailRequest = CreateEmailRequest(
|
||||||
|
session: SessionFixtures.aliceSession,
|
||||||
|
accountId: AccountFixtures.aliceAccountId,
|
||||||
|
emailActionType: EmailActionType.editDraft,
|
||||||
|
subject: 'subject',
|
||||||
|
emailContent: 'emailContent',
|
||||||
|
fromSender: {},
|
||||||
|
toRecipients: {},
|
||||||
|
ccRecipients: {},
|
||||||
|
bccRecipients: {},
|
||||||
|
);
|
||||||
|
|
||||||
|
group('create email request extension test:', () {
|
||||||
|
test(
|
||||||
|
'should return email with identity header '
|
||||||
|
'when generateEmail is called '
|
||||||
|
'and withIdentityHeader is true',
|
||||||
|
() {
|
||||||
|
// act
|
||||||
|
final result = createEmailRequest.generateEmail(
|
||||||
|
newEmailContent: 'newEmailContent',
|
||||||
|
newEmailAttachments: {},
|
||||||
|
userAgent: 'userAgent',
|
||||||
|
partId: PartId('value'),
|
||||||
|
withIdentityHeader: true
|
||||||
|
);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(
|
||||||
|
result.identityHeader?.containsKey(
|
||||||
|
IndividualHeaderIdentifier.identityHeader),
|
||||||
|
isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'should return email without identity header '
|
||||||
|
'when generateEmail is called '
|
||||||
|
'and withIdentityHeader is false',
|
||||||
|
() {
|
||||||
|
// act
|
||||||
|
final result = createEmailRequest.generateEmail(
|
||||||
|
newEmailContent: 'newEmailContent',
|
||||||
|
newEmailAttachments: {},
|
||||||
|
userAgent: 'userAgent',
|
||||||
|
partId: PartId('value'),
|
||||||
|
withIdentityHeader: false
|
||||||
|
);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(result.identityHeader, isNull);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user