Add unit test for createDefaultMailbox & setRoleDefaultMailbox method in MailboxAPI
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -52,7 +52,7 @@ abstract class MailboxDataSource {
|
|||||||
|
|
||||||
Future<bool> handleMailboxRightRequest(Session session, AccountId accountId, MailboxRightRequest request);
|
Future<bool> handleMailboxRightRequest(Session session, AccountId accountId, MailboxRightRequest request);
|
||||||
|
|
||||||
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, List<Role> listRole);
|
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, Map<Id, Role> mapRoles);
|
||||||
|
|
||||||
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> setRoleDefaultMailbox(Session session, AccountId accountId, List<Mailbox> listMailbox);
|
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> setRoleDefaultMailbox(Session session, AccountId accountId, List<Mailbox> listMailbox);
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, List<Role> listRole) {
|
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, Map<Id, Role> mapRoles) {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,9 +130,9 @@ class MailboxDataSourceImpl extends MailboxDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, List<Role> listRole) {
|
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, Map<Id, Role> mapRoles) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
return await mailboxAPI.createDefaultMailbox(session, accountId, listRole);
|
return await mailboxAPI.createDefaultMailbox(session, accountId, mapRoles);
|
||||||
}).catchError(_exceptionThrower.throwException);
|
}).catchError(_exceptionThrower.throwException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -456,13 +456,8 @@ class MailboxAPI with HandleSetErrorMixin {
|
|||||||
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(
|
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(
|
||||||
Session session,
|
Session session,
|
||||||
AccountId accountId,
|
AccountId accountId,
|
||||||
List<Role> listRole
|
Map<Id, Role> mapRoles,
|
||||||
) async {
|
) async {
|
||||||
final mapRoles = {
|
|
||||||
for (var role in listRole)
|
|
||||||
Id(_uuid.v1()) : role
|
|
||||||
};
|
|
||||||
|
|
||||||
final mapCreate = {
|
final mapCreate = {
|
||||||
for (var id in mapRoles.keys)
|
for (var id in mapRoles.keys)
|
||||||
id : Mailbox(name: MailboxName(mapRoles[id]!.mailboxName), isSubscribed: IsSubscribed(true))
|
id : Mailbox(name: MailboxName(mapRoles[id]!.mailboxName), isSubscribed: IsSubscribed(true))
|
||||||
|
|||||||
@@ -292,8 +292,8 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, List<Role> listRole) {
|
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, Map<Id, Role> mapRoles) {
|
||||||
return mapDataSource[DataSourceType.network]!.createDefaultMailbox(session, accountId, listRole);
|
return mapDataSource[DataSourceType.network]!.createDefaultMailbox(session, accountId, mapRoles);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ abstract class MailboxRepository {
|
|||||||
|
|
||||||
Future<bool> handleMailboxRightRequest(Session session, AccountId accountId, MailboxRightRequest request);
|
Future<bool> handleMailboxRightRequest(Session session, AccountId accountId, MailboxRightRequest request);
|
||||||
|
|
||||||
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, List<Role> listRole);
|
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> createDefaultMailbox(Session session, AccountId accountId, Map<Id, Role> mapRoles);
|
||||||
|
|
||||||
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> setRoleDefaultMailbox(Session session, AccountId accountId, List<Mailbox> listMailbox);
|
Future<(List<Mailbox> mailboxes, Map<Id, SetError> mapErrors)> setRoleDefaultMailbox(Session session, AccountId accountId, List<Mailbox> listMailbox);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
|
|||||||
import 'package:core/utils/app_logger.dart';
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:dartz/dartz.dart' as dartz;
|
import 'package:dartz/dartz.dart' as dartz;
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/set_mailbox_method_exception.dart';
|
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/set_mailbox_method_exception.dart';
|
||||||
@@ -17,14 +18,14 @@ class CreateDefaultMailboxInteractor {
|
|||||||
Stream<dartz.Either<Failure, Success>> execute(
|
Stream<dartz.Either<Failure, Success>> execute(
|
||||||
Session session,
|
Session session,
|
||||||
AccountId accountId,
|
AccountId accountId,
|
||||||
List<Role> listRole
|
Map<Id, Role> mapRoles,
|
||||||
) async* {
|
) async* {
|
||||||
try {
|
try {
|
||||||
yield dartz.Right<Failure, Success>(CreateDefaultMailboxLoading());
|
yield dartz.Right<Failure, Success>(CreateDefaultMailboxLoading());
|
||||||
final mailboxesRecord = await _mailboxRepository.createDefaultMailbox(
|
final mailboxesRecord = await _mailboxRepository.createDefaultMailbox(
|
||||||
session,
|
session,
|
||||||
accountId,
|
accountId,
|
||||||
listRole
|
mapRoles,
|
||||||
);
|
);
|
||||||
|
|
||||||
final listMailboxCreated = mailboxesRecord.$1;
|
final listMailboxCreated = mailboxesRecord.$1;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import 'package:flutter_svg/flutter_svg.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart';
|
import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
@@ -650,12 +651,17 @@ class MailboxController extends BaseMailboxController
|
|||||||
final listRoleMissing = MailboxConstants.defaultMailboxRoles
|
final listRoleMissing = MailboxConstants.defaultMailboxRoles
|
||||||
.whereNot((role) => mapDefaultMailboxRole.containsKey(role) || findNodeByNameOnFirstLevel(role.value) != null)
|
.whereNot((role) => mapDefaultMailboxRole.containsKey(role) || findNodeByNameOnFirstLevel(role.value) != null)
|
||||||
.toList();
|
.toList();
|
||||||
log('MailboxController::_handleCreateDefaultFolderIfMissing():listRoleMissing: $listRoleMissing');
|
|
||||||
if (listRoleMissing.isNotEmpty && accountId != null && session != null) {
|
final mapRoles = {
|
||||||
|
for (var role in listRoleMissing)
|
||||||
|
Id(uuid.v1()) : role
|
||||||
|
};
|
||||||
|
log('MailboxController::_handleCreateDefaultFolderIfMissing():mapRoles: $mapRoles');
|
||||||
|
if (mapRoles.isNotEmpty && accountId != null && session != null) {
|
||||||
consumeState(_createDefaultMailboxInteractor.execute(
|
consumeState(_createDefaultMailboxInteractor.execute(
|
||||||
session!,
|
session!,
|
||||||
accountId!,
|
accountId!,
|
||||||
listRoleMissing
|
mapRoles,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,393 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:jmap_dart_client/http/http_client.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:model/extensions/account_id_extensions.dart';
|
||||||
|
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox/domain/extensions/role_extension.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
import '../../../fixtures/account_fixtures.dart';
|
||||||
|
import '../../../fixtures/session_fixtures.dart';
|
||||||
|
|
||||||
|
import 'mailbox_api_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([
|
||||||
|
MockSpec<HttpClient>(),
|
||||||
|
MockSpec<Uuid>()
|
||||||
|
])
|
||||||
|
void main() {
|
||||||
|
group('MailboxAPI::', () {
|
||||||
|
late HttpClient httpClient;
|
||||||
|
late Uuid uuid;
|
||||||
|
late MailboxAPI mailboxAPI;
|
||||||
|
|
||||||
|
final accountId = AccountFixtures.aliceAccountId;
|
||||||
|
final session = SessionFixtures.aliceSession;
|
||||||
|
|
||||||
|
final mapRoles = <Id, Role>{
|
||||||
|
Id('sent-create-id'): PresentationMailbox.roleSent,
|
||||||
|
Id('outbox-create-id'): PresentationMailbox.roleOutbox,
|
||||||
|
};
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
httpClient = MockHttpClient();
|
||||||
|
uuid = MockUuid();
|
||||||
|
|
||||||
|
mailboxAPI = MailboxAPI(httpClient, uuid);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('createDefaultMailbox::', () {
|
||||||
|
test('Should return full mailbox with input is a list roles when create mailbox success', () async {
|
||||||
|
final mapResponseData = {
|
||||||
|
"methodResponses": [
|
||||||
|
[
|
||||||
|
"Mailbox/set",
|
||||||
|
{
|
||||||
|
"oldState": "105",
|
||||||
|
"newState": "107",
|
||||||
|
"created": {
|
||||||
|
"sent-create-id": {
|
||||||
|
"id": "sent-id",
|
||||||
|
"myRights": {
|
||||||
|
"mayReadItems": true,
|
||||||
|
"mayAddItems": true,
|
||||||
|
"mayRemoveItems": true,
|
||||||
|
"mayCreateChild": true,
|
||||||
|
"mayDelete": true,
|
||||||
|
"maySubmit": true,
|
||||||
|
"maySetSeen": true,
|
||||||
|
"maySetKeywords": true,
|
||||||
|
"mayAdmin": true,
|
||||||
|
"mayRename": true
|
||||||
|
},
|
||||||
|
"totalEmails": 0,
|
||||||
|
"unreadEmails": 0,
|
||||||
|
"totalThreads": 0,
|
||||||
|
"unreadThreads": 0,
|
||||||
|
"isSeenShared": false,
|
||||||
|
"sortOrder": 10,
|
||||||
|
"showAsLabel": true
|
||||||
|
},
|
||||||
|
"outbox-create-id": {
|
||||||
|
"id": "outbox-id",
|
||||||
|
"myRights": {
|
||||||
|
"mayReadItems": true,
|
||||||
|
"mayAddItems": true,
|
||||||
|
"mayRemoveItems": true,
|
||||||
|
"mayCreateChild": true,
|
||||||
|
"mayDelete": true,
|
||||||
|
"maySubmit": true,
|
||||||
|
"maySetSeen": true,
|
||||||
|
"maySetKeywords": true,
|
||||||
|
"mayAdmin": true,
|
||||||
|
"mayRename": true
|
||||||
|
},
|
||||||
|
"totalEmails": 0,
|
||||||
|
"unreadEmails": 0,
|
||||||
|
"totalThreads": 0,
|
||||||
|
"unreadThreads": 0,
|
||||||
|
"isSeenShared": false,
|
||||||
|
"sortOrder": 10,
|
||||||
|
"showAsLabel": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"updated": null,
|
||||||
|
"destroyed": null,
|
||||||
|
"notCreated": null,
|
||||||
|
"notUpdated": null,
|
||||||
|
"notDestroyed": null,
|
||||||
|
"accountId": accountId.asString,
|
||||||
|
},
|
||||||
|
"c0"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sessionState": "0"
|
||||||
|
};
|
||||||
|
|
||||||
|
when(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
)).thenAnswer((_) async => mapResponseData);
|
||||||
|
|
||||||
|
final mailboxRecords = await mailboxAPI.createDefaultMailbox(
|
||||||
|
session,
|
||||||
|
accountId,
|
||||||
|
mapRoles,
|
||||||
|
);
|
||||||
|
|
||||||
|
final listMailbox = mailboxRecords.$1;
|
||||||
|
final mapErrors = mailboxRecords.$2;
|
||||||
|
|
||||||
|
verify(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
));
|
||||||
|
expect(listMailbox.length, mapRoles.length);
|
||||||
|
expect(mapErrors.isEmpty, isTrue);
|
||||||
|
expect(
|
||||||
|
listMailbox.any((mailbox) => mailbox.name!.name == PresentationMailbox.roleSent.mailboxName),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
listMailbox.any((mailbox) => mailbox.name!.name == PresentationMailbox.roleOutbox.mailboxName),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should return some mailbox list with input is a list roles when create mailbox fail', () async {
|
||||||
|
final mapResponseData = {
|
||||||
|
"methodResponses": [
|
||||||
|
[
|
||||||
|
"Mailbox/set",
|
||||||
|
{
|
||||||
|
"oldState": "105",
|
||||||
|
"newState": "107",
|
||||||
|
"created": {
|
||||||
|
"sent-create-id": {
|
||||||
|
"id": "sent-id",
|
||||||
|
"myRights": {
|
||||||
|
"mayReadItems": true,
|
||||||
|
"mayAddItems": true,
|
||||||
|
"mayRemoveItems": true,
|
||||||
|
"mayCreateChild": true,
|
||||||
|
"mayDelete": true,
|
||||||
|
"maySubmit": true,
|
||||||
|
"maySetSeen": true,
|
||||||
|
"maySetKeywords": true,
|
||||||
|
"mayAdmin": true,
|
||||||
|
"mayRename": true
|
||||||
|
},
|
||||||
|
"totalEmails": 0,
|
||||||
|
"unreadEmails": 0,
|
||||||
|
"totalThreads": 0,
|
||||||
|
"unreadThreads": 0,
|
||||||
|
"isSeenShared": false,
|
||||||
|
"sortOrder": 10,
|
||||||
|
"showAsLabel": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"updated": null,
|
||||||
|
"destroyed": null,
|
||||||
|
"notCreated": {
|
||||||
|
"outbox-create-id": {
|
||||||
|
"type": "invalidProperties",
|
||||||
|
"properties": [
|
||||||
|
"role"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notUpdated": null,
|
||||||
|
"notDestroyed": null,
|
||||||
|
"accountId": accountId.asString,
|
||||||
|
},
|
||||||
|
"c0"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sessionState": "0"
|
||||||
|
};
|
||||||
|
|
||||||
|
when(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
)).thenAnswer((_) async => mapResponseData);
|
||||||
|
|
||||||
|
final mailboxRecords = await mailboxAPI.createDefaultMailbox(
|
||||||
|
session,
|
||||||
|
accountId,
|
||||||
|
mapRoles,
|
||||||
|
);
|
||||||
|
|
||||||
|
final listMailbox = mailboxRecords.$1;
|
||||||
|
final mapErrors = mailboxRecords.$2;
|
||||||
|
|
||||||
|
verify(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(listMailbox.length, lessThan(mapRoles.length));
|
||||||
|
expect(mapErrors.isNotEmpty, isTrue);
|
||||||
|
expect(
|
||||||
|
listMailbox.any((mailbox) => mailbox.name?.name == PresentationMailbox.roleSent.mailboxName),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
listMailbox.every((mailbox) => mailbox.name?.name != PresentationMailbox.roleOutbox.mailboxName),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should throw exception when http client throw exception', () async {
|
||||||
|
when(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
)).thenThrow(Exception());
|
||||||
|
|
||||||
|
expect(
|
||||||
|
() => mailboxAPI.createDefaultMailbox(session, accountId, mapRoles),
|
||||||
|
throwsA(isA<Exception>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('setRoleDefaultMailbox::', () {
|
||||||
|
final listMailbox = <Mailbox>[
|
||||||
|
Mailbox(
|
||||||
|
id: MailboxId(Id('sent-id')),
|
||||||
|
name: MailboxName(PresentationMailbox.roleSent.mailboxName),
|
||||||
|
role: PresentationMailbox.roleSent,
|
||||||
|
isSubscribed: IsSubscribed(true),
|
||||||
|
) ,
|
||||||
|
Mailbox(
|
||||||
|
id: MailboxId(Id('outbox-id')),
|
||||||
|
name: MailboxName(PresentationMailbox.roleOutbox.mailboxName),
|
||||||
|
role: PresentationMailbox.roleOutbox,
|
||||||
|
isSubscribed: IsSubscribed(true),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
test('Should return full mailbox with role when update role mailbox success', () async {
|
||||||
|
final mapResponseData = {
|
||||||
|
"methodResponses": [
|
||||||
|
[
|
||||||
|
"Mailbox/set",
|
||||||
|
{
|
||||||
|
"oldState": "105",
|
||||||
|
"newState": "107",
|
||||||
|
"created": null,
|
||||||
|
"updated": {
|
||||||
|
'sent-id': null,
|
||||||
|
'outbox-id': null
|
||||||
|
},
|
||||||
|
"destroyed": null,
|
||||||
|
"notCreated": null,
|
||||||
|
"notUpdated": null,
|
||||||
|
"notDestroyed": null,
|
||||||
|
"accountId": accountId.asString,
|
||||||
|
},
|
||||||
|
"c0"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sessionState": "0"
|
||||||
|
};
|
||||||
|
|
||||||
|
when(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
)).thenAnswer((_) async => mapResponseData);
|
||||||
|
|
||||||
|
final mailboxRecords = await mailboxAPI.setRoleDefaultMailbox(
|
||||||
|
session,
|
||||||
|
accountId,
|
||||||
|
listMailbox,
|
||||||
|
);
|
||||||
|
|
||||||
|
final newListMailbox = mailboxRecords.$1;
|
||||||
|
final mapErrors = mailboxRecords.$2;
|
||||||
|
|
||||||
|
verify(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
));
|
||||||
|
expect(newListMailbox.length, listMailbox.length);
|
||||||
|
expect(mapErrors.isEmpty, isTrue);
|
||||||
|
expect(
|
||||||
|
newListMailbox.any((mailbox) => mailbox.role == PresentationMailbox.roleSent),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
newListMailbox.any((mailbox) => mailbox.role == PresentationMailbox.roleOutbox),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should return some mailbox with role when update role mailbox fail', () async {
|
||||||
|
final mapResponseData = {
|
||||||
|
"methodResponses": [
|
||||||
|
[
|
||||||
|
"Mailbox/set",
|
||||||
|
{
|
||||||
|
"oldState": "105",
|
||||||
|
"newState": "107",
|
||||||
|
"created": null,
|
||||||
|
"updated": {
|
||||||
|
'sent-id': null
|
||||||
|
},
|
||||||
|
"destroyed": null,
|
||||||
|
"notCreated": null,
|
||||||
|
"notUpdated": {
|
||||||
|
"outbox-id": {
|
||||||
|
"type": "invalidProperties",
|
||||||
|
"properties": [
|
||||||
|
"role"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notDestroyed": null,
|
||||||
|
"accountId": accountId.asString,
|
||||||
|
},
|
||||||
|
"c0"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sessionState": "0"
|
||||||
|
};
|
||||||
|
|
||||||
|
when(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
)).thenAnswer((_) async => mapResponseData);
|
||||||
|
|
||||||
|
final mailboxRecords = await mailboxAPI.setRoleDefaultMailbox(
|
||||||
|
session,
|
||||||
|
accountId,
|
||||||
|
listMailbox,
|
||||||
|
);
|
||||||
|
|
||||||
|
final newListMailbox = mailboxRecords.$1;
|
||||||
|
final mapErrors = mailboxRecords.$2;
|
||||||
|
|
||||||
|
verify(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(newListMailbox.length,listMailbox.length);
|
||||||
|
expect(mapErrors.isNotEmpty, isTrue);
|
||||||
|
expect(
|
||||||
|
newListMailbox.any((mailbox) => mailbox.role == PresentationMailbox.roleSent),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
newListMailbox.every((mailbox) => mailbox.role != PresentationMailbox.roleOutbox),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should throw exception when http client throw exception', () async {
|
||||||
|
when(httpClient.post(
|
||||||
|
'',
|
||||||
|
data: anyNamed('data'),
|
||||||
|
cancelToken: anyNamed('cancelToken'),
|
||||||
|
)).thenThrow(Exception());
|
||||||
|
|
||||||
|
expect(
|
||||||
|
() => mailboxAPI.setRoleDefaultMailbox(session, accountId, listMailbox),
|
||||||
|
throwsA(isA<Exception>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user