TF-3370 Handle SetError when make email action (Mark as read/star/move/delete)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:core/data/network/dio_client.dart';
|
||||
import 'package:core/data/network/download/download_manager.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -60,7 +59,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 50;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -102,16 +101,16 @@ void main() {
|
||||
]
|
||||
});
|
||||
|
||||
final emails = List.generate(
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => Email(id: EmailId(Id('email_$index'))),
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.markAsRead(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emails,
|
||||
emailIds,
|
||||
ReadActions.markAsRead,
|
||||
);
|
||||
|
||||
@@ -121,7 +120,8 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
@@ -133,7 +133,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 200;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -175,16 +175,16 @@ void main() {
|
||||
]
|
||||
});
|
||||
|
||||
final emails = List.generate(
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => Email(id: EmailId(Id('email_$index'))),
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.markAsRead(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emails,
|
||||
emailIds,
|
||||
ReadActions.markAsRead,
|
||||
);
|
||||
|
||||
@@ -194,7 +194,8 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
@@ -206,7 +207,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 20;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -248,16 +249,16 @@ void main() {
|
||||
]
|
||||
});
|
||||
|
||||
final emails = List.generate(
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => Email(id: EmailId(Id('email_$index'))),
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.markAsRead(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emails,
|
||||
emailIds,
|
||||
ReadActions.markAsRead,
|
||||
);
|
||||
|
||||
@@ -267,7 +268,83 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'SHOULD calls execute the correct number of times\n'
|
||||
'WHEN totalEmails is less than defaultMaxObjectsInSet\n'
|
||||
'WHEN maxObjectsInSet equal defaultMaxObjectsInSet\n'
|
||||
'AND defaultMaxObjectsInSet is 50',
|
||||
() async {
|
||||
// Arrange
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 50;
|
||||
const totalEmails = 30;
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
when(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).thenAnswer((_) async => {
|
||||
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
|
||||
"methodResponses": [
|
||||
[
|
||||
"Email/set",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"oldState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"newState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"updated": {
|
||||
for (var item in List.generate(maxBatches, (index) => {"email_$index": null}))
|
||||
item.keys.first: item.values.first
|
||||
}
|
||||
},
|
||||
"c0"
|
||||
],
|
||||
[
|
||||
"Email/get",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"state": "b965db40-c11c-11ef-9cfb-ef2eae0e64b1",
|
||||
"list": List.generate(maxBatches, (index) => {
|
||||
"id": "email_$index",
|
||||
"keywords": {
|
||||
"\$seen": true
|
||||
}
|
||||
}),
|
||||
"notFound": []
|
||||
},
|
||||
"c1"
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.markAsRead(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emailIds,
|
||||
ReadActions.markAsRead,
|
||||
);
|
||||
|
||||
// Assert
|
||||
verify(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -281,7 +358,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 50;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -323,16 +400,16 @@ void main() {
|
||||
]
|
||||
});
|
||||
|
||||
final emails = List.generate(
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => Email(id: EmailId(Id('email_$index'))),
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.markAsStar(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emails,
|
||||
emailIds,
|
||||
MarkStarAction.markStar,
|
||||
);
|
||||
|
||||
@@ -342,7 +419,8 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
@@ -354,7 +432,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 200;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -396,16 +474,16 @@ void main() {
|
||||
]
|
||||
});
|
||||
|
||||
final emails = List.generate(
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => Email(id: EmailId(Id('email_$index'))),
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.markAsStar(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emails,
|
||||
emailIds,
|
||||
MarkStarAction.markStar,
|
||||
);
|
||||
|
||||
@@ -415,7 +493,8 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
@@ -427,7 +506,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 20;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -469,16 +548,16 @@ void main() {
|
||||
]
|
||||
});
|
||||
|
||||
final emails = List.generate(
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => Email(id: EmailId(Id('email_$index'))),
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.markAsStar(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emails,
|
||||
emailIds,
|
||||
MarkStarAction.markStar,
|
||||
);
|
||||
|
||||
@@ -488,7 +567,306 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'SHOULD calls execute the correct number of times\n'
|
||||
'WHEN totalEmails is less than defaultMaxObjectsInSet\n'
|
||||
'WHEN maxObjectsInSet equal defaultMaxObjectsInSet\n'
|
||||
'AND defaultMaxObjectsInSet is 50',
|
||||
() async {
|
||||
// Arrange
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 50;
|
||||
const totalEmails = 30;
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
when(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).thenAnswer((_) async => {
|
||||
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
|
||||
"methodResponses": [
|
||||
[
|
||||
"Email/set",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"oldState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"newState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"updated": {
|
||||
for (var item in List.generate(maxBatches, (index) => {"email_$index": null}))
|
||||
item.keys.first: item.values.first
|
||||
}
|
||||
},
|
||||
"c0"
|
||||
],
|
||||
[
|
||||
"Email/get",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"state": "b965db40-c11c-11ef-9cfb-ef2eae0e64b1",
|
||||
"list": List.generate(maxBatches, (index) => {
|
||||
"id": "email_$index",
|
||||
"keywords": {
|
||||
"\$flagged": true
|
||||
}
|
||||
}),
|
||||
"notFound": []
|
||||
},
|
||||
"c1"
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.markAsStar(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emailIds,
|
||||
MarkStarAction.markStar,
|
||||
);
|
||||
|
||||
// Assert
|
||||
verify(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('deleteMultipleEmailsPermanently::test', () {
|
||||
test(
|
||||
'SHOULD calls execute the correct number of times\n'
|
||||
'WHEN maxObjectsInSet equal defaultMaxObjectsInSet\n'
|
||||
'AND defaultMaxObjectsInSet is 50',
|
||||
() async {
|
||||
// Arrange
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 50;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
when(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).thenAnswer((_) async => {
|
||||
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
|
||||
"methodResponses": [
|
||||
[
|
||||
"Email/set",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"oldState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"newState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"destroyed": List.generate(maxBatches, (index) => "email_$index")
|
||||
},
|
||||
"c0"
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.deleteMultipleEmailsPermanently(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emailIds,
|
||||
);
|
||||
|
||||
// Assert
|
||||
verify(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'SHOULD calls execute the correct number of times\n'
|
||||
'WHEN maxObjectsInSet is greater than defaultMaxObjectsInSet\n'
|
||||
'AND defaultMaxObjectsInSet is 50',
|
||||
() async {
|
||||
// Arrange
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 200;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
when(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).thenAnswer((_) async => {
|
||||
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
|
||||
"methodResponses": [
|
||||
[
|
||||
"Email/set",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"oldState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"newState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"destroyed": List.generate(maxBatches, (index) => "email_$index")
|
||||
},
|
||||
"c0"
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.deleteMultipleEmailsPermanently(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emailIds,
|
||||
);
|
||||
|
||||
// Assert
|
||||
verify(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'SHOULD calls execute the correct number of times\n'
|
||||
'WHEN maxObjectsInSet is less than defaultMaxObjectsInSet\n'
|
||||
'AND defaultMaxObjectsInSet is 50',
|
||||
() async {
|
||||
// Arrange
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 20;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
when(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).thenAnswer((_) async => {
|
||||
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
|
||||
"methodResponses": [
|
||||
[
|
||||
"Email/set",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"oldState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"newState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"destroyed": List.generate(maxBatches, (index) => "email_$index")
|
||||
},
|
||||
"c0"
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.deleteMultipleEmailsPermanently(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emailIds,
|
||||
);
|
||||
|
||||
// Assert
|
||||
verify(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'SHOULD calls execute the correct number of times\n'
|
||||
'WHEN totalEmails is less than defaultMaxObjectsInSet\n'
|
||||
'WHEN maxObjectsInSet equal defaultMaxObjectsInSet\n'
|
||||
'AND defaultMaxObjectsInSet is 50',
|
||||
() async {
|
||||
// Arrange
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 50;
|
||||
const totalEmails = 30;
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
when(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).thenAnswer((_) async => {
|
||||
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
|
||||
"methodResponses": [
|
||||
[
|
||||
"Email/set",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"oldState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"newState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"destroyed": List.generate(maxBatches, (index) => "email_$index")
|
||||
},
|
||||
"c0"
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.deleteMultipleEmailsPermanently(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emailIds,
|
||||
);
|
||||
|
||||
// Assert
|
||||
verify(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -502,7 +880,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 50;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -554,7 +932,8 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
@@ -566,7 +945,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 200;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -618,7 +997,8 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
@@ -630,7 +1010,7 @@ void main() {
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 20;
|
||||
const totalEmails = 100;
|
||||
final maxBatches = min(maxObjectsInSet, defaultMaxObjectsInSet);
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
@@ -682,7 +1062,74 @@ void main() {
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.length, totalEmails);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'SHOULD calls execute the correct number of times\n'
|
||||
'WHEN totalEmails is less than defaultMaxObjectsInSet\n'
|
||||
'WHEN maxObjectsInSet equal defaultMaxObjectsInSet\n'
|
||||
'AND defaultMaxObjectsInSet is 50',
|
||||
() async {
|
||||
// Arrange
|
||||
const defaultMaxObjectsInSet = 50;
|
||||
const maxObjectsInSet = 50;
|
||||
const totalEmails = 30;
|
||||
final maxBatches = [maxObjectsInSet, defaultMaxObjectsInSet, totalEmails].min;
|
||||
final countIterations = (totalEmails / maxBatches).ceil();
|
||||
final aliceSession = SessionFixtures.getAliceSessionWithMaxObjectsInSet(maxObjectsInSet);
|
||||
|
||||
when(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).thenAnswer((_) async => {
|
||||
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
|
||||
"methodResponses": [
|
||||
[
|
||||
"Email/set",
|
||||
{
|
||||
"accountId": AccountFixtures.aliceAccountId.asString,
|
||||
"oldState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"newState": "4cb1e760-c11b-11ef-9cfb-ef2eae0e64b1",
|
||||
"updated": {
|
||||
for (var item in List.generate(maxBatches, (index) => {"email_$index": null}))
|
||||
item.keys.first: item.values.first
|
||||
}
|
||||
},
|
||||
"c0"
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
final emailIds = List.generate(
|
||||
totalEmails,
|
||||
(index) => EmailId(Id('email_$index')),
|
||||
);
|
||||
|
||||
// Act
|
||||
final result = await emailApi.moveToMailbox(
|
||||
aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
MoveToMailboxRequest(
|
||||
{
|
||||
MailboxId(Id('mailboxA')): emailIds,
|
||||
},
|
||||
MailboxId(Id('mailboxB')),
|
||||
MoveAction.moving,
|
||||
EmailActionType.moveToMailbox,
|
||||
),
|
||||
);
|
||||
|
||||
// Assert
|
||||
verify(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).called(countIterations);
|
||||
expect(result.emailIdsSuccess.length, totalEmails);
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user