Browse Source

Merge pull request #1053 from nextcloud/refactor/nextcloud/group-tests

refactor(nextcloud): Group tests by tags
pull/1029/head
Kate 1 year ago committed by GitHub
parent
commit
87f6fe851f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 230
      packages/nextcloud/test/core_test.dart
  2. 135
      packages/nextcloud/test/notifications_test.dart
  3. 2
      packages/nextcloud/test/provisioning_api_test.dart
  4. 10
      packages/nextcloud/test/settings_test.dart
  5. 350
      packages/nextcloud/test/user_status_test.dart

230
packages/nextcloud/test/core_test.dart

@ -52,129 +52,145 @@ void main() {
expect(response.body.extendedSupport, isFalse); expect(response.body.extendedSupport, isFalse);
}); });
test('Get capabilities', () async { group('OCS', () {
final response = await client.core.ocs.getCapabilities(); test('Get capabilities', () async {
expect(response.statusCode, 200); final response = await client.core.ocs.getCapabilities();
expect(() => response.headers, isA<void>()); expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.version.major, core.supportedVersion);
expect(response.body.ocs.data.version.string, startsWith('${core.supportedVersion}.')); expect(response.body.ocs.data.version.major, core.supportedVersion);
expect(response.body.ocs.data.capabilities.commentsCapabilities, isNotNull); expect(response.body.ocs.data.version.string, startsWith('${core.supportedVersion}.'));
expect(response.body.ocs.data.capabilities.davCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.commentsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.davCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesSharingCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.filesCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesTrashbinCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.filesSharingCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesVersionsCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.filesTrashbinCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.notesCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.filesVersionsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.notificationsCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.notesCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.provisioningApiCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.notificationsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.sharebymailCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.provisioningApiCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.themingPublicCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.sharebymailCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.userStatusCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.themingPublicCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.weatherStatusCapabilities, isNotNull); expect(response.body.ocs.data.capabilities.userStatusCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.weatherStatusCapabilities, isNotNull);
});
}); });
test('Get navigation apps', () async { group('Navigation', () {
final response = await client.core.navigation.getAppsNavigation(); test('Get apps navigation', () async {
expect(response.statusCode, 200); final response = await client.core.navigation.getAppsNavigation();
expect(() => response.headers, isA<void>()); expect(response.statusCode, 200);
expect(response.body.ocs.data, hasLength(6)); expect(() => response.headers, isA<void>());
expect(response.body.ocs.data, hasLength(6));
expect(response.body.ocs.data[0].id, 'dashboard');
expect(response.body.ocs.data[1].id, 'files'); expect(response.body.ocs.data[0].id, 'dashboard');
expect(response.body.ocs.data[2].id, 'photos'); expect(response.body.ocs.data[1].id, 'files');
expect(response.body.ocs.data[3].id, 'activity'); expect(response.body.ocs.data[2].id, 'photos');
expect(response.body.ocs.data[4].id, 'notes'); expect(response.body.ocs.data[3].id, 'activity');
expect(response.body.ocs.data[5].id, 'news'); expect(response.body.ocs.data[4].id, 'notes');
expect(response.body.ocs.data[5].id, 'news');
});
}); });
test('Autocomplete', () async { group('Autocomplete', () {
final response = await client.core.autoComplete.$get( test('Get', () async {
search: '', final response = await client.core.autoComplete.$get(
itemType: 'call', search: '',
itemId: 'new', itemType: 'call',
shareTypes: [core.ShareType.group.index], itemId: 'new',
); shareTypes: [core.ShareType.group.index],
expect(response.body.ocs.data, hasLength(1)); );
expect(response.body.ocs.data, hasLength(1));
expect(response.body.ocs.data[0].id, 'admin');
expect(response.body.ocs.data[0].label, 'admin'); expect(response.body.ocs.data[0].id, 'admin');
expect(response.body.ocs.data[0].icon, ''); expect(response.body.ocs.data[0].label, 'admin');
expect(response.body.ocs.data[0].source, 'groups'); expect(response.body.ocs.data[0].icon, '');
expect(response.body.ocs.data[0].status.autocompleteResultStatus0, isNull); expect(response.body.ocs.data[0].source, 'groups');
expect(response.body.ocs.data[0].status.string, isEmpty); expect(response.body.ocs.data[0].status.autocompleteResultStatus0, isNull);
expect(response.body.ocs.data[0].subline, ''); expect(response.body.ocs.data[0].status.string, isEmpty);
expect(response.body.ocs.data[0].shareWithDisplayNameUnique, ''); expect(response.body.ocs.data[0].subline, '');
expect(response.body.ocs.data[0].shareWithDisplayNameUnique, '');
});
}); });
test('Get preview', () async { group('Preview', () {
final response = await client.core.preview.getPreview(file: 'Nextcloud.png'); test('Get', () async {
expect(response.statusCode, 200); final response = await client.core.preview.getPreview(file: 'Nextcloud.png');
expect(() => response.headers, isA<void>()); expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body, isNotEmpty); expect(response.body, isNotEmpty);
});
}); });
test('Get avatar', () async { group('Avatar', () {
final response = await client.core.avatar.getAvatar(userId: 'admin', size: 32); test('Get', () async {
expect(response.body, isNotEmpty); final response = await client.core.avatar.getAvatar(userId: 'admin', size: 32);
}); expect(response.body, isNotEmpty);
});
test('Get dark avatar', () async {
final response = await client.core.avatar.getAvatarDark(userId: 'admin', size: 32);
expect(response.body, isNotEmpty);
});
test('Delete app password', () async { test('Get dark', () async {
await client.core.appPassword.deleteAppPassword(); final response = await client.core.avatar.getAvatarDark(userId: 'admin', size: 32);
expect( expect(response.body, isNotEmpty);
() => client.core.appPassword.deleteAppPassword(), });
throwsA(predicate((final e) => (e! as DynamiteApiException).statusCode == 401)),
);
}); });
test('Unified search providers', () async { group('App password', () {
final response = await client.core.unifiedSearch.getProviders(); test('Delete', () async {
expect(response.statusCode, 200); await client.core.appPassword.deleteAppPassword();
expect(() => response.headers, isA<void>()); expect(
() => client.core.appPassword.deleteAppPassword(),
expect(response.body.ocs.data, hasLength(14)); throwsA(predicate((final e) => (e! as DynamiteApiException).statusCode == 401)),
);
});
}); });
test('Unified search', () async { group('Unified search', () {
final response = await client.core.unifiedSearch.search( test('Get providers', () async {
providerId: 'settings', final response = await client.core.unifiedSearch.getProviders();
term: 'Personal info', expect(response.statusCode, 200);
); expect(() => response.headers, isA<void>());
expect(response.statusCode, 200); expect(response.body.ocs.data, hasLength(14));
expect(() => response.headers, isA<void>()); });
expect(response.body.ocs.data.name, 'Settings'); test('Search', () async {
expect(response.body.ocs.data.isPaginated, isFalse); final response = await client.core.unifiedSearch.search(
expect(response.body.ocs.data.entries, hasLength(1)); providerId: 'settings',
expect(response.body.ocs.data.entries.single.thumbnailUrl, isEmpty); term: 'Personal info',
expect(response.body.ocs.data.entries.single.title, 'Personal info'); );
expect(response.body.ocs.data.entries.single.subline, isEmpty);
expect(response.body.ocs.data.entries.single.resourceUrl, isNotEmpty); expect(response.statusCode, 200);
expect(response.body.ocs.data.entries.single.icon, 'icon-settings-dark'); expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.entries.single.rounded, isFalse);
expect(response.body.ocs.data.entries.single.attributes, isEmpty); expect(response.body.ocs.data.name, 'Settings');
expect(response.body.ocs.data.isPaginated, isFalse);
expect(response.body.ocs.data.entries, hasLength(1));
expect(response.body.ocs.data.entries.single.thumbnailUrl, isEmpty);
expect(response.body.ocs.data.entries.single.title, 'Personal info');
expect(response.body.ocs.data.entries.single.subline, isEmpty);
expect(response.body.ocs.data.entries.single.resourceUrl, isNotEmpty);
expect(response.body.ocs.data.entries.single.icon, 'icon-settings-dark');
expect(response.body.ocs.data.entries.single.rounded, isFalse);
expect(response.body.ocs.data.entries.single.attributes, isEmpty);
});
}); });
test('Client login flow V2', () async { group('Client login flow V2', () {
final response = await client.core.clientFlowLoginV2.init(); test('Init and poll', () async {
expect(response.statusCode, 200); final response = await client.core.clientFlowLoginV2.init();
expect(() => response.headers, isA<void>()); expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.login, startsWith('http://localhost'));
expect(response.body.poll.endpoint, startsWith('http://localhost')); expect(response.body.login, startsWith('http://localhost'));
expect(response.body.poll.token, isNotEmpty); expect(response.body.poll.endpoint, startsWith('http://localhost'));
expect(response.body.poll.token, isNotEmpty);
expect(
() => client.core.clientFlowLoginV2.poll(token: response.body.poll.token), expect(
throwsA(predicate<DynamiteApiException>((final e) => e.statusCode == 404)), () => client.core.clientFlowLoginV2.poll(token: response.body.poll.token),
); throwsA(predicate<DynamiteApiException>((final e) => e.statusCode == 404)),
);
});
}); });
}, },
retry: retryCount, retry: retryCount,

