TF-2100 Add email_recovery_action/set method and response and unit test
(cherry picked from commit c2d37183c4f0fa9f11e2588df8a8ccb032e9d0b4)
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
import 'package:email_recovery/email_recovery/capability_deleted_messages_vault.dart';
|
||||||
|
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||||
|
import 'package:jmap_dart_client/http/converter/id_converter.dart';
|
||||||
|
import 'package:jmap_dart_client/http/converter/set/set_method_properties_converter.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/method/request/set_method.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
|
||||||
|
|
||||||
|
class SetEmailRecoveryActionMethod extends SetMethodNoNeedAccountId<EmailRecoveryAction> with OptionalCreate<EmailRecoveryAction> {
|
||||||
|
SetEmailRecoveryActionMethod() : super();
|
||||||
|
|
||||||
|
@override
|
||||||
|
MethodName get methodName => MethodName('EmailRecoveryAction/set');
|
||||||
|
|
||||||
|
@override
|
||||||
|
Set<CapabilityIdentifier> get requiredCapabilities => {
|
||||||
|
CapabilityIdentifier.jmapCore,
|
||||||
|
capabilityDeletedMessagesVault,
|
||||||
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final val = <String, dynamic>{};
|
||||||
|
|
||||||
|
void writeNotNull(String key, dynamic value) {
|
||||||
|
if (value != null) {
|
||||||
|
val[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeNotNull('create', create
|
||||||
|
?.map((id, create) => SetMethodPropertiesConverter().fromMapIdToJson(id, create.toJson())));
|
||||||
|
writeNotNull('update', update
|
||||||
|
?.map((id, update) => SetMethodPropertiesConverter().fromMapIdToJson(id, update.toJson())));
|
||||||
|
writeNotNull('destroy', destroy
|
||||||
|
?.map((destroyId) => const IdConverter().toJson(destroyId)).toList());
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [create, update, destroy];
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||||
|
import 'package:jmap_dart_client/http/converter/id_converter.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/error/set_error.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/method/response/set_response.dart';
|
||||||
|
|
||||||
|
class SetEmailRecoveryActionResponse extends SetResponseNoAccount<EmailRecoveryAction> {
|
||||||
|
SetEmailRecoveryActionResponse({
|
||||||
|
Map<Id, EmailRecoveryAction>? created,
|
||||||
|
Map<Id, EmailRecoveryAction?>? updated,
|
||||||
|
Set<Id>? destroyed,
|
||||||
|
Map<Id, SetError>? notCreated,
|
||||||
|
Map<Id, SetError>? notUpdated,
|
||||||
|
Map<Id, SetError>? notDestroyed
|
||||||
|
}) : super(
|
||||||
|
created: created,
|
||||||
|
updated: updated,
|
||||||
|
destroyed: destroyed,
|
||||||
|
notCreated: notCreated,
|
||||||
|
notUpdated: notUpdated,
|
||||||
|
notDestroyed: notDestroyed
|
||||||
|
);
|
||||||
|
|
||||||
|
static SetEmailRecoveryActionResponse deserialize(Map<String, dynamic> json) {
|
||||||
|
return SetEmailRecoveryActionResponse(
|
||||||
|
created: (json['created'] as Map<String, dynamic>?)?.map((key, value) => MapEntry(
|
||||||
|
const IdConverter().fromJson(key),
|
||||||
|
EmailRecoveryAction.fromJson(value as Map<String, dynamic>)
|
||||||
|
)),
|
||||||
|
updated: (json['updated'] as Map<String, dynamic>?)?.map((key, value) => MapEntry(
|
||||||
|
const IdConverter().fromJson(key),
|
||||||
|
value != null ? EmailRecoveryAction.fromJson(value as Map<String, dynamic>) : null
|
||||||
|
)),
|
||||||
|
destroyed: (json['destroyed'] as List<dynamic>?)?.map((id) => const IdConverter().fromJson(id)).toSet(),
|
||||||
|
notCreated: (json['notCreated'] as Map<String, dynamic>?)?.map((key, value) => MapEntry(
|
||||||
|
const IdConverter().fromJson(key),
|
||||||
|
SetError.fromJson(value)
|
||||||
|
)),
|
||||||
|
notUpdated: (json['notUpdated'] as Map<String, dynamic>?)?.map((key, value) => MapEntry(
|
||||||
|
const IdConverter().fromJson(key),
|
||||||
|
SetError.fromJson(value)
|
||||||
|
)),
|
||||||
|
notDestroyed: (json['notDestroyed'] as Map<String, dynamic>?)?.map((key, value) => MapEntry(
|
||||||
|
const IdConverter().fromJson(key),
|
||||||
|
SetError.fromJson(value)
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
created,
|
||||||
|
updated,
|
||||||
|
destroyed,
|
||||||
|
notCreated,
|
||||||
|
notUpdated,
|
||||||
|
notDestroyed
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||||
|
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
|
||||||
|
import 'package:email_recovery/email_recovery/set/set_email_recovery_action_method.dart';
|
||||||
|
import 'package:email_recovery/email_recovery/set/set_email_recovery_action_response.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/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/jmap_request.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('test to json email recovery action set method', () {
|
||||||
|
final expectEmailRecoveryAction = EmailRecoveryAction(
|
||||||
|
id: EmailRecoveryActionId(Id('2034-495-05857-57abcd-0876664'))
|
||||||
|
);
|
||||||
|
|
||||||
|
test('email recovery action set method and response parsing', () async {
|
||||||
|
final baseOption = BaseOptions(method: 'POST');
|
||||||
|
final dio = Dio(baseOption)..options.baseUrl = 'http://domain.com/jmap';
|
||||||
|
final dioAdapter = DioAdapter(dio: dio);
|
||||||
|
dioAdapter.onPost(
|
||||||
|
'',
|
||||||
|
(server) => server.reply(200, {
|
||||||
|
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
|
||||||
|
"methodResponses": [
|
||||||
|
[
|
||||||
|
"EmailRecoveryAction/set",
|
||||||
|
{
|
||||||
|
"created": {
|
||||||
|
"hieubt": {
|
||||||
|
"id": "2034-495-05857-57abcd-0876664"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"c0"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
data: {
|
||||||
|
"using": [
|
||||||
|
"urn:ietf:params:jmap:core",
|
||||||
|
"com:linagora:params:jmap:messages:vault"
|
||||||
|
],
|
||||||
|
"methodCalls": [
|
||||||
|
[
|
||||||
|
"EmailRecoveryAction/set",
|
||||||
|
{
|
||||||
|
"create": {
|
||||||
|
"hieubt": {
|
||||||
|
"deletedBefore": "2023-02-09T10:00:00.000Z",
|
||||||
|
"deletedAfter": "2023-02-09T09:00:00.000Z",
|
||||||
|
"receivedBefore": "2023-02-09T10:00:00.000Z",
|
||||||
|
"receivedAfter": "2023-02-09T09:00:00.000Z",
|
||||||
|
"hasAttachment": "true",
|
||||||
|
"subject": "Simple topic",
|
||||||
|
"sender": "bob@domain.tld",
|
||||||
|
"recipients": ["alice@domain.tld"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"c0"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
"accept": "application/json;jmapVersion=rfc-8621",
|
||||||
|
"content-length": 868
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
final createRequestId = Id('hieubt');
|
||||||
|
|
||||||
|
final emailRecoveryActionSetMethod = SetEmailRecoveryActionMethod()
|
||||||
|
..addCreate(
|
||||||
|
createRequestId,
|
||||||
|
EmailRecoveryAction(
|
||||||
|
deletedBefore: UTCDate(DateTime.parse('2023-02-09T10:00:00')),
|
||||||
|
deletedAfter: UTCDate(DateTime.parse('2023-02-09T09:00:00')),
|
||||||
|
receivedBefore: UTCDate(DateTime.parse('2023-02-09T10:00:00')),
|
||||||
|
receivedAfter: UTCDate(DateTime.parse('2023-02-09T09:00:00')),
|
||||||
|
hasAttachment: true,
|
||||||
|
subject: 'Simple topic',
|
||||||
|
sender: 'bob@domain.tld',
|
||||||
|
recipients: ['alice@domain.tld']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final httpClient = HttpClient(dio);
|
||||||
|
final requestBuilder = JmapRequestBuilder(httpClient, ProcessingInvocation());
|
||||||
|
final emailRecoveryActionSetInvocation = requestBuilder.invocation(emailRecoveryActionSetMethod);
|
||||||
|
final response = await (requestBuilder
|
||||||
|
..usings(emailRecoveryActionSetMethod.requiredCapabilities))
|
||||||
|
.build()
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
final emailRecoveryActionSetResponse = response.parse<SetEmailRecoveryActionResponse>(
|
||||||
|
emailRecoveryActionSetInvocation.methodCallId,
|
||||||
|
SetEmailRecoveryActionResponse.deserialize
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
emailRecoveryActionSetResponse!.created![createRequestId]!.id,
|
||||||
|
equals(expectEmailRecoveryAction.id)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user