Browse Source

refactor(nextcloud): Group tests by tags

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/1053/head
jld3103 1 year ago
parent
commit
5c220df656
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  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);
});
test('Get capabilities', () async {
final response = await client.core.ocs.getCapabilities();
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.capabilities.commentsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.davCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesSharingCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesTrashbinCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesVersionsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.notesCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.notificationsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.provisioningApiCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.sharebymailCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.themingPublicCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.userStatusCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.weatherStatusCapabilities, isNotNull);
group('OCS', () {
test('Get capabilities', () async {
final response = await client.core.ocs.getCapabilities();
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.capabilities.commentsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.davCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesSharingCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesTrashbinCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.filesVersionsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.notesCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.notificationsCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.provisioningApiCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.sharebymailCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.themingPublicCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.userStatusCapabilities, isNotNull);
expect(response.body.ocs.data.capabilities.weatherStatusCapabilities, isNotNull);
});
});
test('Get navigation apps', () async {
final response = await client.core.navigation.getAppsNavigation();
expect(response.statusCode, 200);
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[2].id, 'photos');
expect(response.body.ocs.data[3].id, 'activity');
expect(response.body.ocs.data[4].id, 'notes');
expect(response.body.ocs.data[5].id, 'news');
group('Navigation', () {
test('Get apps navigation', () async {
final response = await client.core.navigation.getAppsNavigation();
expect(response.statusCode, 200);
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[2].id, 'photos');
expect(response.body.ocs.data[3].id, 'activity');
expect(response.body.ocs.data[4].id, 'notes');
expect(response.body.ocs.data[5].id, 'news');
});
});
test('Autocomplete', () async {
final response = await client.core.autoComplete.$get(
search: '',
itemType: 'call',
itemId: 'new',
shareTypes: [core.ShareType.group.index],
);
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].icon, '');
expect(response.body.ocs.data[0].source, 'groups');
expect(response.body.ocs.data[0].status.autocompleteResultStatus0, isNull);
expect(response.body.ocs.data[0].status.string, isEmpty);
expect(response.body.ocs.data[0].subline, '');
expect(response.body.ocs.data[0].shareWithDisplayNameUnique, '');
group('Autocomplete', () {
test('Get', () async {
final response = await client.core.autoComplete.$get(
search: '',
itemType: 'call',
itemId: 'new',
shareTypes: [core.ShareType.group.index],
);
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].icon, '');
expect(response.body.ocs.data[0].source, 'groups');
expect(response.body.ocs.data[0].status.autocompleteResultStatus0, isNull);
expect(response.body.ocs.data[0].status.string, isEmpty);
expect(response.body.ocs.data[0].subline, '');
expect(response.body.ocs.data[0].shareWithDisplayNameUnique, '');
});
});
test('Get preview', () async {
final response = await client.core.preview.getPreview(file: 'Nextcloud.png');
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
group('Preview', () {
test('Get', () async {
final response = await client.core.preview.getPreview(file: 'Nextcloud.png');
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body, isNotEmpty);
expect(response.body, isNotEmpty);
});
});
test('Get avatar', () async {
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);
});
group('Avatar', () {
test('Get', () async {
final response = await client.core.avatar.getAvatar(userId: 'admin', size: 32);
expect(response.body, isNotEmpty);
});
test('Delete app password', () async {
await client.core.appPassword.deleteAppPassword();
expect(
() => client.core.appPassword.deleteAppPassword(),
throwsA(predicate((final e) => (e! as DynamiteApiException).statusCode == 401)),
);
test('Get dark', () async {
final response = await client.core.avatar.getAvatarDark(userId: 'admin', size: 32);
expect(response.body, isNotEmpty);
});
});
test('Unified search providers', () async {
final response = await client.core.unifiedSearch.getProviders();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data, hasLength(14));
group('App password', () {
test('Delete', () async {
await client.core.appPassword.deleteAppPassword();
expect(
() => client.core.appPassword.deleteAppPassword(),
throwsA(predicate((final e) => (e! as DynamiteApiException).statusCode == 401)),
);
});
});
test('Unified search', () async {
final response = await client.core.unifiedSearch.search(
providerId: 'settings',
term: 'Personal info',
);
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
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);
group('Unified search', () {
test('Get providers', () async {
final response = await client.core.unifiedSearch.getProviders();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data, hasLength(14));
});
test('Search', () async {
final response = await client.core.unifiedSearch.search(
providerId: 'settings',
term: 'Personal info',
);
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
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 {
final response = await client.core.clientFlowLoginV2.init();
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.poll.token, isNotEmpty);
expect(
() => client.core.clientFlowLoginV2.poll(token: response.body.poll.token),
throwsA(predicate<DynamiteApiException>((final e) => e.statusCode == 404)),
);
group('Client login flow V2', () {
test('Init and poll', () async {
final response = await client.core.clientFlowLoginV2.init();
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.poll.token, isNotEmpty);
expect(
() => client.core.clientFlowLoginV2.poll(token: response.body.poll.token),
throwsA(predicate<DynamiteApiException>((final e) => e.statusCode == 404)),
);
});
});
},
retry: retryCount,

135
packages/nextcloud/test/notifications_test.dart

@ -29,79 +29,80 @@ void main() {
);
}
test('Send admin notification', () async {
await sendTestNotification();
group('API', () {
test('Send admin notification', () async {
await sendTestNotification();
});
});
test('List notifications', () async {
await sendTestNotification();
final startTime = DateTime.now().toUtc();
final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data, hasLength(2));
expect(response.ocs.data[0].notificationId, 2);
expect(response.ocs.data[0].app, 'admin_notifications');
expect(response.ocs.data[0].user, 'admin');
expectDateInReasonableTimeRange(DateTime.parse(response.ocs.data[0].datetime), startTime);
expect(response.ocs.data[0].objectType, 'admin_notifications');
expect(response.ocs.data[0].objectId, isNotNull);
expect(response.ocs.data[0].subject, '123');
expect(response.ocs.data[0].message, '456');
expect(response.ocs.data[0].link, '');
expect(response.ocs.data[0].subjectRich, '');
expect(response.ocs.data[0].subjectRichParameters, isEmpty);
expect(response.ocs.data[0].messageRich, '');
expect(response.ocs.data[0].messageRichParameters, isEmpty);
expect(response.ocs.data[0].icon, isNotEmpty);
expect(response.ocs.data[0].actions, hasLength(0));
});
group('Endpoint', () {
test('List notifications', () async {
await sendTestNotification();
final startTime = DateTime.now().toUtc();
final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data, hasLength(2));
expect(response.ocs.data[0].notificationId, 2);
expect(response.ocs.data[0].app, 'admin_notifications');
expect(response.ocs.data[0].user, 'admin');
expectDateInReasonableTimeRange(DateTime.parse(response.ocs.data[0].datetime), startTime);
expect(response.ocs.data[0].objectType, 'admin_notifications');
expect(response.ocs.data[0].objectId, isNotNull);
expect(response.ocs.data[0].subject, '123');
expect(response.ocs.data[0].message, '456');
expect(response.ocs.data[0].link, '');
expect(response.ocs.data[0].subjectRich, '');
expect(response.ocs.data[0].subjectRichParameters, isEmpty);
expect(response.ocs.data[0].messageRich, '');
expect(response.ocs.data[0].messageRichParameters, isEmpty);
expect(response.ocs.data[0].icon, isNotEmpty);
expect(response.ocs.data[0].actions, hasLength(0));
});
test('Get notification', () async {
await sendTestNotification();
final startTime = DateTime.now().toUtc();
final response = await client.notifications.endpoint.getNotification(id: 2);
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.notificationId, 2);
expect(response.body.ocs.data.app, 'admin_notifications');
expect(response.body.ocs.data.user, 'admin');
expectDateInReasonableTimeRange(DateTime.parse(response.body.ocs.data.datetime), startTime);
expect(response.body.ocs.data.objectType, 'admin_notifications');
expect(response.body.ocs.data.objectId, isNotNull);
expect(response.body.ocs.data.subject, '123');
expect(response.body.ocs.data.message, '456');
expect(response.body.ocs.data.link, '');
expect(response.body.ocs.data.subjectRich, '');
expect(response.body.ocs.data.subjectRichParameters, isEmpty);
expect(response.body.ocs.data.messageRich, '');
expect(response.body.ocs.data.messageRichParameters, isEmpty);
expect(response.body.ocs.data.icon, isNotEmpty);
expect(response.body.ocs.data.actions, hasLength(0));
});
test('Get notification', () async {
await sendTestNotification();
final startTime = DateTime.now().toUtc();
final response = await client.notifications.endpoint.getNotification(id: 2);
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data.notificationId, 2);
expect(response.body.ocs.data.app, 'admin_notifications');
expect(response.body.ocs.data.user, 'admin');
expectDateInReasonableTimeRange(DateTime.parse(response.body.ocs.data.datetime), startTime);
expect(response.body.ocs.data.objectType, 'admin_notifications');
expect(response.body.ocs.data.objectId, isNotNull);
expect(response.body.ocs.data.subject, '123');
expect(response.body.ocs.data.message, '456');
expect(response.body.ocs.data.link, '');
expect(response.body.ocs.data.subjectRich, '');
expect(response.body.ocs.data.subjectRichParameters, isEmpty);
expect(response.body.ocs.data.messageRich, '');
expect(response.body.ocs.data.messageRichParameters, isEmpty);
expect(response.body.ocs.data.icon, isNotEmpty);
expect(response.body.ocs.data.actions, hasLength(0));
});
test('Delete notification', () async {
await sendTestNotification();
await client.notifications.endpoint.deleteNotification(id: 2);
test('Delete notification', () async {
await sendTestNotification();
await client.notifications.endpoint.deleteNotification(id: 2);
final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data, hasLength(1));
});
final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data, hasLength(1));
});
test('Delete all notifications', () async {
await sendTestNotification();
await sendTestNotification();
await client.notifications.endpoint.deleteAllNotifications();
test('Delete all notifications', () async {
await sendTestNotification();
await sendTestNotification();
await client.notifications.endpoint.deleteAllNotifications();
final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data, hasLength(0));
final response = (await client.notifications.endpoint.listNotifications()).body;
expect(response.ocs.data, hasLength(0));
});
});
});
group(
'push notifications',
() {
group('Push', () {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
@ -139,8 +140,6 @@ void main() {
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', () {
test('Get apps', () async {
test('Get', () async {
final response = await client.provisioningApi.apps.getApps();
expect(response.statusCode, 200);
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());
test('Download log file', () async {
final response = await client.settings.logSettings.download();
final logs = utf8.decode(response.body);
expect(logs, await container.nextcloudLogs());
group('Logs', () {
test('Download', () async {
final response = await client.settings.logSettings.download();
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());
test('Find all predefined statuses', () async {
final expectedStatusIDs = ['meeting', 'commuting', 'remote-work', 'sick-leave', 'vacationing'];
final response = await client.userStatus.predefinedStatus.findAll();
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(expectedStatusIDs.map(responseIDs.contains).contains(false), false);
for (final status in response.body.ocs.data) {
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);
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);
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);
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);
expect(sickLeave.time.clearAtTimeType, user_status.ClearAtTimeType.day);
final vacationing = response.body.ocs.data.singleWhere((final s) => s.id == 'vacationing').clearAt;
expect(vacationing, null);
group('Predefined status', () {
test('Find all', () async {
final expectedStatusIDs = ['meeting', 'commuting', 'remote-work', 'sick-leave', 'vacationing'];
final response = await client.userStatus.predefinedStatus.findAll();
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(expectedStatusIDs.map(responseIDs.contains).contains(false), false);
for (final status in response.body.ocs.data) {
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);
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);
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);
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);
expect(sickLeave.time.clearAtTimeType, user_status.ClearAtTimeType.day);
final vacationing = response.body.ocs.data.singleWhere((final s) => s.id == 'vacationing').clearAt;
expect(vacationing, null);
});
});
test('Set status', () async {
final response = await client.userStatus.userStatus.setStatus(statusType: '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, true);
group('User status', () {
test('Set', () async {
final response = await client.userStatus.userStatus.setStatus(statusType: '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, 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 {
// 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);
group('Statuses', () {
test('Find all', () async {
var response = await client.userStatus.statuses.findAll();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data, hasLength(0));
await client.userStatus.userStatus.setStatus(statusType: 'online');
response = await client.userStatus.statuses.findAll();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data, hasLength(1));
expect(response.body.ocs.data[0].userId, 'user1');
expect(response.body.ocs.data[0].message, null);
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 all statuses', () async {
var response = await client.userStatus.statuses.findAll();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data, hasLength(0));
await client.userStatus.userStatus.setStatus(statusType: 'online');
response = await client.userStatus.statuses.findAll();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());
expect(response.body.ocs.data, hasLength(1));
expect(response.body.ocs.data[0].userId, 'user1');
expect(response.body.ocs.data[0].message, null);
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);
group('Heartbeat', () {
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,

Loading…
Cancel
Save