From 272f922a5a436dabc12b65ee1922b3d4fa35a2a0 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 26 Nov 2023 13:34:23 +0100 Subject: [PATCH] chore(nextcloud): Remove custom date range expect function Signed-off-by: jld3103 --- packages/nextcloud/test/helper.dart | 6 ---- .../nextcloud/test/notifications_test.dart | 10 +++++-- packages/nextcloud/test/spreed_test.dart | 30 ++++--------------- packages/nextcloud/test/webdav_test.dart | 14 ++++++--- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/packages/nextcloud/test/helper.dart b/packages/nextcloud/test/helper.dart index a0e04b65..5723bcb6 100644 --- a/packages/nextcloud/test/helper.dart +++ b/packages/nextcloud/test/helper.dart @@ -207,9 +207,3 @@ Future getDockerContainer() async { } 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); -} diff --git a/packages/nextcloud/test/notifications_test.dart b/packages/nextcloud/test/notifications_test.dart index 0520bf84..ad3580c3 100644 --- a/packages/nextcloud/test/notifications_test.dart +++ b/packages/nextcloud/test/notifications_test.dart @@ -42,7 +42,10 @@ void main() { 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( + 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].objectId, isNotNull); 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.app, 'admin_notifications'); 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.objectId, isNotNull); expect(response.body.ocs.data.subject, '123'); diff --git a/packages/nextcloud/test/spreed_test.dart b/packages/nextcloud/test/spreed_test.dart index 84ad5773..bbc7f5e2 100644 --- a/packages/nextcloud/test/spreed_test.dart +++ b/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!.actorId, 'user1'); expect(response.body.ocs.data!.actorDisplayName, 'User One'); - expectDateInReasonableTimeRange( - DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data!.timestamp * 1000), - startTime, - ); + expect(response.body.ocs.data!.timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3)); expect(response.body.ocs.data!.message, 'bla'); 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].actorId, 'user1'); expect(response.body.ocs.data[0].actorDisplayName, 'User One'); - expectDateInReasonableTimeRange( - DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[0].timestamp * 1000), - startTime, - ); + expect(response.body.ocs.data[0].timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3)); expect(response.body.ocs.data[0].message, '123'); 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!.actorId, 'user1'); expect(response.body.ocs.data[0].parent!.actorDisplayName, 'User One'); - expectDateInReasonableTimeRange( - DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[0].parent!.timestamp * 1000), - startTime, - ); + expect(response.body.ocs.data[0].parent!.timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3)); expect(response.body.ocs.data[0].parent!.message, 'bla'); 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].actorId, 'user1'); expect(response.body.ocs.data[1].actorDisplayName, 'User One'); - expectDateInReasonableTimeRange( - DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[1].timestamp * 1000), - startTime, - ); + expect(response.body.ocs.data[1].timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3)); expect(response.body.ocs.data[1].message, 'bla'); 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].actorId, 'user1'); expect(response.body.ocs.data[2].actorDisplayName, 'User One'); - expectDateInReasonableTimeRange( - DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[2].timestamp * 1000), - startTime, - ); + expect(response.body.ocs.data[2].timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3)); 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].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].actorId, 'user1'); expect(response.body.ocs.data[0].actorDisplayName, 'User One'); - expectDateInReasonableTimeRange( - DateTime.fromMillisecondsSinceEpoch(response.body.ocs.data[0].timestamp * 1000), - startTime, - ); + expect(response.body.ocs.data[0].timestamp * 1000, closeTo(startTime.millisecondsSinceEpoch, 10E3)); expect(response.body.ocs.data[0].message, '123'); expect(response.body.ocs.data[0].messageType, spreed.MessageType.comment.name); }); diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index 2155aca1..b5f030b0 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/packages/nextcloud/test/webdav_test.dart @@ -281,12 +281,18 @@ void main() { expect(response.isCollection, isTrue); expect(response.mimeType, isNull); 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.isDirectory, isTrue); 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.ocsize, data.lengthInBytes); }); @@ -355,8 +361,8 @@ void main() { .prop; expect(props.ocfavorite, 1); expect(webdavDateFormat.parseUtc(props.davgetlastmodified!), lastModifiedDate); - expect(DateTime.fromMillisecondsSinceEpoch(props.nccreationtime! * 1000).isAtSameMomentAs(createdDate), isTrue); - expectDateInReasonableTimeRange(DateTime.fromMillisecondsSinceEpoch(props.ncuploadtime! * 1000), uploadTime); + expect(props.nccreationtime! * 1000, createdDate.millisecondsSinceEpoch); + expect(props.ncuploadtime! * 1000, closeTo(uploadTime.millisecondsSinceEpoch, 10E3)); }); test('Remove properties', () async {