A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
7.9 KiB

3 years ago
import 'package:nextcloud/nextcloud.dart';
import 'package:test/test.dart';
import 'helper.dart';
Future main() async {
final dockerImageName = await TestHelper.prepareDockerImage();
group('user_status', () {
late TestNextcloudClient client;
setUp(() async {
client = await TestHelper.getPreparedClient(dockerImageName);
});
tearDown(() => client.destroy());
test('Find all predefined statuses', () async {
final expectedStatusIDs = ['meeting', 'commuting', 'remote-work', 'sick-leave', 'vacationing'];
final response = await client.userStatus.findAllPredefinedStatuses();
3 years ago
expect(response.ocs!.data, hasLength(5));
final responseIDs = response.ocs!.data!.map((final status) => status.id!);
3 years ago
expect(expectedStatusIDs.map(responseIDs.contains).contains(false), false);
for (final status in response.ocs!.data!) {
3 years ago
expect(status.icon, isNotNull);
expect(status.message, isNotNull);
}
final meeting = response.ocs!.data!.singleWhere((final s) => s.id == 'meeting').clearAt!.userStatusClearAt!;
expect(meeting.type, UserStatusClearAtType.period);
expect(meeting.time!.int_, 3600);
3 years ago
final commuting = response.ocs!.data!.singleWhere((final s) => s.id == 'commuting').clearAt!.userStatusClearAt!;
expect(commuting.type, UserStatusClearAtType.period);
expect(commuting.time!.int_, 1800);
3 years ago
final remoteWork =
response.ocs!.data!.singleWhere((final s) => s.id == 'remote-work').clearAt!.userStatusClearAt!;
expect(remoteWork.type, UserStatusClearAtType.endOf);
expect(remoteWork.time!.userStatusClearAtTime0, UserStatusClearAtTime0.day);
3 years ago
final sickLeave = response.ocs!.data!.singleWhere((final s) => s.id == 'sick-leave').clearAt!.userStatusClearAt!;
expect(sickLeave.type, UserStatusClearAtType.endOf);
expect(sickLeave.time!.userStatusClearAtTime0, UserStatusClearAtTime0.day);
3 years ago
expect(response.ocs!.data!.singleWhere((final s) => s.id == 'vacationing').clearAt, null);
3 years ago
});
test('Set status', () async {
final response = await client.userStatus.setStatus(statusType: UserStatusType.online);
expect(response.ocs!.data!.userStatus!.userId, 'test');
expect(response.ocs!.data!.userStatus!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
expect(response.ocs!.data!.userStatus!.icon, null);
expect(response.ocs!.data!.userStatus!.clearAt, null);
expect(response.ocs!.data!.userStatus!.status, UserStatusType.online);
expect(response.ocs!.data!.userStatus!.statusIsUserDefined, true);
3 years ago
});
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.setStatus(statusType: UserStatusType.online);
final response = await client.userStatus.getStatus();
expect(response.ocs!.data!.userStatus!.userId, 'test');
expect(response.ocs!.data!.userStatus!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
expect(response.ocs!.data!.userStatus!.icon, null);
expect(response.ocs!.data!.userStatus!.clearAt, null);
expect(response.ocs!.data!.userStatus!.status, UserStatusType.online);
expect(response.ocs!.data!.userStatus!.statusIsUserDefined, true);
3 years ago
});
test('Find all statuses', () async {
var response = await client.userStatus.findAllStatuses();
3 years ago
expect(response.ocs!.data, hasLength(0));
await client.userStatus.setStatus(statusType: UserStatusType.online);
3 years ago
response = await client.userStatus.findAllStatuses();
3 years ago
expect(response.ocs!.data, hasLength(1));
expect(response.ocs!.data![0].userId, 'test');
expect(response.ocs!.data![0].message, null);
expect(response.ocs!.data![0].icon, null);
expect(response.ocs!.data![0].clearAt, null);
expect(response.ocs!.data![0].status, UserStatusType.online);
3 years ago
});
test('Find status', () async {
// Same as getting status
await client.userStatus.setStatus(statusType: UserStatusType.online);
3 years ago
final response = await client.userStatus.findStatus(userId: 'test');
expect(response.ocs!.data!.userStatusPublicUserStatus!.userId, 'test');
expect(response.ocs!.data!.userStatusPublicUserStatus!.message, null);
expect(response.ocs!.data!.userStatusPublicUserStatus!.icon, null);
expect(response.ocs!.data!.userStatusPublicUserStatus!.clearAt, null);
expect(response.ocs!.data!.userStatusPublicUserStatus!.status, UserStatusType.online);
3 years ago
});
test('Set predefined message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
final response = await client.userStatus.setPredefinedMessage(
messageId: 'meeting',
clearAt: clearAt,
);
expect(response.ocs!.data!.userStatus!.userId, 'test');
expect(response.ocs!.data!.userStatus!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, 'meeting');
expect(response.ocs!.data!.userStatus!.messageIsPredefined, true);
expect(response.ocs!.data!.userStatus!.icon, null);
expect(response.ocs!.data!.userStatus!.clearAt!.int_, clearAt);
expect(response.ocs!.data!.userStatus!.status, UserStatusType.offline);
expect(response.ocs!.data!.userStatus!.statusIsUserDefined, false);
3 years ago
});
test('Set custom message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
final response = await client.userStatus.setCustomMessage(
statusIcon: '😀',
message: 'bla',
clearAt: clearAt,
);
expect(response.ocs!.data!.userStatus!.userId, 'test');
expect(response.ocs!.data!.userStatus!.message, 'bla');
expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
expect(response.ocs!.data!.userStatus!.icon, '😀');
expect(response.ocs!.data!.userStatus!.clearAt!.int_, clearAt);
expect(response.ocs!.data!.userStatus!.status, UserStatusType.offline);
expect(response.ocs!.data!.userStatus!.statusIsUserDefined, false);
3 years ago
});
test('Clear message', () async {
final clearAt = DateTime.now().millisecondsSinceEpoch ~/ 1000 + 60;
await client.userStatus.setCustomMessage(
statusIcon: '😀',
message: 'bla',
clearAt: clearAt,
3 years ago
);
await client.userStatus.clearMessage();
final response = await client.userStatus.getStatus();
expect(response.ocs!.data!.userStatus!.userId, 'test');
expect(response.ocs!.data!.userStatus!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
expect(response.ocs!.data!.userStatus!.icon, null);
expect(response.ocs!.data!.userStatus!.clearAt, null);
expect(response.ocs!.data!.userStatus!.status, UserStatusType.offline);
expect(response.ocs!.data!.userStatus!.statusIsUserDefined, false);
3 years ago
});
test('Heartbeat', () async {
await client.userStatus.heartbeat(status: UserStatusType.online);
final response = await client.userStatus.getStatus();
expect(response.ocs!.data!.userStatus!.userId, 'test');
expect(response.ocs!.data!.userStatus!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
expect(response.ocs!.data!.userStatus!.icon, null);
expect(response.ocs!.data!.userStatus!.clearAt, null);
expect(response.ocs!.data!.userStatus!.status, UserStatusType.online);
expect(response.ocs!.data!.userStatus!.statusIsUserDefined, false);
3 years ago
});
});
}