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/method/request/calendar_event_reply_method.dart' ;
8
+ import 'package:jmap_dart_client/jmap/core/method/response/calendar_event_reply_response.dart' ;
9
+ import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart' ;
10
+ import 'package:jmap_dart_client/jmap/jmap_request.dart' ;
11
+ import 'package:jmap_dart_client/jmap/mail/calendar/properties/event_id.dart' ;
12
+ import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_maybe_method.dart' ;
13
+ import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_maybe_response.dart' ;
14
+
15
+ void main () {
16
+ final baseOption = BaseOptions (method: 'POST' );
17
+ final dio = Dio (baseOption)..options.baseUrl = 'http://domain.com/jmap' ;
18
+ final dioAdapter = DioAdapter (dio: dio);
19
+ final dioAdapterHeaders = {"accept" : "application/json;jmapVersion=rfc-8621" };
20
+ final httpClient = HttpClient (dio);
21
+ final processingInvocation = ProcessingInvocation ();
22
+ final requestBuilder = JmapRequestBuilder (httpClient, processingInvocation);
23
+ final accountId = AccountId (Id ('123abc' ));
24
+ final successBlobId = Id ('abc123' );
25
+ final failureBlobId = Id ('def456' );
26
+ final notFoundBlobId = Id ('ghi789' );
27
+ final blobIds = [successBlobId, failureBlobId, notFoundBlobId];
28
+ final methodCallId = MethodCallId ('c0' );
29
+
30
+ Map <String , dynamic > constructData (CalendarEventReplyMethod method) => {
31
+ "using" : method.requiredCapabilities
32
+ .map ((capability) => capability.value.toString ())
33
+ .toList (),
34
+ "methodCalls" : [
35
+ [
36
+ method.methodName.value,
37
+ {
38
+ "accountId" : accountId.id.value,
39
+ "blobIds" : blobIds.map ((id) => id.value).toList (),
40
+ },
41
+ methodCallId.value
42
+ ]
43
+ ]
44
+ };
45
+
46
+ Map <String , dynamic > constructResponse (CalendarEventReplyMethod method) => {
47
+ "sessionState" : "abcdefghij" ,
48
+ "methodResponses" : [[
49
+ method.methodName.value,
50
+ {
51
+ "accountId" : accountId.id.value,
52
+ "maybe" : [successBlobId.value],
53
+ "notMaybe" : [failureBlobId.value],
54
+ "notFound" : [notFoundBlobId.value],
55
+ },
56
+ methodCallId.value
57
+ ]]
58
+ };
59
+
60
+ group ('calendar event maybe method' , () {
61
+ final method = CalendarEventMaybeMethod (accountId, blobIds: blobIds);
62
+
63
+ test ('should succeed with success blob data, '
64
+ 'and fail with failure blob data '
65
+ 'and not found with not found blob data' , () async {
66
+ // arrange
67
+ final invocation = requestBuilder.invocation (method, methodCallId: methodCallId);
68
+ dioAdapter.onPost (
69
+ '' ,
70
+ (server) => server.reply (200 , constructResponse (method)),
71
+ data: constructData (method),
72
+ headers: dioAdapterHeaders,
73
+ );
74
+
75
+ // act
76
+ final response = (await (requestBuilder..usings (method.requiredCapabilities))
77
+ .build ()
78
+ .execute ())
79
+ .parse <CalendarEventReplyResponse >(
80
+ invocation.methodCallId,
81
+ CalendarEventMaybeResponse .deserialize);
82
+
83
+ // assert
84
+ expect (
85
+ (response as CalendarEventMaybeResponse ? )? .maybe,
86
+ equals ([EventId (successBlobId.value)]));
87
+ expect (response? .notMaybe, equals ([failureBlobId]));
88
+ expect (response? .notFound, equals ([notFoundBlobId]));
89
+ });
90
+ });
91
+ }
0 commit comments