Skip to content

Commit

Permalink
Create CalendarEvent reject method
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora authored and hoangdat committed May 6, 2024
1 parent b0aa4d5 commit 76e83e4
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/jmap/mail/calendar/reply/calendar_event_reject_method.dart
Original file line number Diff line number Diff line change
@@ -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<CapabilityIdentifier> get requiredCapabilities => {
CapabilityIdentifier.jmapCore,
CapabilityIdentifier.jamesCalendarEvent
};

@override
Map<String, dynamic> toJson() => _$CalendarEventRejectMethodToJson(this);
}
33 changes: 33 additions & 0 deletions lib/jmap/mail/calendar/reply/calendar_event_reject_method.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions lib/jmap/mail/calendar/reply/calendar_event_reject_response.dart
Original file line number Diff line number Diff line change
@@ -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<EventId>? rejected;
final List<Id>? notRejected;

static CalendarEventRejectResponse deserialize(Map<String, dynamic> json) {
return CalendarEventRejectResponse(
JsonParsers().parsingAccountId(json),
JsonParsers().parsingListId(json, 'notFound'),
rejected: JsonParsers().parsingListEventId(json, 'rejected'),
notRejected: JsonParsers().parsingListId(json, 'notRejected'),
);
}

@override
List<Object?> get props => [...super.props, rejected, notRejected];
}
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> 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<String, dynamic> 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<CalendarEventReplyResponse>(
invocation.methodCallId,
CalendarEventRejectResponse.deserialize);

// assert
expect(
(response as CalendarEventRejectResponse?)?.rejected,
equals([EventId(successBlobId.value)]));
expect(response?.notRejected, equals([failureBlobId]));
expect(response?.notFound, equals([notFoundBlobId]));
});
});
}

0 comments on commit 76e83e4

Please sign in to comment.