Skip to content

Commit 36ff5d1

Browse files
Add CalendarEventCounter/accept method
1 parent 00b8c07 commit 36ff5d1

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
2+
import 'package:jmap_dart_client/http/converter/id_converter.dart';
3+
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
4+
import 'package:jmap_dart_client/jmap/core/method/request/calendar_event_reply_method.dart';
5+
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
6+
import 'package:json_annotation/json_annotation.dart';
7+
8+
part 'calendar_event_counter_accept_method.g.dart';
9+
10+
@JsonSerializable(converters: [
11+
AccountIdConverter(),
12+
IdConverter(),
13+
])
14+
class CalendarEventCounterAcceptMethod extends CalendarEventReplyMethod {
15+
CalendarEventCounterAcceptMethod(super.accountId, {required super.blobIds});
16+
17+
@override
18+
MethodName get methodName => MethodName('CalendarEventCounter/accept');
19+
20+
@override
21+
Set<CapabilityIdentifier> get requiredCapabilities => {
22+
CapabilityIdentifier.jmapCore,
23+
CapabilityIdentifier.jamesCalendarEvent
24+
};
25+
26+
@override
27+
Map<String, dynamic> toJson() => _$CalendarEventCounterAcceptMethodToJson(this);
28+
}

lib/jmap/mail/calendar/reply/calendar_event_counter_accept_method.g.dart

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

0 commit comments

Comments
 (0)