135
packages/nextcloud/test/notifications_test.dart

@ -29,79 +29,80 @@ void main() {
); );
} }
test('Send admin notification', () async { group('API', () {
await sendTestNotification(); test('Send admin notification', () async {
await sendTestNotification();
});
}); });
test('List notifications', () async { group('Endpoint', () {
await sendTestNotification(); test('List notifications', () async {
await sendTestNotification();
final startTime = DateTime.now().toUtc();
final response = (await client.notifications.endpoint.listNotifications()).body; final startTime = DateTime.now().toUtc();
expect(response.ocs.data, hasLength(2)); final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data[0].notificationId, 2); expect(response.ocs.data, hasLength(2));
expect(response.ocs.data[0].app, 'admin_notifications'); expect(response.ocs.data[0].notificationId, 2);
expect(response.ocs.data[0].user, 'admin'); expect(response.ocs.data[0].app, 'admin_notifications');
expectDateInReasonableTimeRange(DateTime.parse(response.ocs.data[0].datetime), startTime); expect(response.ocs.data[0].user, 'admin');
expect(response.ocs.data[0].objectType, 'admin_notifications'); expectDateInReasonableTimeRange(DateTime.parse(response.ocs.data[0].datetime), startTime);
expect(response.ocs.data[0].objectId, isNotNull); expect(response.ocs.data[0].objectType, 'admin_notifications');
expect(response.ocs.data[0].subject, '123'); expect(response.ocs.data[0].objectId, isNotNull);
expect(response.ocs.data[0].message, '456'); expect(response.ocs.data[0].subject, '123');
expect(response.ocs.data[0].link, ''); expect(response.ocs.data[0].message, '456');
expect(response.ocs.data[0].subjectRich, ''); expect(response.ocs.data[0].link, '');
expect(response.ocs.data[0].subjectRichParameters, isEmpty); expect(response.ocs.data[0].subjectRich, '');
expect(response.ocs.data[0].messageRich, ''); expect(response.ocs.data[0].subjectRichParameters, isEmpty);
expect(response.ocs.data[0].messageRichParameters, isEmpty); expect(response.ocs.data[0].messageRich, '');
expect(response.ocs.data[0].icon, isNotEmpty); expect(response.ocs.data[0].messageRichParameters, isEmpty);
expect(response.ocs.data[0].actions, hasLength(0)); expect(response.ocs.data[0].icon, isNotEmpty);
}); expect(response.ocs.data[0].actions, hasLength(0));
});
test('Get notification', () async { test('Get notification', () async {
await sendTestNotification(); await sendTestNotification();
final startTime = DateTime.now().toUtc(); final startTime = DateTime.now().toUtc();
final response = await client.notifications.endpoint.getNotification(id: 2); final response = await client.notifications.endpoint.getNotification(id: 2);
expect(response.statusCode, 200); expect(response.statusCode, 200);
expect(() => response.headers, isA<void>()); expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.notificationId, 2); expect(response.body.ocs.data.notificationId, 2);
expect(response.body.ocs.data.app, 'admin_notifications'); expect(response.body.ocs.data.app, 'admin_notifications');
expect(response.body.ocs.data.user, 'admin'); expect(response.body.ocs.data.user, 'admin');
expectDateInReasonableTimeRange(DateTime.parse(response.body.ocs.data.datetime), startTime); expectDateInReasonableTimeRange(DateTime.parse(response.body.ocs.data.datetime), startTime);
expect(response.body.ocs.data.objectType, 'admin_notifications'); expect(response.body.ocs.data.objectType, 'admin_notifications');
expect(response.body.ocs.data.objectId, isNotNull); expect(response.body.ocs.data.objectId, isNotNull);
expect(response.body.ocs.data.subject, '123'); expect(response.body.ocs.data.subject, '123');
expect(response.body.ocs.data.message, '456'); expect(response.body.ocs.data.message, '456');
expect(response.body.ocs.data.link, ''); expect(response.body.ocs.data.link, '');
expect(response.body.ocs.data.subjectRich, ''); expect(response.body.ocs.data.subjectRich, '');
expect(response.body.ocs.data.subjectRichParameters, isEmpty); expect(response.body.ocs.data.subjectRichParameters, isEmpty);
expect(response.body.ocs.data.messageRich, ''); expect(response.body.ocs.data.messageRich, '');
expect(response.body.ocs.data.messageRichParameters, isEmpty); expect(response.body.ocs.data.messageRichParameters, isEmpty);
expect(response.body.ocs.data.icon, isNotEmpty); expect(response.body.ocs.data.icon, isNotEmpty);
expect(response.body.ocs.data.actions, hasLength(0)); expect(response.body.ocs.data.actions, hasLength(0));
}); });
test('Delete notification', () async { test('Delete notification', () async {
await sendTestNotification(); await sendTestNotification();
await client.notifications.endpoint.deleteNotification(id: 2); await client.notifications.endpoint.deleteNotification(id: 2);
final response = (await client.notifications.endpoint.listNotifications()).body; final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data, hasLength(1)); expect(response.ocs.data, hasLength(1));
}); });
test('Delete all notifications', () async { test('Delete all notifications', () async {
await sendTestNotification(); await sendTestNotification();
await sendTestNotification(); await sendTestNotification();
await client.notifications.endpoint.deleteAllNotifications(); await client.notifications.endpoint.deleteAllNotifications();
final response = (await client.notifications.endpoint.listNotifications()).body; final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data, hasLength(0)); expect(response.ocs.data, hasLength(0));
});
}); });
});
group( group('Push', () {
'push notifications',
() {
late DockerImage image; late DockerImage image;
setUpAll(() async => image = await getDockerImage()); setUpAll(() async => image = await getDockerImage());
@ -139,8 +140,6 @@ void main() {
await client.notifications.push.removeDevice(); await client.notifications.push.removeDevice();
}); });
}, });
retry: retryCount, });
timeout: timeout,
);
} }

