Browse Source

chore(nextcloud): Remove custom date range expect function

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/1185/head
jld3103 1 year ago
parent
commit
272f922a5a
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 6
      packages/nextcloud/test/helper.dart
  2. 10
      packages/nextcloud/test/notifications_test.dart
  3. 30
      packages/nextcloud/test/spreed_test.dart
  4. 14
      packages/nextcloud/test/webdav_test.dart

6
packages/nextcloud/test/helper.dart

@ -207,9 +207,3 @@ Future<DockerContainer> getDockerContainer() async {
} }
int randomPort() => 1024 + Random().nextInt(65535 - 1024); int randomPort() => 1024 + Random().nextInt(65535 - 1024);
void expectDateInReasonableTimeRange(final DateTime actual, final DateTime expected) {
const duration = Duration(seconds: 10);
expect(actual.isAfter(expected.subtract(duration)), isTrue);
expect(actual.isBefore(expected.add(duration)), isTrue);
}

10
packages/nextcloud/test/notifications_test.dart

@ -42,7 +42,10 @@ void main() {
expect(response.ocs.data[0].notificationId, 2); expect(response.ocs.data[0].notificationId, 2);
expect(response.ocs.data[0].app, 'admin_notifications'); expect(response.ocs.data[0].app, 'admin_notifications');
expect(response.ocs.data[0].user, 'admin'); expect(response.ocs.data[0].user, 'admin');
expectDateInReasonableTimeRange(DateTime.parse(response.ocs.data[0].datetime), startTime); expect(
DateTime.parse(response.ocs.data[0].datetime).millisecondsSinceEpoch,
closeTo(startTime.millisecondsSinceEpoch, 10E3),
);
expect(response.ocs.data[0].objectType, 'admin_notifications'); expect(response.ocs.data[0].objectType, 'admin_notifications');
expect(response.ocs.data[0].objectId, isNotNull); expect(response.ocs.data[0].objectId, isNotNull);
expect(response.ocs.data[0].subject, '123'); expect(response.ocs.data[0].subject, '123');
@ -67,7 +70,10 @@ void main() {
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); expect(
DateTime.parse(response.body.ocs.data.datetime).millisecondsSinceEpoch,
closeTo(startTime.millisecondsSinceEpoch, 10E3),
);
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');

30
packages/nextcloud/test/spreed_test.dart

@ -183,10 +183,7 @@ void main() {
expect(response.body.ocs.data!.actorType, spreed.ActorType.users.name); expect(response.body.ocs.data!.actorType, spreed.ActorType.users.name);
expect(response.body.ocs.data!.actorId, 'user1'); expect(response.body.ocs.data!.actorId, 'user1');
expect(response.body.ocs.data!.actorDisplayName, 'User One'); expect(response.body.ocs.data!.actorDisplayName, 'User One');
expectDateInReasonableTimeRange( expect(response.body.ocs.data!.timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3));
DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data!.timestamp * 1000),
startTime,
);
expect(response.body.ocs.data!.message, 'bla'); expect(response.body.ocs.data!.message, 'bla');
expect(response.body.ocs.data!.messageType, spreed.MessageType.comment.name); expect(response.body.ocs.data!.messageType, spreed.MessageType.comment.name);
}); });
@ -227,10 +224,7 @@ void main() {
expect(response.body.ocs.data[0].actorType, spreed.ActorType.users.name); expect(response.body.ocs.data[0].actorType, spreed.ActorType.users.name);
expect(response.body.ocs.data[0].actorId, 'user1'); expect(response.body.ocs.data[0].actorId, 'user1');
expect(response.body.ocs.data[0].actorDisplayName, 'User One'); expect(response.body.ocs.data[0].actorDisplayName, 'User One');
expectDateInReasonableTimeRange( expect(response.body.ocs.data[0].timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3));
DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[0].timestamp * 1000),
startTime,
);
expect(response.body.ocs.data[0].message, '123'); expect(response.body.ocs.data[0].message, '123');
expect(response.body.ocs.data[0].messageType, spreed.MessageType.comment.name); expect(response.body.ocs.data[0].messageType, spreed.MessageType.comment.name);
@ -238,10 +232,7 @@ void main() {
expect(response.body.ocs.data[0].parent!.actorType, spreed.ActorType.users.name); expect(response.body.ocs.data[0].parent!.actorType, spreed.ActorType.users.name);
expect(response.body.ocs.data[0].parent!.actorId, 'user1'); expect(response.body.ocs.data[0].parent!.actorId, 'user1');
expect(response.body.ocs.data[0].parent!.actorDisplayName, 'User One'); expect(response.body.ocs.data[0].parent!.actorDisplayName, 'User One');
expectDateInReasonableTimeRange( expect(response.body.ocs.data[0].parent!.timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3));
DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[0].parent!.timestamp * 1000),
startTime,
);
expect(response.body.ocs.data[0].parent!.message, 'bla'); expect(response.body.ocs.data[0].parent!.message, 'bla');
expect(response.body.ocs.data[0].parent!.messageType, spreed.MessageType.comment.name); expect(response.body.ocs.data[0].parent!.messageType, spreed.MessageType.comment.name);
@ -249,10 +240,7 @@ void main() {
expect(response.body.ocs.data[1].actorType, spreed.ActorType.users.name); expect(response.body.ocs.data[1].actorType, spreed.ActorType.users.name);
expect(response.body.ocs.data[1].actorId, 'user1'); expect(response.body.ocs.data[1].actorId, 'user1');
expect(response.body.ocs.data[1].actorDisplayName, 'User One'); expect(response.body.ocs.data[1].actorDisplayName, 'User One');
expectDateInReasonableTimeRange( expect(response.body.ocs.data[1].timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3));
DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[1].timestamp * 1000),
startTime,
);
expect(response.body.ocs.data[1].message, 'bla'); expect(response.body.ocs.data[1].message, 'bla');
expect(response.body.ocs.data[1].messageType, spreed.MessageType.comment.name); expect(response.body.ocs.data[1].messageType, spreed.MessageType.comment.name);
@ -260,10 +248,7 @@ void main() {
expect(response.body.ocs.data[2].actorType, spreed.ActorType.users.name); expect(response.body.ocs.data[2].actorType, spreed.ActorType.users.name);
expect(response.body.ocs.data[2].actorId, 'user1'); expect(response.body.ocs.data[2].actorId, 'user1');
expect(response.body.ocs.data[2].actorDisplayName, 'User One'); expect(response.body.ocs.data[2].actorDisplayName, 'User One');
expectDateInReasonableTimeRange( expect(response.body.ocs.data[2].timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3));
DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[2].timestamp * 1000),
startTime,
);
expect(response.body.ocs.data[2].message, 'You created the conversation'); expect(response.body.ocs.data[2].message, 'You created the conversation');
expect(response.body.ocs.data[2].systemMessage, 'conversation_created'); expect(response.body.ocs.data[2].systemMessage, 'conversation_created');
expect(response.body.ocs.data[2].messageType, spreed.MessageType.system.name); expect(response.body.ocs.data[2].messageType, spreed.MessageType.system.name);
@ -300,10 +285,7 @@ void main() {
expect(response.body.ocs.data[0].actorType, spreed.ActorType.users.name); expect(response.body.ocs.data[0].actorType, spreed.ActorType.users.name);
expect(response.body.ocs.data[0].actorId, 'user1'); expect(response.body.ocs.data[0].actorId, 'user1');
expect(response.body.ocs.data[0].actorDisplayName, 'User One'); expect(response.body.ocs.data[0].actorDisplayName, 'User One');
expectDateInReasonableTimeRange( expect(response.body.ocs.data[0].timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3));
DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[0].timestamp * 1000),
startTime,
);
expect(response.body.ocs.data[0].message, '123'); expect(response.body.ocs.data[0].message, '123');
expect(response.body.ocs.data[0].messageType, spreed.MessageType.comment.name); expect(response.body.ocs.data[0].messageType, spreed.MessageType.comment.name);
}); });

