TF-3416 Implement parse email by blob id interactor
This commit is contained in:
@@ -659,11 +659,11 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: bb4ffba9e3aba2cbb60c1173663abf975b521199
|
||||
ref: "feature/implement-email-parse"
|
||||
resolved-ref: fbbbb2f69861719b7634b49193d9a8d2fa4e0c34
|
||||
url: "https://github.com/linagora/jmap-dart-client.git"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
version: "0.3.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -18,7 +18,7 @@ dependencies:
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: https://github.com/linagora/jmap-dart-client.git
|
||||
ref: main
|
||||
ref: feature/implement-email-parse
|
||||
|
||||
### Dependencies from pub.dev ###
|
||||
equatable: 2.0.5
|
||||
|
||||
@@ -295,11 +295,11 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: bb4ffba9e3aba2cbb60c1173663abf975b521199
|
||||
ref: "feature/implement-email-parse"
|
||||
resolved-ref: fbbbb2f69861719b7634b49193d9a8d2fa4e0c34
|
||||
url: "https://github.com/linagora/jmap-dart-client.git"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
version: "0.3.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -15,7 +15,7 @@ dependencies:
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: https://github.com/linagora/jmap-dart-client.git
|
||||
ref: main
|
||||
ref: feature/implement-email-parse
|
||||
|
||||
### Dependencies from pub.dev ###
|
||||
equatable: 2.0.5
|
||||
|
||||
+3
-3
@@ -295,11 +295,11 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: bb4ffba9e3aba2cbb60c1173663abf975b521199
|
||||
ref: "feature/implement-email-parse"
|
||||
resolved-ref: fbbbb2f69861719b7634b49193d9a8d2fa4e0c34
|
||||
url: "https://github.com/linagora/jmap-dart-client.git"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
version: "0.3.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ dependencies:
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: https://github.com/linagora/jmap-dart-client.git
|
||||
ref: main
|
||||
ref: feature/implement-email-parse
|
||||
|
||||
### Dependencies from pub.dev ###
|
||||
equatable: 2.0.5
|
||||
|
||||
@@ -295,11 +295,11 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: bb4ffba9e3aba2cbb60c1173663abf975b521199
|
||||
ref: "feature/implement-email-parse"
|
||||
resolved-ref: fbbbb2f69861719b7634b49193d9a8d2fa4e0c34
|
||||
url: "https://github.com/linagora/jmap-dart-client.git"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
version: "0.3.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -15,7 +15,7 @@ dependencies:
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: https://github.com/linagora/jmap-dart-client.git
|
||||
ref: main
|
||||
ref: feature/implement-email-parse
|
||||
|
||||
### Dependencies from pub.dev ###
|
||||
equatable: 2.0.5
|
||||
|
||||
@@ -185,4 +185,6 @@ abstract class EmailDataSource {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds);
|
||||
|
||||
Future<List<Email>> parseEmailByBlobIds(AccountId accountId, Set<Id> blobIds);
|
||||
}
|
||||
@@ -378,4 +378,11 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
Future<void> markAsForwarded(Session session, AccountId accountId, List<EmailId> emailIds) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Email>> parseEmailByBlobIds(AccountId accountId, Set<Id> blobIds) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.parseEmailByBlobIds(accountId, blobIds);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -526,4 +526,9 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Email>> parseEmailByBlobIds(AccountId accountId, Set<Id> blobIds) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/get/get_email_method.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/get/get_email_response.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/parse/parse_email_method.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/parse/parse_email_response.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/set/set_email_method.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/set/set_email_response.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/submission/address.dart';
|
||||
@@ -897,4 +899,29 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
throw SetMethodException(mapErrors);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Email>> parseEmailByBlobIds(AccountId accountId, Set<Id> blobIds) async {
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
final parseEmailMethod = ParseEmailMethod(accountId, blobIds);
|
||||
final parseEmailInvocation = requestBuilder.invocation(parseEmailMethod);
|
||||
|
||||
final response = await (requestBuilder
|
||||
..usings(parseEmailMethod.requiredCapabilities))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
final parseEmailResponse = response.parse<ParseEmailResponse>(
|
||||
parseEmailInvocation.methodCallId,
|
||||
ParseEmailResponse.deserialize);
|
||||
|
||||
if (parseEmailResponse?.parsed?.isNotEmpty == true) {
|
||||
return parseEmailResponse!.parsed!.values.toList();
|
||||
} else if (parseEmailResponse?.notParsable?.isNotEmpty == true) {
|
||||
throw NotParsableBlobIdToEmailException(ids: parseEmailResponse!.notParsable!);
|
||||
} else if (parseEmailResponse?.notFound?.isNotEmpty == true) {
|
||||
throw NotFoundBlobIdException(parseEmailResponse!.notFound!);
|
||||
} else {
|
||||
throw NotParsableBlobIdToEmailException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -483,4 +483,9 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
emailId,
|
||||
eventActionType);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Email>> parseEmailByBlobIds(AccountId accountId, Set<Id> blobIds) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
|
||||
class NotFoundEmailException implements Exception {}
|
||||
|
||||
class NotFoundEmailContentException implements Exception {}
|
||||
@@ -9,3 +11,15 @@ class NotFoundEmailRecoveryActionException implements Exception {}
|
||||
class NotFoundEmailBlobIdException implements Exception {}
|
||||
|
||||
class CannotCreateEmailObjectException implements Exception {}
|
||||
|
||||
class NotFoundBlobIdException implements Exception {
|
||||
final List<Id> ids;
|
||||
|
||||
NotFoundBlobIdException(this.ids);
|
||||
}
|
||||
|
||||
class NotParsableBlobIdToEmailException implements Exception {
|
||||
final List<Id>? ids;
|
||||
|
||||
NotParsableBlobIdToEmailException({this.ids});
|
||||
}
|
||||
@@ -179,4 +179,6 @@ abstract class EmailRepository {
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
EventActionType eventActionType);
|
||||
|
||||
Future<List<Email>> parseEmailByBlobIds(AccountId accountId, Set<Id> blobIds);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
|
||||
class ParsingEmailByBlobId extends LoadingState {}
|
||||
|
||||
class ParseEmailByBlobIdSuccess extends UIState {
|
||||
|
||||
final Email email;
|
||||
|
||||
ParseEmailByBlobIdSuccess(this.email);
|
||||
|
||||
@override
|
||||
List<Object> get props => [email];
|
||||
}
|
||||
|
||||
class ParseEmailByBlobIdFailure extends FeatureFailure {
|
||||
ParseEmailByBlobIdFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/parse_email_by_blob_id_state.dart';
|
||||
|
||||
class ParseEmailByBlobIdInteractor {
|
||||
final EmailRepository _emailRepository;
|
||||
|
||||
const ParseEmailByBlobIdInteractor(this._emailRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, Id blobId) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(ParsingEmailByBlobId());
|
||||
|
||||
final emailParsed = await _emailRepository.parseEmailByBlobIds(
|
||||
accountId,
|
||||
{blobId},
|
||||
);
|
||||
|
||||
yield Right<Failure, Success>(ParseEmailByBlobIdSuccess(emailParsed.first));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(ParseEmailByBlobIdFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -651,11 +651,11 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: bb4ffba9e3aba2cbb60c1173663abf975b521199
|
||||
ref: "feature/implement-email-parse"
|
||||
resolved-ref: fbbbb2f69861719b7634b49193d9a8d2fa4e0c34
|
||||
url: "https://github.com/linagora/jmap-dart-client.git"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
version: "0.3.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ dependencies:
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: https://github.com/linagora/jmap-dart-client.git
|
||||
ref: main
|
||||
ref: feature/implement-email-parse
|
||||
|
||||
### Dependencies from pub.dev ###
|
||||
cupertino_icons: 1.0.6
|
||||
|
||||
+3
-3
@@ -1259,11 +1259,11 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: bb4ffba9e3aba2cbb60c1173663abf975b521199
|
||||
ref: "feature/implement-email-parse"
|
||||
resolved-ref: fbbbb2f69861719b7634b49193d9a8d2fa4e0c34
|
||||
url: "https://github.com/linagora/jmap-dart-client.git"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
version: "0.3.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ dependencies:
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: https://github.com/linagora/jmap-dart-client.git
|
||||
ref: main
|
||||
ref: feature/implement-email-parse
|
||||
|
||||
contacts_service:
|
||||
git:
|
||||
|
||||
@@ -295,11 +295,11 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: bb4ffba9e3aba2cbb60c1173663abf975b521199
|
||||
ref: "feature/implement-email-parse"
|
||||
resolved-ref: fbbbb2f69861719b7634b49193d9a8d2fa4e0c34
|
||||
url: "https://github.com/linagora/jmap-dart-client.git"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
version: "0.3.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -15,7 +15,7 @@ dependencies:
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: https://github.com/linagora/jmap-dart-client.git
|
||||
ref: main
|
||||
ref: feature/implement-email-parse
|
||||
|
||||
### Dependencies from pub.dev ###
|
||||
equatable: 2.0.5
|
||||
|
||||
@@ -287,11 +287,11 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: bb4ffba9e3aba2cbb60c1173663abf975b521199
|
||||
ref: "feature/implement-email-parse"
|
||||
resolved-ref: fbbbb2f69861719b7634b49193d9a8d2fa4e0c34
|
||||
url: "https://github.com/linagora/jmap-dart-client.git"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
version: "0.3.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -14,7 +14,7 @@ dependencies:
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: https://github.com/linagora/jmap-dart-client.git
|
||||
ref: main
|
||||
ref: feature/implement-email-parse
|
||||
|
||||
### Dependencies from pub.dev ###
|
||||
equatable: 2.0.5
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart' hide State;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/parse_email_by_blob_id_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/parse_email_by_blob_id_interactor.dart';
|
||||
|
||||
import '../../../../fixtures/account_fixtures.dart';
|
||||
import '../../../../fixtures/email_fixtures.dart';
|
||||
|
||||
import 'parse_email_by_blob_id_interactor_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<EmailRepository>()])
|
||||
void main() {
|
||||
group('ParseEmailByBlobIdInteractor::execute::', () {
|
||||
late MockEmailRepository mockEmailRepository;
|
||||
late ParseEmailByBlobIdInteractor parseEmailByBlobIdInteractor;
|
||||
|
||||
setUp(() {
|
||||
mockEmailRepository = MockEmailRepository();
|
||||
parseEmailByBlobIdInteractor =
|
||||
ParseEmailByBlobIdInteractor(mockEmailRepository);
|
||||
});
|
||||
|
||||
final accountId = AccountFixtures.aliceAccountId;
|
||||
final blobId = Id('blob-id');
|
||||
|
||||
test(
|
||||
'should emit ParsingEmailByBlobId and ParseEmailByBlobIdSuccess\n'
|
||||
'when repository call succeeds', () async {
|
||||
// Arrange
|
||||
final parsedEmail = EmailFixtures.email1;
|
||||
|
||||
when(mockEmailRepository.parseEmailByBlobIds(accountId, {blobId}))
|
||||
.thenAnswer((_) async => [parsedEmail]);
|
||||
|
||||
// Act
|
||||
final result = parseEmailByBlobIdInteractor.execute(accountId, blobId);
|
||||
|
||||
// Assert
|
||||
|
||||
await expectLater(
|
||||
result,
|
||||
emitsInOrder([
|
||||
Right<Failure, Success>(ParsingEmailByBlobId()),
|
||||
Right<Failure, Success>(ParseEmailByBlobIdSuccess(parsedEmail)),
|
||||
]),
|
||||
);
|
||||
|
||||
verify(mockEmailRepository.parseEmailByBlobIds(accountId, {blobId}))
|
||||
.called(1);
|
||||
verifyNoMoreInteractions(mockEmailRepository);
|
||||
});
|
||||
|
||||
test(
|
||||
'should emit ParsingEmailByBlobId and ParseEmailByBlobIdFailure\n'
|
||||
'when repository call throws exception', () async {
|
||||
// Arrange
|
||||
final exception = Exception('Failed to parse email');
|
||||
|
||||
when(mockEmailRepository.parseEmailByBlobIds(accountId, {blobId}))
|
||||
.thenThrow(exception);
|
||||
|
||||
// Act
|
||||
final result = parseEmailByBlobIdInteractor.execute(accountId, blobId);
|
||||
|
||||
// Assert
|
||||
await expectLater(
|
||||
result,
|
||||
emitsInOrder([
|
||||
Right<Failure, Success>(ParsingEmailByBlobId()),
|
||||
Left<Failure, Success>(ParseEmailByBlobIdFailure(exception)),
|
||||
]),
|
||||
);
|
||||
|
||||
verify(mockEmailRepository.parseEmailByBlobIds(accountId, {blobId}))
|
||||
.called(1);
|
||||
verifyNoMoreInteractions(mockEmailRepository);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user