Browse Source

nextcloud: Refactor version checks

pull/452/head
jld3103 1 year ago
parent
commit
e589595be7
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 10
      packages/nextcloud/lib/src/version_supported.dart
  2. 9
      packages/nextcloud/test/core_test.dart
  3. 2
      packages/nextcloud/test/notes_test.dart

10
packages/nextcloud/lib/src/version_supported.dart

@ -17,12 +17,18 @@ extension CoreVersionSupported on CoreClient {
/// Check if the core/Server version is supported by this client /// Check if the core/Server version is supported by this client
/// ///
/// Also returns the supported version number /// Also returns the supported version number
Future<(bool, int)> isSupported(final CoreServerCapabilities_Ocs_Data capabilities) async => ( (bool, int) isSupported(final CoreServerCapabilities_Ocs_Data capabilities) => (
capabilities.version.major == coreSupportedVersion, capabilities.version.major == coreSupportedVersion,
coreSupportedVersion, coreSupportedVersion,
); );
} }
// ignore: public_member_api_docs
extension CoreStatusVersionSupported on CoreServerStatus {
/// Check if the core/Server version is supported
bool get isSupported => version.startsWith('$coreSupportedVersion.');
}
// ignore: public_member_api_docs // ignore: public_member_api_docs
extension NewsVersionSupported on NewsClient { extension NewsVersionSupported on NewsClient {
/// Check if the news app version is supported by this client /// Check if the news app version is supported by this client
@ -42,7 +48,7 @@ extension NotesVersionSupported on NotesClient {
/// Check if the notes app version is supported by this client /// Check if the notes app version is supported by this client
/// ///
/// Also returns the supported API version number /// Also returns the supported API version number
Future<(bool, int)> isSupported(final CoreServerCapabilities_Ocs_Data capabilities) async => ( (bool, int) isSupported(final CoreServerCapabilities_Ocs_Data capabilities) => (
capabilities.capabilities.notes?.apiVersion capabilities.capabilities.notes?.apiVersion
?.map(Version.parse) ?.map(Version.parse)
.where((final version) => version.major == notesSupportedVersion) .where((final version) => version.major == notesSupportedVersion)

9
packages/nextcloud/test/core_test.dart

@ -17,11 +17,16 @@ Future run(final DockerImage image) async {
}); });
tearDown(() => container.destroy()); tearDown(() => container.destroy());
test('Is supported', () async { test('Is supported from capabilities', () async {
final (supported, _) = await client.core.isSupported((await client.core.getCapabilities()).ocs.data); final (supported, _) = client.core.isSupported((await client.core.getCapabilities()).ocs.data);
expect(supported, isTrue); expect(supported, isTrue);
}); });
test('Is supported from status', () async {
final status = await client.core.getStatus();
expect(status.isSupported, isTrue);
});
test('Get status', () async { test('Get status', () async {
final status = await client.core.getStatus(); final status = await client.core.getStatus();
expect(status.installed, true); expect(status.installed, true);

2
packages/nextcloud/test/notes_test.dart

@ -18,7 +18,7 @@ Future run(final DockerImage image) async {
tearDown(() => container.destroy()); tearDown(() => container.destroy());
test('Is supported', () async { test('Is supported', () async {
final (supported, _) = await client.notes.isSupported((await client.core.getCapabilities()).ocs.data); final (supported, _) = client.notes.isSupported((await client.core.getCapabilities()).ocs.data);
expect(supported, isTrue); expect(supported, isTrue);
}); });

Loading…
Cancel
Save