107 lines
3.2 KiB
Dart
107 lines
3.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:immich_mobile/utils/openapi_patching.dart';
|
|
import 'package:openapi/api.dart';
|
|
|
|
void main() {
|
|
group('Test OpenApi Patching', () {
|
|
test('older public config deserializes with map and video defaults', () {
|
|
final config = PublicConfigDto.fromJson(<String, dynamic>{
|
|
'oauth': {'autoLaunch': false, 'buttonText': 'Login', 'enabled': false},
|
|
'passwordLogin': {'enabled': true},
|
|
'server': {'loginPageMessage': ''},
|
|
});
|
|
expect(config, isNotNull);
|
|
expect(config!.map.enabled, isTrue);
|
|
expect(config.map.lightStyle, 'https://tiles.immich.cloud/v1/style/light.json');
|
|
expect(config.ffmpeg.realtime.enabled, isFalse);
|
|
});
|
|
|
|
test('public config keeps explicit server map and video settings', () {
|
|
final config = PublicConfigDto.fromJson(<String, dynamic>{
|
|
'oauth': {'autoLaunch': false, 'buttonText': 'Login', 'enabled': false},
|
|
'passwordLogin': {'enabled': true},
|
|
'server': {'loginPageMessage': ''},
|
|
'map': {'enabled': false, 'lightStyle': 'https://example.com/light', 'darkStyle': 'https://example.com/dark'},
|
|
'ffmpeg': {
|
|
'realtime': {'enabled': true},
|
|
},
|
|
});
|
|
expect(config!.map.enabled, isFalse);
|
|
expect(config.map.lightStyle, 'https://example.com/light');
|
|
expect(config.ffmpeg.realtime.enabled, isTrue);
|
|
});
|
|
|
|
test('older user config defaults SMTP to disabled', () {
|
|
final value = <String, dynamic>{};
|
|
upgradeDto(value, 'UserConfigDto');
|
|
final notifications = UserConfigNotificationsDto.fromJson(value['notifications']);
|
|
expect(notifications!.smtp.enabled, isFalse);
|
|
});
|
|
|
|
test('user config preserves an enabled SMTP setting', () {
|
|
final value = <String, dynamic>{
|
|
'notifications': {
|
|
'smtp': {'enabled': true},
|
|
},
|
|
};
|
|
upgradeDto(value, 'UserConfigDto');
|
|
final notifications = UserConfigNotificationsDto.fromJson(value['notifications']);
|
|
expect(notifications!.smtp.enabled, isTrue);
|
|
});
|
|
|
|
test('upgradeDto', () {
|
|
dynamic value;
|
|
String targetType;
|
|
|
|
targetType = 'UserPreferencesResponseDto';
|
|
value = jsonDecode("""
|
|
{
|
|
"download": {
|
|
"archiveSize": 4294967296,
|
|
"includeEmbeddedVideos": false
|
|
}
|
|
}
|
|
""");
|
|
|
|
upgradeDto(value, targetType);
|
|
expect(value['tags'], TagsResponse(enabled: false, sidebarWeb: false).toJson());
|
|
expect(value['download']['includeEmbeddedVideos'], false);
|
|
});
|
|
|
|
test('addDefault', () {
|
|
final dynamic value = jsonDecode("""
|
|
{
|
|
"download": {
|
|
"archiveSize": 4294967296,
|
|
"includeEmbeddedVideos": false
|
|
}
|
|
}
|
|
""");
|
|
String keys = 'download.unknownKey';
|
|
dynamic defaultValue = 69420;
|
|
|
|
addDefault(value, keys, defaultValue);
|
|
expect(value['download']['unknownKey'], 69420);
|
|
|
|
keys = 'alpha.beta';
|
|
defaultValue = 'gamma';
|
|
addDefault(value, keys, defaultValue);
|
|
expect(value['alpha']['beta'], 'gamma');
|
|
});
|
|
|
|
test('addDefault with null', () {
|
|
final dynamic value = jsonDecode("""
|
|
{
|
|
"download": {
|
|
"archiveSize": 4294967296,
|
|
"includeEmbeddedVideos": false
|
|
}
|
|
}
|
|
""");
|
|
expect(value['download']['unknownKey'], isNull);
|
|
});
|
|
});
|
|
}
|