platform/packages/websocket/test/service/common.dart

36 lines
893 B
Dart
Raw Normal View History

2019-05-01 22:58:47 +00:00
import 'dart:async';
2021-05-15 07:19:35 +00:00
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_model/angel3_model.dart';
import 'package:angel3_websocket/base_websocket_client.dart';
import 'package:angel3_websocket/server.dart';
2016-12-23 20:57:46 +00:00
import 'package:test/test.dart';
2017-02-22 22:34:35 +00:00
class Todo extends Model {
2021-04-26 00:47:32 +00:00
String? text;
String? when;
2016-12-23 20:57:46 +00:00
2021-04-10 15:12:43 +00:00
Todo({this.text, this.when});
2016-12-23 20:57:46 +00:00
}
2018-08-28 14:17:14 +00:00
class TodoService extends MapService {
TodoService() : super() {
2018-10-02 15:32:06 +00:00
configuration['ws:filter'] =
(HookedServiceEvent e, WebSocketContext socket) {
2017-04-10 01:45:45 +00:00
print('Hello, service filter world!');
return true;
};
}
2017-02-28 14:15:34 +00:00
}
2016-12-23 20:57:46 +00:00
2021-04-10 15:12:43 +00:00
dynamic testIndex(BaseWebSocketClient client) async {
2018-08-28 14:17:14 +00:00
var todoService = client.service('api/todos');
2019-05-01 22:58:47 +00:00
scheduleMicrotask(() => todoService.index());
2016-12-23 20:57:46 +00:00
2018-08-28 14:17:14 +00:00
var indexed = await todoService.onIndexed.first;
2017-12-10 05:31:34 +00:00
print('indexed: $indexed');
2016-12-23 20:57:46 +00:00
2017-12-10 05:31:34 +00:00
expect(indexed, isList);
expect(indexed, isEmpty);
2016-12-23 20:57:46 +00:00
}