Skip to content

Commit a8b8f87

Browse files
ManhNTManhNT
authored andcommitted
TF-626: create unit test for test case get changes mailbox
1 parent e64a81a commit a8b8f87

File tree

2 files changed

+228
-18
lines changed

2 files changed

+228
-18
lines changed

lib/jmap/mail/mailbox/get/get_mailbox_method.g.dart

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
import 'package:dio/dio.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:http_mock_adapter/http_mock_adapter.dart';
4+
import 'package:jmap_dart_client/http/http_client.dart';
5+
import 'package:jmap_dart_client/jmap/account_id.dart';
6+
import 'package:jmap_dart_client/jmap/core/id.dart';
7+
import 'package:jmap_dart_client/jmap/core/request/reference_path.dart';
8+
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
9+
import 'package:jmap_dart_client/jmap/core/state.dart';
10+
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
11+
import 'package:jmap_dart_client/jmap/jmap_request.dart';
12+
import 'package:jmap_dart_client/jmap/mail/mailbox/changes/changes_mailbox_method.dart';
13+
import 'package:jmap_dart_client/jmap/mail/mailbox/get/get_mailbox_method.dart';
14+
import 'package:jmap_dart_client/jmap/mail/mailbox/get/get_mailbox_response.dart';
15+
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
16+
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_rights.dart';
17+
18+
void main() {
19+
group('[MailBox/changes]', () {
20+
final expectedUpdated = Mailbox(
21+
id: MailboxId(Id('c2543650-32cf-11eb-995c-a3ae66e9f96a')),
22+
role: Role('inbox'),
23+
name: MailboxName('INBOX'),
24+
sortOrder: SortOrder(sortValue: 10),
25+
totalEmails: TotalEmails(UnsignedInt(4079)),
26+
unreadEmails: UnreadEmails(UnsignedInt(10)),
27+
totalThreads: TotalThreads(UnsignedInt(4079)),
28+
unreadThreads: UnreadThreads(UnsignedInt(10)),
29+
myRights: MailboxRights(
30+
true,
31+
true,
32+
true,
33+
true,
34+
true,
35+
true,
36+
true,
37+
true,
38+
true,
39+
),
40+
isSubscribed: IsSubscribed(true),
41+
);
42+
43+
test('get changes email', () async {
44+
final baseOption = BaseOptions(method: 'POST');
45+
final dio = Dio(baseOption)..options.baseUrl = 'http://domain.com';
46+
final dioAdapter = DioAdapter(dio: dio);
47+
dioAdapter.onPost(
48+
'/jmap',
49+
(server) => server.reply(200, {
50+
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
51+
"methodResponses": [
52+
[
53+
"Mailbox/changes",
54+
{
55+
"accountId":
56+
"0eacc7a5c74b27ab36a823bc5c34da36e16c093705f241d6ed5f48ee73a4ecfb",
57+
"oldState": "94bbff21-e87c-11ec-aae4-43ebf0340ebd",
58+
"newState": "4a523070-eb89-11ec-aae4-43ebf0340ebd",
59+
"hasMoreChanges": false,
60+
"updatedProperties": null,
61+
"created": [],
62+
"updated": ["c2543650-32cf-11eb-995c-a3ae66e9f96a"],
63+
"destroyed": ["7dc7cb50-3f63-11eb-bf20-f1a8da6866c8"]
64+
},
65+
"c0"
66+
],
67+
[
68+
"Mailbox/get",
69+
{
70+
"accountId":
71+
"0eacc7a5c74b27ab36a823bc5c34da36e16c093705f241d6ed5f48ee73a4ecfb",
72+
"notFound": [],
73+
"state": "4a523070-eb89-11ec-aae4-43ebf0340ebd",
74+
"list": [
75+
{
76+
"id": "c2543650-32cf-11eb-995c-a3ae66e9f96a",
77+
"name": "INBOX",
78+
"role": "inbox",
79+
"sortOrder": 10,
80+
"totalEmails": 4079,
81+
"unreadEmails": 10,
82+
"totalThreads": 4079,
83+
"unreadThreads": 10,
84+
"myRights": {
85+
"mayReadItems": true,
86+
"mayAddItems": true,
87+
"mayRemoveItems": true,
88+
"maySetSeen": true,
89+
"maySetKeywords": true,
90+
"mayCreateChild": true,
91+
"mayRename": true,
92+
"mayDelete": true,
93+
"maySubmit": true
94+
},
95+
"isSubscribed": true
96+
}
97+
]
98+
},
99+
"c1"
100+
],
101+
[
102+
"Mailbox/get",
103+
{
104+
"accountId":
105+
"0eacc7a5c74b27ab36a823bc5c34da36e16c093705f241d6ed5f48ee73a4ecfb",
106+
"notFound": ["7dc7cb50-3f63-11eb-bf20-f1a8da6866c8"],
107+
"state": "4a523070-eb89-11ec-aae4-43ebf0340ebd",
108+
"list": []
109+
},
110+
"c2"
111+
]
112+
]
113+
}),
114+
data: {
115+
"using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
116+
"methodCalls": [
117+
[
118+
"Mailbox/changes",
119+
{
120+
"accountId":
121+
"0eacc7a5c74b27ab36a823bc5c34da36e16c093705f241d6ed5f48ee73a4ecfb",
122+
"sinceState": "94bbff21-e87c-11ec-aae4-43ebf0340ebd"
123+
},
124+
"c0"
125+
],
126+
[
127+
"Mailbox/get",
128+
{
129+
"accountId":
130+
"0eacc7a5c74b27ab36a823bc5c34da36e16c093705f241d6ed5f48ee73a4ecfb",
131+
"#ids": {
132+
"resultOf": "c0",
133+
"name": "Mailbox/changes",
134+
"path": "updated/*"
135+
}
136+
},
137+
"c1"
138+
],
139+
[
140+
"Mailbox/get",
141+
{
142+
"accountId": "0eacc7a5c74b27ab36a823bc5c34da36e16c093705f241d6ed5f48ee73a4ecfb",
143+
"#ids": {
144+
"resultOf": "c0",
145+
"name": "Mailbox/changes",
146+
"path": "destroyed/*"
147+
}
148+
},
149+
"c2"
150+
]
151+
]
152+
},
153+
headers: {
154+
"accept": "application/json;jmapVersion=rfc-8621",
155+
"content-type": "application/json; charset=utf-8",
156+
"content-length": 585
157+
});
158+
159+
final HttpClient httpClient = HttpClient(dio);
160+
final processingInvocation = ProcessingInvocation();
161+
final jmapRequestBuilder =
162+
JmapRequestBuilder(httpClient, processingInvocation);
163+
final accountId = AccountId(Id(
164+
'0eacc7a5c74b27ab36a823bc5c34da36e16c093705f241d6ed5f48ee73a4ecfb'));
165+
final state = State('94bbff21-e87c-11ec-aae4-43ebf0340ebd');
166+
167+
final changesMailboxMethod = ChangesMailboxMethod(accountId, state);
168+
final changesMailboxInvocation = jmapRequestBuilder.invocation(
169+
changesMailboxMethod,
170+
methodCallId: MethodCallId('c0'),
171+
);
172+
173+
final getMailboxMethodForUpdate = GetMailboxMethod(accountId)
174+
..addReferenceIds(processingInvocation.createResultReference(
175+
changesMailboxInvocation.methodCallId,
176+
ReferencePath.updatedPath,
177+
));
178+
179+
final getMailboxForUpdateInvocation = jmapRequestBuilder.invocation(
180+
getMailboxMethodForUpdate,
181+
methodCallId: MethodCallId('c1'));
182+
183+
final getMailboxMethodForDestroyed = GetMailboxMethod(accountId)
184+
..addReferenceIds(processingInvocation.createResultReference(
185+
changesMailboxInvocation.methodCallId,
186+
ReferencePath('destroyed/*'),
187+
));
188+
final getMailboxForDestroyInvocation = jmapRequestBuilder.invocation(
189+
getMailboxMethodForDestroyed,
190+
methodCallId: MethodCallId('c2'),
191+
);
192+
193+
final result = await (jmapRequestBuilder
194+
..usings(getMailboxMethodForUpdate.requiredCapabilities))
195+
.build()
196+
.execute();
197+
198+
final resultUpdated = result.parse<GetMailboxResponse>(
199+
getMailboxForUpdateInvocation.methodCallId,
200+
GetMailboxResponse.deserialize);
201+
202+
final resultDestroyed = result.parse<GetMailboxResponse>(
203+
getMailboxForDestroyInvocation.methodCallId,
204+
GetMailboxResponse.deserialize);
205+
206+
expect(resultUpdated!.list[0], equals(expectedUpdated));
207+
expect(resultDestroyed!.list.length, equals(0));
208+
});
209+
});
210+
}

0 commit comments

Comments
 (0)