Skip to content

Commit ab07a8a

Browse files
sherlockvnhoangdat
authored andcommitted
add test for add header mdn
1 parent 02fcc9d commit ab07a8a

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

test/jmap/email/set/set_email_method_test.dart

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,121 @@ void main() {
261261

262262
expect(setEmailResponse!.created![Id('aa1234')], equals(expectedCreated));
263263
});
264+
265+
test('set email method and response parsing with header Mdn', () async {
266+
final baseOption = BaseOptions(method: 'POST');
267+
final dio = Dio(baseOption)
268+
..options.baseUrl = 'http://domain.com/jmap';
269+
final dioAdapter = DioAdapter(dio: dio);
270+
dioAdapter.onPost(
271+
'',
272+
(server) => server.reply(200, {
273+
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
274+
"methodResponses": [
275+
[
276+
"Email/set",
277+
{
278+
"accountId": "587a9c5a4a9c0a4d36243b7417700d5383cbbfa25f0909ab7f6f4baaa5bf4e9b",
279+
"oldState": "24152b20-4ab0-11ed-88ee-ffc86e0cde67",
280+
"newState": "24152b20-4ab0-11ed-88ee-ffc86e0cde67",
281+
"created": {
282+
"e01": {
283+
"id": "77664010-4ab1-11ed-88ee-ffc86e0cde67",
284+
"blobId": "77664010-4ab1-11ed-88ee-ffc86e0cde67",
285+
"threadId": "77664010-4ab1-11ed-88ee-ffc86e0cde67",
286+
"size": 600
287+
}
288+
}
289+
},
290+
"c0"
291+
]
292+
]
293+
}),
294+
data: {
295+
"using": [
296+
"urn:ietf:params:jmap:mail",
297+
"urn:ietf:params:jmap:core"
298+
],
299+
"methodCalls": [
300+
[
301+
"Email/set",
302+
{
303+
"accountId":
304+
"587a9c5a4a9c0a4d36243b7417700d5383cbbfa25f0909ab7f6f4baaa5bf4e9b",
305+
"create": {
306+
"e01": {
307+
"id": "e102",
308+
"mailboxIds": {
309+
"a6f488c0-964b-11ec-83d6-c1ded34233a9": true
310+
},
311+
"subject": "[POSTMAN] SEND EMAIL WITH MDN MDN MDN",
312+
"from": [
313+
{
314+
"name": "[email protected]",
315+
"email": "[email protected]"
316+
}
317+
],
318+
"htmlBody": [
319+
{"partId": "abc123", "type": "text/html"}
320+
],
321+
"bodyValues": {
322+
"abc123": {
323+
"value": "[POSTMAN] SEND EMAIL WITH MDN",
324+
"isEncodingProblem": false,
325+
"isTruncated": false
326+
}
327+
},
328+
"header:Disposition-Notification-To:asText": "[email protected]"
329+
}
330+
}
331+
},
332+
"c0"
333+
]
334+
]
335+
},
336+
headers: {
337+
"accept": "application/json;jmapVersion=rfc-8621",
338+
"content-type": "application/json; charset=utf-8",
339+
"content-length": 617
340+
}
341+
);
342+
343+
final setEmailMethod = SetEmailMethod(AccountId(Id('587a9c5a4a9c0a4d36243b7417700d5383cbbfa25f0909ab7f6f4baaa5bf4e9b')))
344+
..addCreate(Id('e01'),
345+
Email(
346+
EmailId(Id('e102')),
347+
mailboxIds: {
348+
MailboxId(Id('a6f488c0-964b-11ec-83d6-c1ded34233a9')): true
349+
},
350+
from: {EmailAddress('[email protected]', '[email protected]')},
351+
subject: '[POSTMAN] SEND EMAIL WITH MDN MDN MDN',
352+
htmlBody: {EmailBodyPart(partId: PartId('abc123'), type: MediaType.parse('text/html'))},
353+
bodyValues: {
354+
PartId('abc123'): EmailBodyValue('[POSTMAN] SEND EMAIL WITH MDN', false, false)
355+
},
356+
headerMdn: {IndividualHeaderIdentifier.headerMdn : "[email protected]"}
357+
)
358+
);
359+
360+
final httpClient = HttpClient(dio);
361+
final requestBuilder = JmapRequestBuilder(httpClient, ProcessingInvocation());
362+
final setEmailInvocation = requestBuilder.invocation(setEmailMethod);
363+
final response = await (requestBuilder..usings(setEmailMethod.requiredCapabilities))
364+
.build()
365+
.execute();
366+
367+
final setEmailResponse = response.parse<SetEmailResponse>(
368+
setEmailInvocation.methodCallId,
369+
SetEmailResponse.deserialize);
370+
371+
final expectedCreated1 = Email(
372+
EmailId(Id("77664010-4ab1-11ed-88ee-ffc86e0cde67")),
373+
blobId: Id("77664010-4ab1-11ed-88ee-ffc86e0cde67"),
374+
threadId: ThreadId(Id("77664010-4ab1-11ed-88ee-ffc86e0cde67")),
375+
size: UnsignedInt(600),
376+
);
377+
378+
expect(setEmailResponse!.created![Id('e01')], equals(expectedCreated1));
379+
});
264380
});
265381
}

0 commit comments

Comments
 (0)