diff --git a/lib/jmap/mail/calendar/reply/calendar_event_reject_method.dart b/lib/jmap/mail/calendar/reply/calendar_event_reject_method.dart new file mode 100644 index 0000000..025776a --- /dev/null +++ b/lib/jmap/mail/calendar/reply/calendar_event_reject_method.dart @@ -0,0 +1,28 @@ +import 'package:jmap_dart_client/http/converter/account_id_converter.dart'; +import 'package:jmap_dart_client/http/converter/id_converter.dart'; +import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; +import 'package:jmap_dart_client/jmap/core/method/request/calendar_event_reply_method.dart'; +import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'calendar_event_reject_method.g.dart'; + +@JsonSerializable(converters: [ + AccountIdConverter(), + IdConverter(), +]) +class CalendarEventRejectMethod extends CalendarEventReplyMethod { + CalendarEventRejectMethod(super.accountId, {required super.blobIds}); + + @override + MethodName get methodName => MethodName('CalendarEvent/reject'); + + @override + Set get requiredCapabilities => { + CapabilityIdentifier.jmapCore, + CapabilityIdentifier.jamesCalendarEvent + }; + + @override + Map toJson() => _$CalendarEventRejectMethodToJson(this); +} \ No newline at end of file diff --git a/lib/jmap/mail/calendar/reply/calendar_event_reject_method.g.dart b/lib/jmap/mail/calendar/reply/calendar_event_reject_method.g.dart new file mode 100644 index 0000000..963ec63 --- /dev/null +++ b/lib/jmap/mail/calendar/reply/calendar_event_reject_method.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'calendar_event_reject_method.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CalendarEventRejectMethod _$CalendarEventRejectMethodFromJson( + Map json) => + CalendarEventRejectMethod( + const AccountIdConverter().fromJson(json['accountId'] as String), + blobIds: (json['blobIds'] as List) + .map((e) => const IdConverter().fromJson(e as String)) + .toList(), + )..language = json['language'] as String?; + +Map _$CalendarEventRejectMethodToJson( + CalendarEventRejectMethod instance) { + final val = { + 'accountId': const AccountIdConverter().toJson(instance.accountId), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('language', instance.language); + val['blobIds'] = instance.blobIds.map(const IdConverter().toJson).toList(); + return val; +} diff --git a/lib/jmap/mail/calendar/reply/calendar_event_reject_response.dart b/lib/jmap/mail/calendar/reply/calendar_event_reject_response.dart new file mode 100644 index 0000000..3314a9b --- /dev/null +++ b/lib/jmap/mail/calendar/reply/calendar_event_reject_response.dart @@ -0,0 +1,29 @@ +import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:jmap_dart_client/jmap/core/method/response/calendar_event_reply_response.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/properties/event_id.dart'; +import 'package:jmap_dart_client/util/json_parsers.dart'; + +class CalendarEventRejectResponse extends CalendarEventReplyResponse { + CalendarEventRejectResponse( + super.accountId, + super.notFound, + { + this.rejected, + this.notRejected + }); + + final List? rejected; + final List? notRejected; + + static CalendarEventRejectResponse deserialize(Map json) { + return CalendarEventRejectResponse( + JsonParsers().parsingAccountId(json), + JsonParsers().parsingListId(json, 'notFound'), + rejected: JsonParsers().parsingListEventId(json, 'rejected'), + notRejected: JsonParsers().parsingListId(json, 'notRejected'), + ); + } + + @override + List get props => [...super.props, rejected, notRejected]; +} \ No newline at end of file diff --git a/test/jmap/mail/calendar/reply/calendar_event_reject_method_test.dart b/test/jmap/mail/calendar/reply/calendar_event_reject_method_test.dart new file mode 100644 index 0000000..5587a0d --- /dev/null +++ b/test/jmap/mail/calendar/reply/calendar_event_reject_method_test.dart @@ -0,0 +1,91 @@ +import 'package:dio/dio.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:http_mock_adapter/http_mock_adapter.dart'; +import 'package:jmap_dart_client/http/http_client.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; +import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:jmap_dart_client/jmap/core/method/request/calendar_event_reply_method.dart'; +import 'package:jmap_dart_client/jmap/core/method/response/calendar_event_reply_response.dart'; +import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart'; +import 'package:jmap_dart_client/jmap/jmap_request.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/properties/event_id.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_reject_method.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_reject_response.dart'; + +void main() { + final baseOption = BaseOptions(method: 'POST'); + final dio = Dio(baseOption)..options.baseUrl = 'http://domain.com/jmap'; + final dioAdapter = DioAdapter(dio: dio); + final dioAdapterHeaders = {"accept": "application/json;jmapVersion=rfc-8621"}; + final httpClient = HttpClient(dio); + final processingInvocation = ProcessingInvocation(); + final requestBuilder = JmapRequestBuilder(httpClient, processingInvocation); + final accountId = AccountId(Id('123abc')); + final successBlobId = Id('abc123'); + final failureBlobId = Id('def456'); + final notFoundBlobId = Id('ghi789'); + final blobIds = [successBlobId, failureBlobId, notFoundBlobId]; + final methodCallId = MethodCallId('c0'); + + Map constructData(CalendarEventReplyMethod method) => { + "using": method.requiredCapabilities + .map((capability) => capability.value.toString()) + .toList(), + "methodCalls": [ + [ + method.methodName.value, + { + "accountId": accountId.id.value, + "blobIds": blobIds.map((id) => id.value).toList(), + }, + methodCallId.value + ] + ] + }; + + Map constructResponse(CalendarEventReplyMethod method) => { + "sessionState": "abcdefghij", + "methodResponses": [[ + method.methodName.value, + { + "accountId": accountId.id.value, + "rejected": [successBlobId.value], + "notRejected": [failureBlobId.value], + "notFound": [notFoundBlobId.value], + }, + methodCallId.value + ]] + }; + + group('calendar event reject method', () { + final method = CalendarEventRejectMethod(accountId, blobIds: blobIds); + + test('should succeed with success blob data, ' + 'and fail with failure blob data ' + 'and not found with not found blob data', () async { + // arrange + final invocation = requestBuilder.invocation(method, methodCallId: methodCallId); + dioAdapter.onPost( + '', + (server) => server.reply(200, constructResponse(method)), + data: constructData(method), + headers: dioAdapterHeaders, + ); + + // act + final response = (await (requestBuilder..usings(method.requiredCapabilities)) + .build() + .execute()) + .parse( + invocation.methodCallId, + CalendarEventRejectResponse.deserialize); + + // assert + expect( + (response as CalendarEventRejectResponse?)?.rejected, + equals([EventId(successBlobId.value)])); + expect(response?.notRejected, equals([failureBlobId])); + expect(response?.notFound, equals([notFoundBlobId])); + }); + }); +} \ No newline at end of file