TF-2677 Create set server settings
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
|
||||
import 'package:jmap_dart_client/http/converter/set/set_method_properties_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.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';
|
||||
import 'package:server_settings/server_settings/capability_server_settings.dart';
|
||||
import 'package:server_settings/server_settings/tmail_server_settings.dart';
|
||||
|
||||
class SetServerSettingsMethod extends SetMethod<TMailServerSettings> with OptionalUpdateSingleton<TMailServerSettings>{
|
||||
SetServerSettingsMethod(AccountId accountId) : super(accountId);
|
||||
|
||||
@override
|
||||
MethodName get methodName => MethodName('Settings/set');
|
||||
|
||||
@override
|
||||
Set<CapabilityIdentifier> get requiredCapabilities => {
|
||||
CapabilityIdentifier.jmapCore,
|
||||
capabilityServerSettings,
|
||||
};
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
final val = <String, dynamic>{
|
||||
'accountId': const AccountIdConverter().toJson(accountId),
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('ifInState', ifInState?.value);
|
||||
writeNotNull('update', updateSingleton
|
||||
?.map((id, update) => SetMethodPropertiesConverter().fromMapIdToJson(id, update.toJson())));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [accountId, ifInState, update];
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
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/http/converter/state_nullable_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.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';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:server_settings/server_settings/tmail_server_settings.dart';
|
||||
|
||||
class SetServerSettingsResponse extends SetResponse<TMailServerSettings> {
|
||||
|
||||
SetServerSettingsResponse(
|
||||
AccountId accountId,
|
||||
{
|
||||
State? newState,
|
||||
State? oldState,
|
||||
Map<Id, TMailServerSettings>? created,
|
||||
Map<Id, TMailServerSettings?>? updated,
|
||||
Set<Id>? destroyed,
|
||||
Map<Id, SetError>? notCreated,
|
||||
Map<Id, SetError>? notUpdated,
|
||||
Map<Id, SetError>? notDestroyed
|
||||
}
|
||||
) : super(
|
||||
accountId,
|
||||
newState: newState,
|
||||
oldState: oldState,
|
||||
created: created,
|
||||
updated: updated,
|
||||
destroyed: destroyed,
|
||||
notCreated: notCreated,
|
||||
notUpdated: notUpdated,
|
||||
notDestroyed: notDestroyed
|
||||
);
|
||||
|
||||
static SetServerSettingsResponse deserialize(Map<String, dynamic> json) {
|
||||
return SetServerSettingsResponse(
|
||||
const AccountIdConverter().fromJson(json['accountId'] as String),
|
||||
newState: const StateNullableConverter().fromJson(json['newState'] as String?),
|
||||
oldState: const StateNullableConverter().fromJson(json['oldState'] as String?),
|
||||
created: (json['created'] as Map<String, dynamic>?)
|
||||
?.map((key, value) => MapEntry(
|
||||
const IdConverter().fromJson(key),
|
||||
TMailServerSettings.fromJson(value as Map<String, dynamic>))),
|
||||
updated: (json['updated'] as Map<String, dynamic>?)
|
||||
?.map((key, value) => MapEntry(
|
||||
const IdConverter().fromJson(key),
|
||||
value != null ? TMailServerSettings.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 => [
|
||||
oldState,
|
||||
newState,
|
||||
created,
|
||||
updated,
|
||||
destroyed,
|
||||
notCreated,
|
||||
notUpdated,
|
||||
notDestroyed
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
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/jmap_request.dart';
|
||||
import 'package:server_settings/server_settings/get/get_server_settings_method.dart';
|
||||
import 'package:server_settings/server_settings/get/get_server_settings_response.dart';
|
||||
import 'package:server_settings/server_settings/server_settings_id.dart';
|
||||
import 'package:server_settings/server_settings/set/set_server_settings_method.dart';
|
||||
import 'package:server_settings/server_settings/tmail_server_settings.dart';
|
||||
|
||||
void main() {
|
||||
final expectedResult = TMailServerSettings(
|
||||
id: ServerSettingsIdExtension.serverSettingsIdSingleton,
|
||||
settings: TMailServerSettingOptions(alwaysReadReceipts: true),
|
||||
);
|
||||
|
||||
group('set server settings method', () {
|
||||
test('should return expected result', () async {
|
||||
// arrange
|
||||
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": "abcdefghij",
|
||||
"methodResponses": [
|
||||
[
|
||||
"Settings/set",
|
||||
{
|
||||
"accountId": "123",
|
||||
"newState": "1",
|
||||
"updated": {"singleton": {}}
|
||||
},
|
||||
"c0"
|
||||
],
|
||||
[
|
||||
"Settings/get",
|
||||
{
|
||||
"accountId": "123",
|
||||
"notFound": [],
|
||||
"state": "1",
|
||||
"list": [
|
||||
{
|
||||
"id": "singleton",
|
||||
"settings": {"read.receipts.always": "true"}
|
||||
}
|
||||
]
|
||||
},
|
||||
"c1"
|
||||
]
|
||||
]
|
||||
},
|
||||
),
|
||||
data: {
|
||||
"using": [
|
||||
"urn:ietf:params:jmap:core",
|
||||
"com:linagora:params:jmap:settings"
|
||||
],
|
||||
"methodCalls": [
|
||||
[
|
||||
"Settings/set",
|
||||
{
|
||||
"accountId": "123",
|
||||
"update": {
|
||||
"singleton": {
|
||||
"id": "singleton",
|
||||
"settings": {"read.receipts.always": "true"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"c0"
|
||||
],
|
||||
[
|
||||
"Settings/get",
|
||||
{
|
||||
"accountId": "123",
|
||||
"ids": ["singleton"]
|
||||
},
|
||||
"c1"
|
||||
]
|
||||
]
|
||||
},
|
||||
headers: {
|
||||
"accept": "application/json;jmapVersion=rfc-8621",
|
||||
"content-length": 503
|
||||
},
|
||||
);
|
||||
|
||||
final httpClient = HttpClient(dio);
|
||||
final processingInvocation = ProcessingInvocation();
|
||||
final accountId = AccountId(Id('123'));
|
||||
|
||||
final setServerSettingsMethod = SetServerSettingsMethod(accountId)
|
||||
..addUpdatesSingleton({
|
||||
ServerSettingsIdExtension.serverSettingsIdSingleton.id: expectedResult,
|
||||
});
|
||||
final requestBuilder =
|
||||
JmapRequestBuilder(httpClient, processingInvocation)
|
||||
..invocation(setServerSettingsMethod);
|
||||
final getServerSettingsMethod = GetServerSettingsMethod(accountId)
|
||||
..addIds({ServerSettingsIdExtension.serverSettingsIdSingleton.id});
|
||||
final getServerSettingsInvocation =
|
||||
requestBuilder.invocation(getServerSettingsMethod);
|
||||
|
||||
// act
|
||||
final response = await (requestBuilder
|
||||
..usings(setServerSettingsMethod.requiredCapabilities))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
final setServerSettingsResponse =
|
||||
response.parse<GetServerSettingsResponse>(
|
||||
getServerSettingsInvocation.methodCallId,
|
||||
GetServerSettingsResponse.deserialize);
|
||||
|
||||
// assert
|
||||
expect(setServerSettingsResponse!.list.length, equals(1));
|
||||
expect(setServerSettingsResponse.list, containsAll({expectedResult}));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user