2
packages/nextcloud/test/provisioning_api_test.dart

@ -46,7 +46,7 @@ void main() {
}); });
group('Apps', () { group('Apps', () {
test('Get apps', () async { test('Get', () async {
final response = await client.provisioningApi.apps.getApps(); final response = await client.provisioningApi.apps.getApps();
expect(response.statusCode, 200); expect(response.statusCode, 200);
expect(() => response.headers, isA<void>()); expect(() => response.headers, isA<void>());

10
packages/nextcloud/test/settings_test.dart

@ -22,10 +22,12 @@ Future<void> run(final DockerImage image) async {
}); });
tearDown(() => container.destroy()); tearDown(() => container.destroy());
test('Download log file', () async { group('Logs', () {
final response = await client.settings.logSettings.download(); test('Download', () async {
final logs = utf8.decode(response.body); final response = await client.settings.logSettings.download();
expect(logs, await container.nextcloudLogs()); final logs = utf8.decode(response.body);
expect(logs, await container.nextcloudLogs());
});
}); });
}); });
} }

350
packages/nextcloud/test/user_status_test.dart

@ -18,183 +18,191 @@ void main() {
}); });
tearDown(() => container.destroy()); tearDown(() => container.destroy());
test('Find all predefined statuses', () async { group('Predefined status', () {
final expectedStatusIDs = ['meeting', 'commuting', 'remote-work', 'sick-leave', 'vacationing']; test('Find all', () async {
final response = await client.userStatus.predefinedStatus.findAll(); final expectedStatusIDs = ['meeting', 'commuting', 'remote-work', 'sick-leave', 'vacationing'];
expect(response.statusCode, 200); final response = await client.userStatus.predefinedStatus.findAll();
expect(() => response.headers, isA<void>()); expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data, hasLength(5));
final responseIDs = response.body.ocs.data.map((final status) => status.id); expect(response.body.ocs.data, hasLength(5));
expect(expectedStatusIDs.map(responseIDs.contains).contains(false), false); final responseIDs = response.body.ocs.data.map((final status) => status.id);
for (final status in response.body.ocs.data) { expect(expectedStatusIDs.map(responseIDs.contains).contains(false), false);
expect(status.icon, isNotNull); for (final status in response.body.ocs.data) {
expect(status.message, isNotNull); expect(status.icon, isNotNull);
} expect(status.message, isNotNull);
}
final meeting = response.body.ocs.data.singleWhere((final s) => s.id == 'meeting').clearAt!;
expect(meeting.type, user_status.ClearAt_Type.period); final meeting = response.body.ocs.data.singleWhere((final s) => s.id == 'meeting').clearAt!;
expect(meeting.time.$int, 3600); expect(meeting.type, user_status.ClearAt_Type.period);
expect(meeting.time.$int, 3600);
final commuting = response.body.ocs.data.singleWhere((final s) => s.id == 'commuting').clearAt!;
expect(commuting.type, user_status.ClearAt_Type.period); final commuting = response.body.ocs.data.singleWhere((final s) => s.id == 'commuting').clearAt!;
expect(commuting.time.$int, 1800); expect(commuting.type, user_status.ClearAt_Type.period);
expect(commuting.time.$int, 1800);
final remoteWork = response.body.ocs.data.singleWhere((final s) => s.id == 'remote-work').clearAt!;
expect(remoteWork.type, user_status.ClearAt_Type.endOf); final remoteWork = response.body.ocs.data.singleWhere((final s) => s.id == 'remote-work').clearAt!;
expect(remoteWork.time.clearAtTimeType, user_status.ClearAtTimeType.day); expect(remoteWork.type, user_status.ClearAt_Type.endOf);
expect(remoteWork.time.clearAtTimeType, user_status.ClearAtTimeType.day);
final sickLeave = response.body.ocs.data.singleWhere((final s) => s.id == 'sick-leave').clearAt!;
expect(sickLeave.type, user_status.ClearAt_Type.endOf); final sickLeave = response.body.ocs.data.singleWhere((final s) => s.id == 'sick-leave').clearAt!;
expect(sickLeave.time.clearAtTimeType, user_status.ClearAtTimeType.day); expect(sickLeave.type, user_status.ClearAt_Type.endOf);
expect(sickLeave.time.clearAtTimeType, user_status.ClearAtTimeType.day);
final vacationing = response.body.ocs.data.singleWhere((final s) => s.id == 'vacationing').clearAt;
expect(vacationing, null); final vacationing = response.body.ocs.data.singleWhere((final s) => s.id == 'vacationing').clearAt;
expect(vacationing, null);
});
}); });
test('Set status', () async { group('User status', () {
final response = await client.userStatus.userStatus.setStatus(statusType: 'online'); test('Set', () async {
expect(response.statusCode, 200); final response = await client.userStatus.userStatus.setStatus(statusType: 'online');
expect(() => response.headers, isA<void>()); expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null); expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.messageId, null); expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.messageIsPredefined, false); expect(response.body.ocs.data.messageId, null);
expect(response.body.ocs.data.icon, null); expect(response.body.ocs.data.messageIsPredefined, false);
expect(response.body.ocs.data.clearAt, null); expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.status, 'online'); expect(response.body.ocs.data.clearAt, null);
expect(response.body.ocs.data.statusIsUserDefined, true); expect(response.body.ocs.data.status, 'online');
expect(response.body.ocs.data.statusIsUserDefined, true);
});
test('Get', () async {
// There seems to be a bug in Nextcloud which makes getting the status fail before it has been set once.
// The error message from Nextcloud is "Could not create folder"
await client.userStatus.userStatus.setStatus(statusType: 'online');
final response = await client.userStatus.userStatus.getStatus();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.messageId, null);
expect(response.body.ocs.data.messageIsPredefined, false);
expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.clearAt, null);
expect(response.body.ocs.data.status, 'online');
expect(response.body.ocs.data.statusIsUserDefined, true);
});
test('Find', () async {
// Same as getting status
await client.userStatus.userStatus.setStatus(statusType: 'online');
final response = await client.userStatus.statuses.find(userId: 'user1');
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.clearAt, null);
expect(response.body.ocs.data.status, 'online');
});
test('Set predefined message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
final response = await client.userStatus.userStatus.setPredefinedMessage(
messageId: 'meeting',
clearAt: clearAt,
);
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.messageId, 'meeting');
expect(response.body.ocs.data.messageIsPredefined, true);
expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.clearAt, clearAt);
expect(response.body.ocs.data.status, 'offline');
expect(response.body.ocs.data.statusIsUserDefined, false);
});
test('Set custom message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
final response = await client.userStatus.userStatus.setCustomMessage(
statusIcon: '😀',
message: 'bla',
clearAt: clearAt,
);
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, 'bla');
expect(response.body.ocs.data.messageId, null);
expect(response.body.ocs.data.messageIsPredefined, false);
expect(response.body.ocs.data.icon, '😀');
expect(response.body.ocs.data.clearAt, clearAt);
expect(response.body.ocs.data.status, 'offline');
expect(response.body.ocs.data.statusIsUserDefined, false);
});
test('Clear message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
await client.userStatus.userStatus.setCustomMessage(
statusIcon: '😀',
message: 'bla',
clearAt: clearAt,
);
await client.userStatus.userStatus.clearMessage();
final response = await client.userStatus.userStatus.getStatus();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.messageId, null);
expect(response.body.ocs.data.messageIsPredefined, false);
expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.clearAt, null);
expect(response.body.ocs.data.status, 'offline');
expect(response.body.ocs.data.statusIsUserDefined, false);
});
}); });
test('Get status', () async { group('Statuses', () {
// There seems to be a bug in Nextcloud which makes getting the status fail before it has been set once. test('Find all', () async {
// The error message from Nextcloud is "Could not create folder" var response = await client.userStatus.statuses.findAll();
await client.userStatus.userStatus.setStatus(statusType: 'online'); expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
final response = await client.userStatus.userStatus.getStatus(); expect(response.body.ocs.data, hasLength(0));
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>()); await client.userStatus.userStatus.setStatus(statusType: 'online');
expect(response.body.ocs.data.userId, 'user1'); response = await client.userStatus.statuses.findAll();
expect(response.body.ocs.data.message, null); expect(response.statusCode, 200);
expect(response.body.ocs.data.messageId, null); expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.messageIsPredefined, false); expect(response.body.ocs.data, hasLength(1));
expect(response.body.ocs.data.icon, null); expect(response.body.ocs.data[0].userId, 'user1');
expect(response.body.ocs.data.clearAt, null); expect(response.body.ocs.data[0].message, null);
expect(response.body.ocs.data.status, 'online'); expect(response.body.ocs.data[0].icon, null);
expect(response.body.ocs.data.statusIsUserDefined, true); expect(response.body.ocs.data[0].clearAt, null);
expect(response.body.ocs.data[0].status, 'online');
});
}); });
test('Find all statuses', () async { group('Heartbeat', () {
var response = await client.userStatus.statuses.findAll(); test('Heartbeat', () async {
expect(response.statusCode, 200); final response = await client.userStatus.heartbeat.heartbeat(status: 'online');
expect(() => response.headers, isA<void>()); expect(response.statusCode, 200);
expect(response.body.ocs.data, hasLength(0)); expect(() => response.headers, isA<void>());
await client.userStatus.userStatus.setStatus(statusType: 'online'); expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
response = await client.userStatus.statuses.findAll(); expect(response.body.ocs.data.messageId, null);
expect(response.statusCode, 200); expect(response.body.ocs.data.messageIsPredefined, false);
expect(() => response.headers, isA<void>()); expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data, hasLength(1)); expect(response.body.ocs.data.clearAt, null);
expect(response.body.ocs.data[0].userId, 'user1'); expect(response.body.ocs.data.status, 'online');
expect(response.body.ocs.data[0].message, null); expect(response.body.ocs.data.statusIsUserDefined, false);
expect(response.body.ocs.data[0].icon, null); });
expect(response.body.ocs.data[0].clearAt, null);
expect(response.body.ocs.data[0].status, 'online');
});
test('Find status', () async {
// Same as getting status
await client.userStatus.userStatus.setStatus(statusType: 'online');
final response = await client.userStatus.statuses.find(userId: 'user1');
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.clearAt, null);
expect(response.body.ocs.data.status, 'online');
});
test('Set predefined message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
final response = await client.userStatus.userStatus.setPredefinedMessage(
messageId: 'meeting',
clearAt: clearAt,
);
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.messageId, 'meeting');
expect(response.body.ocs.data.messageIsPredefined, true);
expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.clearAt, clearAt);
expect(response.body.ocs.data.status, 'offline');
expect(response.body.ocs.data.statusIsUserDefined, false);
});
test('Set custom message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
final response = await client.userStatus.userStatus.setCustomMessage(
statusIcon: '😀',
message: 'bla',
clearAt: clearAt,
);
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, 'bla');
expect(response.body.ocs.data.messageId, null);
expect(response.body.ocs.data.messageIsPredefined, false);
expect(response.body.ocs.data.icon, '😀');
expect(response.body.ocs.data.clearAt, clearAt);
expect(response.body.ocs.data.status, 'offline');
expect(response.body.ocs.data.statusIsUserDefined, false);
});
test('Clear message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
await client.userStatus.userStatus.setCustomMessage(
statusIcon: '😀',
message: 'bla',
clearAt: clearAt,
);
await client.userStatus.userStatus.clearMessage();
final response = await client.userStatus.userStatus.getStatus();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.messageId, null);
expect(response.body.ocs.data.messageIsPredefined, false);
expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.clearAt, null);
expect(response.body.ocs.data.status, 'offline');
expect(response.body.ocs.data.statusIsUserDefined, false);
});
test('Heartbeat', () async {
final response = await client.userStatus.heartbeat.heartbeat(status: 'online');
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.userId, 'user1');
expect(response.body.ocs.data.message, null);
expect(response.body.ocs.data.messageId, null);
expect(response.body.ocs.data.messageIsPredefined, false);
expect(response.body.ocs.data.icon, null);
expect(response.body.ocs.data.clearAt, null);
expect(response.body.ocs.data.status, 'online');
expect(response.body.ocs.data.statusIsUserDefined, false);
}); });
}, },
retry: retryCount, retry: retryCount,

Loading…
Cancel
Save