Skip to content

Commit

Permalink
Added integration test for realtime time function
Browse files Browse the repository at this point in the history
  • Loading branch information
ikurek committed Feb 14, 2022
1 parent 00da9dd commit 7d36455
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test_integration/lib/config/test_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:ably_flutter_integration_test/test/realtime/realtime_presence_su
import 'package:ably_flutter_integration_test/test/realtime/realtime_publish_test.dart';
import 'package:ably_flutter_integration_test/test/realtime/realtime_publish_with_auth_callback_test.dart';
import 'package:ably_flutter_integration_test/test/realtime/realtime_subscribe.dart';
import 'package:ably_flutter_integration_test/test/realtime/realtime_time_test.dart';
import 'package:ably_flutter_integration_test/test/rest/rest_capability_test.dart';
import 'package:ably_flutter_integration_test/test/rest/rest_history_test.dart';
import 'package:ably_flutter_integration_test/test/rest/rest_presence_get_test.dart';
Expand Down Expand Up @@ -43,6 +44,7 @@ final testFactory = <String, TestFactory>{
TestName.realtimeSubscribe: testRealtimeSubscribe,
TestName.realtimePublishWithAuthCallback: testRealtimePublishWithAuthCallback,
TestName.realtimeHistory: testRealtimeHistory,
TestName.realtimeTime: testRealtimeTime,
TestName.realtimePresenceGet: testRealtimePresenceGet,
TestName.realtimePresenceHistory: testRealtimePresenceHistory,
TestName.realtimePresenceEnterUpdateLeave:
Expand Down
1 change: 1 addition & 0 deletions test_integration/lib/config/test_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TestName {
static const String realtimeEvents = 'realtimeEvents';
static const String realtimeSubscribe = 'realtimeSubscribe';
static const String realtimeHistory = 'realtimeHistory';
static const String realtimeTime = 'realtimeTime';
static const String realtimePublishWithAuthCallback =
'realtimePublishWithAuthCallback';
static const String realtimePresenceGet = 'realtimePresenceGet';
Expand Down
28 changes: 28 additions & 0 deletions test_integration/lib/test/realtime/realtime_time_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:ably_flutter/ably_flutter.dart';
import 'package:ably_flutter_integration_test/factory/reporter.dart';
import 'package:ably_flutter_integration_test/provisioning.dart';

Future<Map<String, dynamic>> testRealtimeTime({
required Reporter reporter,
Map<String, dynamic>? payload,
}) async {
reporter.reportLog('init start');
final appKey = await provision('sandbox-');
final logMessages = <List<String?>>[];

final realtime = Realtime(
options: ClientOptions.fromKey(appKey.toString())
..environment = 'sandbox'
..clientId = 'someClientId'
..logLevel = LogLevel.verbose
..logHandler =
({msg, exception}) => logMessages.add([msg, exception.toString()]),
);

final realtimeTime = await realtime.time();

return {
'handle': await realtime.handle,
'time': realtimeTime.toIso8601String(),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,23 @@ void testRealtimeHistory(FlutterDriver Function() getDriver) {
});
}

void testRealtimeTime(FlutterDriver Function() getDriver) {
const message = TestControlMessage(TestName.realtimeTime);
late TestControlResponseMessage response;
late DateTime realtimeTime;

setUpAll(() async {
response = await requestDataForTest(getDriver(), message);
realtimeTime = DateTime.parse(response.payload['time'] as String);
});

group('realtime#time', () {
test('returns non-zero date and time', () {
expect(realtimeTime.millisecondsSinceEpoch, isNot(0));
});
});
}

void testRealtimePresenceGet(FlutterDriver Function() getDriver) {
const message = TestControlMessage(TestName.realtimePresenceGet);
late TestControlResponseMessage response;
Expand Down
1 change: 1 addition & 0 deletions test_integration/test_driver/tests_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final _tests =
'should subscribe to connection and channel': testRealtimeEvents,
'should subscribe to messages': testRealtimeSubscribe,
'should retrieve history': testRealtimeHistory,
'should retrieve time': testRealtimeTime,
'realtime#channels#channel#presence#get': testRealtimePresenceGet,
'realtime#channels#channel#presence#history': testRealtimePresenceHistory,
'should enter, update and leave Presence': testRealtimeEnterUpdateLeave,
Expand Down

0 comments on commit 7d36455

Please sign in to comment.