Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to latest dependencies, added tests #2

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
74 changes: 58 additions & 16 deletions test/sails_io_test.dart
Original file line number Diff line number Diff line change
@@ -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
}