diff --git a/CHANGELOG.md b/CHANGELOG.md index e227c57..0a9c00e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,4 +3,9 @@ - Initial version. ## 0.0.2 + - Made `data`, `headers` and `cb` optional for virtual requests + +## 0.0.3 + +- Updated to socket_io_client: ^2.0.2 diff --git a/pubspec.yaml b/pubspec.yaml index 2af466d..fa93885 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,13 +1,13 @@ name: sails_io -version: 0.0.2 +version: 0.0.3 homepage: https://github.com/sailscastshq/sails_io description: Dart/Flutter Websocket Client SDK for communication with Sails from a mobile application. environment: sdk: ">=2.13.0 <3.0.0" dependencies: - socket_io_client: ^1.0.1 + socket_io_client: ^2.0.2 dev_dependencies: pedantic: ^1.10.0 - test: ^1.16.0 + test: ^1.24.3 diff --git a/test/sails_io_test.dart b/test/sails_io_test.dart index 3b70e01..99ad1e6 100644 --- a/test/sails_io_test.dart +++ b/test/sails_io_test.dart @@ -1,16 +1,58 @@ -// import 'package:sails_io/sails_io.dart'; -// import 'package:test/test.dart'; - -// void main() { -// group('A group of tests', () { -// final awesome = Awesome(); - -// setUp(() { -// // Additional setup goes here. -// }); - -// test('First Test', () { -// expect(awesome.isAwesome, isTrue); -// }); -// }); -// } +import 'package:socket_io_client/socket_io_client.dart' as io; +import 'package:sails_io/sails_io.dart'; +import 'package:test/test.dart'; +import 'dart:async'; + +// Work in progress...SNM + +void main() { + // Create an instance of SailsIOClient + late SailsIOClient sailsIOClient; + + // Set up the test case + setUp(() { + // Create a mock SocketIOClient + final mockSocket = io.io( + 'http://localhost:1337', + io.OptionBuilder().setTransports(['websocket']) + // .disableAutoConnect() + .build()); + + // Initialize SailsIOClient with the mock socket + sailsIOClient = SailsIOClient(mockSocket); + + // socket.connect(); + + sailsIOClient.socket.onConnect((_) { + sailsIOClient.socket.emit('toServer', 'init'); + + var count = 0; + Timer.periodic(const Duration(seconds: 1), (Timer countDownTimer) { + sailsIOClient.socket.emit('toServer', count++); + }); + }); + + sailsIOClient.socket.on('event', (data) => print(data)); + sailsIOClient.socket.on('disconnect', (_) => print('disconnect')); + sailsIOClient.socket.on('fromServer', (_) => print(_)); + }); + + // Define your test cases + test('GET request should be simulated', () { + // Create a mock callback function + void mockCallback(dynamic body, JWR jwr) { + // Assert the response body or any other expectations + expect(body, isNotNull); + expect(jwr.statusCode, equals(200)); + } + + // Simulate a GET request using SailsIOClient + sailsIOClient.get( + url: 'https://example.com', + headers: {'Content-Type': 'application/json'}, + cb: mockCallback, + ); + }); + + // Add more test cases for other methods if needed +}