14
packages/nextcloud/test/webdav_test.dart

@ -281,12 +281,18 @@ void main() {
expect(response.isCollection, isTrue); expect(response.isCollection, isTrue);
expect(response.mimeType, isNull); expect(response.mimeType, isNull);
expect(response.size, data.lengthInBytes); expect(response.size, data.lengthInBytes);
expectDateInReasonableTimeRange(response.lastModified!, DateTime.now()); expect(
response.lastModified!.millisecondsSinceEpoch,
closeTo(DateTime.now().millisecondsSinceEpoch, 10E3),
);
expect(response.name, 'test'); expect(response.name, 'test');
expect(response.isDirectory, isTrue); expect(response.isDirectory, isTrue);
expect(response.props.davgetcontenttype, isNull); expect(response.props.davgetcontenttype, isNull);
expectDateInReasonableTimeRange(webdavDateFormat.parseUtc(response.props.davgetlastmodified!), DateTime.now()); expect(
webdavDateFormat.parseUtc(response.props.davgetlastmodified!).millisecondsSinceEpoch,
closeTo(DateTime.now().millisecondsSinceEpoch, 10E3),
);
expect(response.props.davresourcetype!.collection, isNotNull); expect(response.props.davresourcetype!.collection, isNotNull);
expect(response.props.ocsize, data.lengthInBytes); expect(response.props.ocsize, data.lengthInBytes);
}); });
@ -355,8 +361,8 @@ void main() {
.prop; .prop;
expect(props.ocfavorite, 1); expect(props.ocfavorite, 1);
expect(webdavDateFormat.parseUtc(props.davgetlastmodified!), lastModifiedDate); expect(webdavDateFormat.parseUtc(props.davgetlastmodified!), lastModifiedDate);
expect(DateTime.fromMillisecondsSinceEpoch(props.nccreationtime! * 1000).isAtSameMomentAs(createdDate), isTrue); expect(props.nccreationtime! * 1000, createdDate.millisecondsSinceEpoch);
expectDateInReasonableTimeRange(DateTime.fromMillisecondsSinceEpoch(props.ncuploadtime! * 1000), uploadTime); expect(props.ncuploadtime! * 1000, closeTo(uploadTime.millisecondsSinceEpoch, 10E3));
}); });
test('Remove properties', () async { test('Remove properties', () async {

Loading…
Cancel
Save