Merge branch 'feat/nullsafety-stream-chat' of git://github.com/felangel/stream-chat-flutter into felangel-feat/nullsafety-stream-chat
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -4,13 +4,13 @@ import 'package:stream_chat/stream_chat.dart';
|
||||
void main() {
|
||||
group('src/api/requests', () {
|
||||
test('SortOption', () {
|
||||
final option = SortOption('name');
|
||||
const option = SortOption('name');
|
||||
final j = option.toJson();
|
||||
expect(j, {'field': 'name', 'direction': -1});
|
||||
});
|
||||
|
||||
test('PaginationParams', () {
|
||||
final option = PaginationParams();
|
||||
const option = PaginationParams();
|
||||
final j = option.toJson();
|
||||
expect(j, {'limit': 10, 'offset': 0});
|
||||
});
|
||||
|
||||
@@ -3284,7 +3284,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('QueryReactionsResponse', () {
|
||||
const jsonExample = r'''
|
||||
const jsonExample = '''
|
||||
{"reactions": [{"message_id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f","user_id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680","user": {"id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680","role": "user","created_at": "2020-01-28T22:17:30.83015Z","updated_at": "2020-01-28T22:17:31.19435Z","banned": false,"online": false,"image": "https://randomuser.me/api/portraits/women/2.jpg","name": "Mia Denys"},"type": "love","score": 1,"created_at": "2020-01-28T22:17:31.128376Z","updated_at": "2020-01-28T22:17:31.128376Z"}]}
|
||||
''';
|
||||
final response =
|
||||
@@ -3402,31 +3402,31 @@ void main() {
|
||||
|
||||
test('ListDevicesResponse', () {
|
||||
const jsonExample =
|
||||
r'''{"devices":[{"push_provider":"firebase","id":"test"}],"duration":"0.35ms"}''';
|
||||
'''{"devices":[{"push_provider":"firebase","id":"test"}],"duration":"0.35ms"}''';
|
||||
final response = ListDevicesResponse.fromJson(json.decode(jsonExample));
|
||||
expect(response.devices, isA<List<Device>>());
|
||||
});
|
||||
|
||||
test('SendFileResponse', () {
|
||||
const jsonExample = r'''{"file": "file-url","duration":"0.35ms"}''';
|
||||
const jsonExample = '''{"file": "file-url","duration":"0.35ms"}''';
|
||||
final response = SendFileResponse.fromJson(json.decode(jsonExample));
|
||||
expect(response.file, isA<String>());
|
||||
});
|
||||
|
||||
test('SendImageResponse', () {
|
||||
const jsonExample = r'''{"file": "file-url","duration":"0.35ms"}''';
|
||||
const jsonExample = '''{"file": "file-url","duration":"0.35ms"}''';
|
||||
final response = SendImageResponse.fromJson(json.decode(jsonExample));
|
||||
expect(response.file, isA<String>());
|
||||
});
|
||||
|
||||
test('SendImageResponse', () {
|
||||
const jsonExample = r'''{"file": "file-url","duration":"0.35ms"}''';
|
||||
const jsonExample = '''{"file": "file-url","duration":"0.35ms"}''';
|
||||
final response = SendImageResponse.fromJson(json.decode(jsonExample));
|
||||
expect(response.file, isA<String>());
|
||||
});
|
||||
|
||||
test('EmptyResponse', () {
|
||||
const jsonExample = r'''{"file": "file-url","duration":"0.35ms"}''';
|
||||
const jsonExample = '''{"file": "file-url","duration":"0.35ms"}''';
|
||||
final response = EmptyResponse.fromJson(json.decode(jsonExample));
|
||||
expect(response.duration, isA<String>());
|
||||
});
|
||||
@@ -3481,8 +3481,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('UpdateUsersResponse', () {
|
||||
const jsonExample =
|
||||
r'''{"users": {"bbb19d9a-ee50-45bc-84e5-0584e79d0c9e":{
|
||||
const jsonExample = '''{"users": {"bbb19d9a-ee50-45bc-84e5-0584e79d0c9e":{
|
||||
"id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e",
|
||||
"role": "user",
|
||||
"created_at": "2020-01-28T22:17:30.826259Z",
|
||||
@@ -3498,7 +3497,7 @@ void main() {
|
||||
|
||||
test('ConnectGuestUserResponse', () {
|
||||
const jsonExample =
|
||||
r'{"user":{"id":"guest-ac612aee-25fe-49fb-b1af-969e41f452a0-wild-breeze-7","role":"guest","created_at":"2020-02-03T10:19:01.538434Z","updated_at":"2020-02-03T10:19:01.539543Z","banned":false,"online":false},"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZ3Vlc3QtYWM2MTJhZWUtMjVmZS00OWZiLWIxYWYtOTY5ZTQxZjQ1MmEwLXdpbGQtYnJlZXplLTcifQ.mmoFGu7oJjpFsp7nFN78UbIpO7gowbuIbyoppsuvbXA","duration":"4.66ms"}';
|
||||
'''{"user":{"id":"guest-ac612aee-25fe-49fb-b1af-969e41f452a0-wild-breeze-7","role":"guest","created_at":"2020-02-03T10:19:01.538434Z","updated_at":"2020-02-03T10:19:01.539543Z","banned":false,"online":false},"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZ3Vlc3QtYWM2MTJhZWUtMjVmZS00OWZiLWIxYWYtOTY5ZTQxZjQ1MmEwLXdpbGQtYnJlZXplLTcifQ.mmoFGu7oJjpFsp7nFN78UbIpO7gowbuIbyoppsuvbXA","duration":"4.66ms"}''';
|
||||
final response =
|
||||
ConnectGuestUserResponse.fromJson(json.decode(jsonExample));
|
||||
expect(response.user, isA<User>());
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:stream_chat/src/api/web_socket_channel_stub.dart';
|
||||
|
||||
void main() {
|
||||
test('src/api/web_socket_stub_test', () {
|
||||
expect(
|
||||
() => connectWebSocket('fakeurl'),
|
||||
throwsA(isA<UnimplementedError>()),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:stream_chat/src/api/connection_status.dart';
|
||||
import 'package:stream_chat/src/api/websocket.dart';
|
||||
import 'package:stream_chat/src/models/event.dart';
|
||||
@@ -19,7 +19,7 @@ class Functions {
|
||||
}) =>
|
||||
null;
|
||||
|
||||
void handleFunc(Event event) => null;
|
||||
void handleFunc(Event event) {}
|
||||
}
|
||||
|
||||
class MockFunctions extends Mock implements Functions {}
|
||||
@@ -28,35 +28,35 @@ class MockWSChannel extends Mock implements WebSocketChannel {}
|
||||
|
||||
class MockWSSink extends Mock implements WebSocketSink {}
|
||||
|
||||
class FakeEvent extends Fake implements Event {}
|
||||
|
||||
void main() {
|
||||
group('src/api/websocket', () {
|
||||
setUpAll(() {
|
||||
registerFallbackValue<Event>(FakeEvent());
|
||||
});
|
||||
|
||||
test('should connect with correct parameters', () async {
|
||||
final ConnectWebSocket connectFunc = MockFunctions().connectFunc;
|
||||
|
||||
final ws = WebSocket(
|
||||
baseUrl: 'baseurl',
|
||||
user: User(id: 'testid'),
|
||||
logger: Logger('ws'),
|
||||
connectParams: {'test': 'true'},
|
||||
connectPayload: {'payload': 'test'},
|
||||
handler: (e) {
|
||||
print(e);
|
||||
},
|
||||
handler: print,
|
||||
connectFunc: connectFunc,
|
||||
);
|
||||
|
||||
final mockWSChannel = MockWSChannel();
|
||||
|
||||
final streamController = StreamController<String>.broadcast();
|
||||
|
||||
const computedUrl =
|
||||
'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D';
|
||||
|
||||
when(connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(mockWSChannel.sink).thenAnswer((_) => MockWSSink());
|
||||
when(mockWSChannel.stream).thenAnswer((_) {
|
||||
return streamController.stream;
|
||||
});
|
||||
when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink());
|
||||
when(() => mockWSChannel.stream).thenAnswer(
|
||||
(_) => streamController.stream,
|
||||
);
|
||||
|
||||
final timer = Timer.periodic(
|
||||
const Duration(milliseconds: 100),
|
||||
@@ -65,7 +65,7 @@ void main() {
|
||||
|
||||
await ws.connect();
|
||||
|
||||
verify(connectFunc(computedUrl)).called(1);
|
||||
verify(() => connectFunc(computedUrl)).called(1);
|
||||
expect(ws.connectionStatus, ConnectionStatus.connected);
|
||||
|
||||
await streamController.close();
|
||||
@@ -76,7 +76,6 @@ void main() {
|
||||
test('should connect with correct parameters and handle events', () async {
|
||||
final handleFunc = MockFunctions().handleFunc;
|
||||
final ConnectWebSocket connectFunc = MockFunctions().connectFunc;
|
||||
|
||||
final ws = WebSocket(
|
||||
baseUrl: 'baseurl',
|
||||
user: User(id: 'testid'),
|
||||
@@ -86,27 +85,21 @@ void main() {
|
||||
handler: handleFunc,
|
||||
connectFunc: connectFunc,
|
||||
);
|
||||
|
||||
final mockWSChannel = MockWSChannel();
|
||||
|
||||
final StreamController<String> streamController =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
final computedUrl =
|
||||
final streamController = StreamController<String>.broadcast();
|
||||
const computedUrl =
|
||||
'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D';
|
||||
|
||||
when(connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(mockWSChannel.sink).thenAnswer((_) => MockWSSink());
|
||||
when(mockWSChannel.stream).thenAnswer((_) {
|
||||
return streamController.stream;
|
||||
});
|
||||
when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink());
|
||||
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
|
||||
|
||||
final connect = ws.connect().then((_) {
|
||||
streamController.sink.add('{}');
|
||||
return Future.delayed(Duration(milliseconds: 200));
|
||||
return Future.delayed(const Duration(milliseconds: 200));
|
||||
}).then((value) {
|
||||
verify(connectFunc(computedUrl)).called(1);
|
||||
verify(handleFunc(any)).called(greaterThan(0));
|
||||
verify(() => connectFunc(computedUrl)).called(1);
|
||||
verify(() => handleFunc(any())).called(greaterThan(0));
|
||||
|
||||
return streamController.close();
|
||||
});
|
||||
@@ -118,9 +111,7 @@ void main() {
|
||||
|
||||
test('should close correctly the controller', () async {
|
||||
final handleFunc = MockFunctions().handleFunc;
|
||||
|
||||
final ConnectWebSocket connectFunc = MockFunctions().connectFunc;
|
||||
|
||||
final ws = WebSocket(
|
||||
baseUrl: 'baseurl',
|
||||
user: User(id: 'testid'),
|
||||
@@ -130,27 +121,21 @@ void main() {
|
||||
handler: handleFunc,
|
||||
connectFunc: connectFunc,
|
||||
);
|
||||
|
||||
final mockWSChannel = MockWSChannel();
|
||||
|
||||
final StreamController<String> streamController =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
final computedUrl =
|
||||
final streamController = StreamController<String>.broadcast();
|
||||
const computedUrl =
|
||||
'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D';
|
||||
|
||||
when(connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(mockWSChannel.sink).thenAnswer((_) => MockWSSink());
|
||||
when(mockWSChannel.stream).thenAnswer((_) {
|
||||
return streamController.stream;
|
||||
});
|
||||
when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink());
|
||||
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
|
||||
|
||||
final connect = ws.connect().then((_) {
|
||||
streamController.sink.add('{}');
|
||||
return Future.delayed(Duration(milliseconds: 200));
|
||||
return Future.delayed(const Duration(milliseconds: 200));
|
||||
}).then((value) {
|
||||
verify(connectFunc(computedUrl)).called(1);
|
||||
verify(handleFunc(any)).called(greaterThan(0));
|
||||
verify(() => connectFunc(computedUrl)).called(1);
|
||||
verify(() => handleFunc(any())).called(greaterThan(0));
|
||||
|
||||
return streamController.close();
|
||||
});
|
||||
@@ -159,6 +144,7 @@ void main() {
|
||||
|
||||
return connect;
|
||||
});
|
||||
|
||||
test('should close correctly the controller while connecting', () async {
|
||||
final handleFunc = MockFunctions().handleFunc;
|
||||
|
||||
@@ -198,9 +184,7 @@ void main() {
|
||||
|
||||
test('should run correctly health check', () async {
|
||||
final handleFunc = MockFunctions().handleFunc;
|
||||
|
||||
final ConnectWebSocket connectFunc = MockFunctions().connectFunc;
|
||||
|
||||
final ws = WebSocket(
|
||||
baseUrl: 'baseurl',
|
||||
user: User(id: 'testid'),
|
||||
@@ -210,32 +194,27 @@ void main() {
|
||||
handler: handleFunc,
|
||||
connectFunc: connectFunc,
|
||||
);
|
||||
|
||||
final mockWSChannel = MockWSChannel();
|
||||
final mockWSSink = MockWSSink();
|
||||
|
||||
final StreamController<String> streamController =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
final computedUrl =
|
||||
final streamController = StreamController<String>.broadcast();
|
||||
const computedUrl =
|
||||
'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D';
|
||||
|
||||
when(connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(mockWSChannel.stream).thenAnswer((_) {
|
||||
return streamController.stream;
|
||||
});
|
||||
when(mockWSChannel.sink).thenReturn(mockWSSink);
|
||||
when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
|
||||
when(() => mockWSChannel.sink).thenReturn(mockWSSink);
|
||||
|
||||
final timer = Timer.periodic(
|
||||
Duration(milliseconds: 1000),
|
||||
const Duration(milliseconds: 1000),
|
||||
(_) => streamController.sink.add('{}'),
|
||||
);
|
||||
|
||||
final connect = ws.connect().then((_) {
|
||||
streamController.sink.add('{}');
|
||||
return Future.delayed(Duration(milliseconds: 200));
|
||||
return Future.delayed(const Duration(milliseconds: 200));
|
||||
}).then((value) async {
|
||||
verify(mockWSSink.add("{'type': 'health.check'}")).called(greaterThan(0));
|
||||
verify(() => mockWSSink.add("{'type': 'health.check'}"))
|
||||
.called(greaterThan(0));
|
||||
|
||||
timer.cancel();
|
||||
await streamController.close();
|
||||
@@ -249,9 +228,7 @@ void main() {
|
||||
|
||||
test('should run correctly reconnection check', () async {
|
||||
final handleFunc = MockFunctions().handleFunc;
|
||||
|
||||
final ConnectWebSocket connectFunc = MockFunctions().connectFunc;
|
||||
|
||||
Logger.root.level = Level.ALL;
|
||||
final ws = WebSocket(
|
||||
baseUrl: 'baseurl',
|
||||
@@ -262,34 +239,28 @@ void main() {
|
||||
handler: handleFunc,
|
||||
connectFunc: connectFunc,
|
||||
reconnectionMonitorTimeout: 1,
|
||||
reconnectionMonitorInterval: 1,
|
||||
);
|
||||
|
||||
final mockWSChannel = MockWSChannel();
|
||||
final mockWSSink = MockWSSink();
|
||||
|
||||
StreamController<String> streamController =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
final computedUrl =
|
||||
var streamController = StreamController<String>.broadcast();
|
||||
const computedUrl =
|
||||
'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D';
|
||||
|
||||
when(connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(mockWSChannel.stream).thenAnswer((_) {
|
||||
return streamController.stream;
|
||||
});
|
||||
when(mockWSChannel.sink).thenReturn(mockWSSink);
|
||||
when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
|
||||
when(() => mockWSChannel.sink).thenReturn(mockWSSink);
|
||||
|
||||
final connect = ws.connect().then((_) {
|
||||
streamController.sink.add('{}');
|
||||
streamController.close();
|
||||
streamController = StreamController<String>.broadcast();
|
||||
streamController.sink.add('{}');
|
||||
return Future.delayed(Duration(milliseconds: 200));
|
||||
return Future.delayed(const Duration(milliseconds: 200));
|
||||
}).then((value) async {
|
||||
verify(mockWSSink.add("{'type': 'health.check'}")).called(greaterThan(0));
|
||||
verify(() => mockWSSink.add("{'type': 'health.check'}"))
|
||||
.called(greaterThan(0));
|
||||
|
||||
verify(connectFunc(computedUrl)).called(2);
|
||||
verify(() => connectFunc(computedUrl)).called(2);
|
||||
|
||||
await streamController.close();
|
||||
return mockWSSink.close();
|
||||
@@ -302,9 +273,7 @@ void main() {
|
||||
|
||||
test('should close correctly the controller', () async {
|
||||
final handleFunc = MockFunctions().handleFunc;
|
||||
|
||||
final ConnectWebSocket connectFunc = MockFunctions().connectFunc;
|
||||
|
||||
final ws = WebSocket(
|
||||
baseUrl: 'baseurl',
|
||||
user: User(id: 'testid'),
|
||||
@@ -314,28 +283,22 @@ void main() {
|
||||
handler: handleFunc,
|
||||
connectFunc: connectFunc,
|
||||
);
|
||||
|
||||
final mockWSChannel = MockWSChannel();
|
||||
final mockWSSink = MockWSSink();
|
||||
|
||||
final StreamController<String> streamController =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
final computedUrl =
|
||||
final streamController = StreamController<String>.broadcast();
|
||||
const computedUrl =
|
||||
'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D';
|
||||
|
||||
when(connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(mockWSChannel.stream).thenAnswer((_) {
|
||||
return streamController.stream;
|
||||
});
|
||||
when(mockWSChannel.sink).thenReturn(mockWSSink);
|
||||
when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
|
||||
when(() => mockWSChannel.sink).thenReturn(mockWSSink);
|
||||
|
||||
final connect = ws.connect().then((_) {
|
||||
streamController.sink.add('{}');
|
||||
return Future.delayed(Duration(milliseconds: 200));
|
||||
return Future.delayed(const Duration(milliseconds: 200));
|
||||
}).then((value) async {
|
||||
await ws.disconnect();
|
||||
verify(mockWSSink.close()).called(greaterThan(0));
|
||||
verify(mockWSSink.close).called(greaterThan(0));
|
||||
|
||||
await streamController.close();
|
||||
await mockWSSink.close();
|
||||
@@ -348,41 +311,34 @@ void main() {
|
||||
|
||||
test('should throw an error', () async {
|
||||
final ConnectWebSocket connectFunc = MockFunctions().connectFunc;
|
||||
|
||||
final ws = WebSocket(
|
||||
baseUrl: 'baseurl',
|
||||
user: User(id: 'testid'),
|
||||
logger: Logger('ws'),
|
||||
connectParams: {'test': 'true'},
|
||||
connectPayload: {'payload': 'test'},
|
||||
handler: (e) {
|
||||
print(e);
|
||||
},
|
||||
handler: print,
|
||||
connectFunc: connectFunc,
|
||||
);
|
||||
|
||||
final mockWSChannel = MockWSChannel();
|
||||
|
||||
final streamController = StreamController<String>.broadcast();
|
||||
|
||||
final computedUrl =
|
||||
const computedUrl =
|
||||
'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D';
|
||||
|
||||
when(connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(mockWSChannel.sink).thenAnswer((_) => MockWSSink());
|
||||
when(mockWSChannel.stream).thenAnswer((_) {
|
||||
return streamController.stream;
|
||||
});
|
||||
when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel);
|
||||
when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink());
|
||||
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
|
||||
|
||||
Future.delayed(
|
||||
Duration(milliseconds: 1000),
|
||||
const Duration(milliseconds: 1000),
|
||||
() => streamController.sink.addError('test error'),
|
||||
);
|
||||
|
||||
try {
|
||||
expect(await ws.connect(), throwsA(isA<String>()));
|
||||
} catch (e) {
|
||||
verify(connectFunc(computedUrl)).called(greaterThanOrEqualTo(1));
|
||||
verify(() => connectFunc(computedUrl)).called(greaterThanOrEqualTo(1));
|
||||
streamController.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@ import 'package:stream_chat/src/models/action.dart';
|
||||
|
||||
void main() {
|
||||
group('src/models/action', () {
|
||||
const jsonExample = r'''{
|
||||
const jsonExample = '''{
|
||||
"name": "name",
|
||||
"style": "style",
|
||||
"text": "text",
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'dart:convert';
|
||||
import 'package:stream_chat/src/models/attachment.dart';
|
||||
import 'package:stream_chat/src/models/action.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('src/models/attachment', () {
|
||||
const jsonExample = r'''{
|
||||
const jsonExample = '''{
|
||||
"type": "giphy",
|
||||
"title": "awesome",
|
||||
"title_link": "https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti",
|
||||
@@ -38,22 +38,27 @@ void main() {
|
||||
|
||||
test('should parse json correctly', () {
|
||||
final attachment = Attachment.fromJson(json.decode(jsonExample));
|
||||
expect(attachment.type, "giphy");
|
||||
expect(attachment.title, "awesome");
|
||||
expect(attachment.titleLink,
|
||||
"https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti");
|
||||
expect(attachment.thumbUrl,
|
||||
"https://media0.giphy.com/media/3o7TKnCdBx5cMg0qti/giphy.gif");
|
||||
expect(attachment.type, 'giphy');
|
||||
expect(attachment.title, 'awesome');
|
||||
expect(
|
||||
attachment.titleLink,
|
||||
'https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti',
|
||||
);
|
||||
expect(
|
||||
attachment.thumbUrl,
|
||||
'https://media0.giphy.com/media/3o7TKnCdBx5cMg0qti/giphy.gif',
|
||||
);
|
||||
expect(attachment.actions, hasLength(3));
|
||||
expect(attachment.actions[0], isA<Action>());
|
||||
});
|
||||
|
||||
test('should serialize to json correctly', () {
|
||||
final channel = Attachment(
|
||||
type: "image",
|
||||
title: "soo",
|
||||
titleLink:
|
||||
"https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti");
|
||||
type: 'image',
|
||||
title: 'soo',
|
||||
titleLink:
|
||||
'https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti',
|
||||
);
|
||||
|
||||
expect(
|
||||
channel.toJson(),
|
||||
|
||||
@@ -10,7 +10,7 @@ import 'package:stream_chat/stream_chat.dart';
|
||||
|
||||
void main() {
|
||||
group('src/models/channel_state', () {
|
||||
const jsonExample = r'''{
|
||||
const jsonExample = '''{
|
||||
"channel": {
|
||||
"id": "dev",
|
||||
"type": "team",
|
||||
@@ -853,28 +853,32 @@ void main() {
|
||||
expect(channelState.channel.config.commands, hasLength(1));
|
||||
expect(channelState.channel.config.commands[0], isA<Command>());
|
||||
expect(channelState.channel.lastMessageAt,
|
||||
DateTime.parse("2020-01-30T13:43:41.062362Z"));
|
||||
DateTime.parse('2020-01-30T13:43:41.062362Z'));
|
||||
expect(channelState.channel.createdAt,
|
||||
DateTime.parse("2019-04-03T18:43:33.213373Z"));
|
||||
DateTime.parse('2019-04-03T18:43:33.213373Z'));
|
||||
expect(channelState.channel.updatedAt,
|
||||
DateTime.parse("2019-04-03T18:43:33.213374Z"));
|
||||
DateTime.parse('2019-04-03T18:43:33.213374Z'));
|
||||
expect(channelState.channel.createdBy, isA<User>());
|
||||
expect(channelState.channel.frozen, true);
|
||||
expect(channelState.channel.extraData['example'], 1);
|
||||
expect(channelState.channel.extraData['name'], "#dev");
|
||||
expect(channelState.channel.extraData['image'],
|
||||
"https://cdn.chrisshort.net/testing-certificate-chains-in-go/GOPHER_MIC_DROP.png");
|
||||
expect(channelState.channel.extraData['name'], '#dev');
|
||||
expect(
|
||||
channelState.channel.extraData['image'],
|
||||
'https://cdn.chrisshort.net/testing-certificate-chains-in-go/GOPHER_MIC_DROP.png',
|
||||
);
|
||||
expect(channelState.messages, hasLength(25));
|
||||
expect(channelState.messages[0], isA<Message>());
|
||||
expect(channelState.messages[0], isNotNull);
|
||||
expect(channelState.messages[0].createdAt,
|
||||
DateTime.parse("2020-01-29T03:23:02.843948Z"));
|
||||
expect(
|
||||
channelState.messages[0].createdAt,
|
||||
DateTime.parse('2020-01-29T03:23:02.843948Z'),
|
||||
);
|
||||
expect(channelState.messages[0].user, isA<User>());
|
||||
expect(channelState.watcherCount, 5);
|
||||
});
|
||||
|
||||
test('should serialize to json correctly', () {
|
||||
const toJsonExample = r'''
|
||||
const toJsonExample = '''
|
||||
{
|
||||
"channel": {
|
||||
"id": "dev",
|
||||
|
||||
@@ -17,19 +17,19 @@ void main() {
|
||||
|
||||
test('should parse json correctly', () {
|
||||
final channel = ChannelModel.fromJson(json.decode(jsonExample));
|
||||
expect(channel.id, equals("test"));
|
||||
expect(channel.type, equals("livestream"));
|
||||
expect(channel.cid, equals("test:livestream"));
|
||||
expect(channel.extraData["cats"], equals(true));
|
||||
expect(channel.extraData["fruit"], equals(["bananas", "apples"]));
|
||||
expect(channel.id, equals('test'));
|
||||
expect(channel.type, equals('livestream'));
|
||||
expect(channel.cid, equals('test:livestream'));
|
||||
expect(channel.extraData['cats'], equals(true));
|
||||
expect(channel.extraData['fruit'], equals(['bananas', 'apples']));
|
||||
});
|
||||
|
||||
test('should serialize to json correctly', () {
|
||||
final channel = ChannelModel(
|
||||
type: "type",
|
||||
id: "id",
|
||||
cid: "a:a",
|
||||
extraData: {"name": "cool"},
|
||||
type: 'type',
|
||||
id: 'id',
|
||||
cid: 'a:a',
|
||||
extraData: {'name': 'cool'},
|
||||
);
|
||||
|
||||
expect(
|
||||
@@ -40,10 +40,10 @@ void main() {
|
||||
|
||||
test('should serialize to json correctly when frozen is provided', () {
|
||||
final channel = ChannelModel(
|
||||
type: "type",
|
||||
id: "id",
|
||||
cid: "a:a",
|
||||
extraData: {"name": "cool"},
|
||||
type: 'type',
|
||||
id: 'id',
|
||||
cid: 'a:a',
|
||||
extraData: {'name': 'cool'},
|
||||
frozen: false,
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:stream_chat/src/models/command.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:stream_chat/src/models/command.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
@@ -30,9 +30,9 @@ void main() {
|
||||
expect(
|
||||
command.toJson(),
|
||||
{
|
||||
"name": "giphy",
|
||||
"description": "Post a random gif to the channel",
|
||||
"args": "[text]",
|
||||
'name': 'giphy',
|
||||
'description': 'Post a random gif to the channel',
|
||||
'args': '[text]',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:stream_chat/src/models/device.dart';
|
||||
|
||||
void main() {
|
||||
group('src/models/device', () {
|
||||
const jsonExample = r'''{
|
||||
const jsonExample = '''{
|
||||
"id": "device-id",
|
||||
"push_provider": "push-provider"
|
||||
}''';
|
||||
|
||||
@@ -55,7 +55,7 @@ void main() {
|
||||
type: 'type',
|
||||
cid: 'cid',
|
||||
connectionId: 'connectionId',
|
||||
createdAt: DateTime.parse("2020-01-29T03:22:47.63613Z"),
|
||||
createdAt: DateTime.parse('2020-01-29T03:22:47.63613Z'),
|
||||
me: OwnUser(id: 'id2'),
|
||||
totalUnreadCount: 1,
|
||||
unreadChannels: 1,
|
||||
|
||||
@@ -28,8 +28,8 @@ void main() {
|
||||
final member = Member.fromJson(json.decode(jsonExample));
|
||||
expect(member.user, isA<User>());
|
||||
expect(member.role, 'member');
|
||||
expect(member.createdAt, DateTime.parse("2020-01-28T22:17:30.95443Z"));
|
||||
expect(member.updatedAt, DateTime.parse("2020-01-28T22:17:30.95443Z"));
|
||||
expect(member.createdAt, DateTime.parse('2020-01-28T22:17:30.95443Z'));
|
||||
expect(member.updatedAt, DateTime.parse('2020-01-28T22:17:30.95443Z'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,10 +76,10 @@ void main() {
|
||||
|
||||
test('should parse json correctly', () {
|
||||
final message = Message.fromJson(json.decode(jsonExample));
|
||||
expect(message.id, "4637f7e4-a06b-42db-ba5a-8d8270dd926f");
|
||||
expect(message.id, '4637f7e4-a06b-42db-ba5a-8d8270dd926f');
|
||||
expect(message.text,
|
||||
"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA");
|
||||
expect(message.type, "regular");
|
||||
'https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA');
|
||||
expect(message.type, 'regular');
|
||||
expect(message.user, isA<User>());
|
||||
expect(message.silent, isA<bool>());
|
||||
expect(message.attachments, isA<List<Attachment>>());
|
||||
@@ -87,8 +87,8 @@ void main() {
|
||||
expect(message.ownReactions, isA<List<Reaction>>());
|
||||
expect(message.reactionCounts, {'love': 1});
|
||||
expect(message.reactionScores, {'love': 1});
|
||||
expect(message.createdAt, DateTime.parse("2020-01-28T22:17:31.107978Z"));
|
||||
expect(message.updatedAt, DateTime.parse("2020-01-28T22:17:31.130506Z"));
|
||||
expect(message.createdAt, DateTime.parse('2020-01-28T22:17:31.107978Z'));
|
||||
expect(message.updatedAt, DateTime.parse('2020-01-28T22:17:31.130506Z'));
|
||||
expect(message.mentionedUsers, isA<List<User>>());
|
||||
expect(message.pinned, false);
|
||||
expect(message.pinnedAt, null);
|
||||
@@ -98,38 +98,37 @@ void main() {
|
||||
|
||||
test('should serialize to json correctly', () {
|
||||
final message = Message(
|
||||
id: "4637f7e4-a06b-42db-ba5a-8d8270dd926f",
|
||||
id: '4637f7e4-a06b-42db-ba5a-8d8270dd926f',
|
||||
text:
|
||||
"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA",
|
||||
'https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA',
|
||||
silent: false,
|
||||
attachments: [
|
||||
Attachment.fromJson({
|
||||
"type": "video",
|
||||
"author_name": "GIPHY",
|
||||
"title": "The Lion King Disney GIF - Find \u0026 Share on GIPHY",
|
||||
"title_link":
|
||||
"https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
|
||||
"text":
|
||||
"Discover \u0026 share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.",
|
||||
"image_url":
|
||||
"https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
|
||||
"thumb_url":
|
||||
"https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
|
||||
"asset_url":
|
||||
"https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4",
|
||||
"og_scrape_url":
|
||||
"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA"
|
||||
'type': 'video',
|
||||
'author_name': 'GIPHY',
|
||||
'title': 'The Lion King Disney GIF - Find \u0026 Share on GIPHY',
|
||||
'title_link':
|
||||
'https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif',
|
||||
'text':
|
||||
'''Discover \u0026 share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.''',
|
||||
'image_url':
|
||||
'https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif',
|
||||
'thumb_url':
|
||||
'https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif',
|
||||
'asset_url':
|
||||
'https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4',
|
||||
'og_scrape_url':
|
||||
'https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA'
|
||||
})
|
||||
],
|
||||
showInChannel: true,
|
||||
parentId: 'parentId',
|
||||
extraData: {'hey': 'test'},
|
||||
status: MessageSendingStatus.sent,
|
||||
);
|
||||
|
||||
expect(
|
||||
message.toJson(),
|
||||
json.decode(r'''
|
||||
json.decode('''
|
||||
{
|
||||
"id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f",
|
||||
"text": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:stream_chat/src/models/reaction.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'package:stream_chat/src/models/reaction.dart';
|
||||
import 'package:stream_chat/src/models/user.dart';
|
||||
|
||||
void main() {
|
||||
@@ -30,13 +30,13 @@ void main() {
|
||||
test('should parse json correctly', () {
|
||||
final reaction = Reaction.fromJson(json.decode(jsonExample));
|
||||
expect(reaction.messageId, '76cd8c82-b557-4e48-9d12-87995d3a0e04');
|
||||
expect(reaction.createdAt, DateTime.parse("2020-01-28T22:17:31.108742Z"));
|
||||
expect(reaction.createdAt, DateTime.parse('2020-01-28T22:17:31.108742Z'));
|
||||
expect(reaction.type, 'wow');
|
||||
expect(
|
||||
reaction.user.toJson(),
|
||||
User.init("2de0297c-f3f2-489d-b930-ef77342edccf", extraData: {
|
||||
"image": "https://randomuser.me/api/portraits/women/45.jpg",
|
||||
"name": "Daisy Morgan"
|
||||
User.init('2de0297c-f3f2-489d-b930-ef77342edccf', extraData: {
|
||||
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
'name': 'Daisy Morgan'
|
||||
}).toJson(),
|
||||
);
|
||||
expect(reaction.score, 1);
|
||||
@@ -47,13 +47,13 @@ void main() {
|
||||
test('should serialize to json correctly', () {
|
||||
final reaction = Reaction(
|
||||
messageId: '76cd8c82-b557-4e48-9d12-87995d3a0e04',
|
||||
createdAt: DateTime.parse("2020-01-28T22:17:31.108742Z"),
|
||||
createdAt: DateTime.parse('2020-01-28T22:17:31.108742Z'),
|
||||
type: 'wow',
|
||||
user: User.init("2de0297c-f3f2-489d-b930-ef77342edccf", extraData: {
|
||||
"image": "https://randomuser.me/api/portraits/women/45.jpg",
|
||||
"name": "Daisy Morgan"
|
||||
user: User.init('2de0297c-f3f2-489d-b930-ef77342edccf', extraData: {
|
||||
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
'name': 'Daisy Morgan'
|
||||
}),
|
||||
userId: "2de0297c-f3f2-489d-b930-ef77342edccf",
|
||||
userId: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
extraData: {'bananas': 'yes'},
|
||||
score: 1,
|
||||
);
|
||||
@@ -61,10 +61,10 @@ void main() {
|
||||
expect(
|
||||
reaction.toJson(),
|
||||
{
|
||||
"message_id": "76cd8c82-b557-4e48-9d12-87995d3a0e04",
|
||||
"type": "wow",
|
||||
"score": 1,
|
||||
"bananas": 'yes',
|
||||
'message_id': '76cd8c82-b557-4e48-9d12-87995d3a0e04',
|
||||
'type': 'wow',
|
||||
'score': 1,
|
||||
'bananas': 'yes',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -31,8 +31,8 @@ void main() {
|
||||
);
|
||||
|
||||
expect(read.toJson(), {
|
||||
"user": {"id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e"},
|
||||
"last_read": "2020-01-28T22:17:30.966485Z",
|
||||
'user': {'id': 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e'},
|
||||
'last_read': '2020-01-28T22:17:30.966485Z',
|
||||
'unread_messages': 10,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,11 +17,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('should serialize to json correctly', () {
|
||||
final user =
|
||||
User(id: 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e', role: "abc");
|
||||
final user = User(
|
||||
id: 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e',
|
||||
role: 'abc',
|
||||
);
|
||||
|
||||
expect(user.toJson(), {
|
||||
'id': "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e",
|
||||
'id': 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user