added null safety for llc

This commit is contained in:
Deven Joshi
2021-04-08 15:03:16 +05:30
parent 3a5308a9c0
commit c80fc0a6b4
41 changed files with 1222 additions and 1202 deletions
@@ -50,7 +50,7 @@ void main() {
),
);
await channelClient.sendMessage(message);
await channelClient?.sendMessage(message);
verify(() =>
mockDio.post<String>('/channels/messaging/testid/message', data: {
@@ -80,7 +80,7 @@ void main() {
statusCode: 200,
requestOptions: FakeRequestOptions(),
));
await channelClient.watch();
await channelClient?.watch();
when(
() => mockDio.post<String>(
@@ -95,7 +95,7 @@ void main() {
),
);
await channelClient.markRead();
await channelClient?.markRead();
verify(() => mockDio.post<String>('/channels/messaging/testid/read',
data: {})).called(1);
@@ -124,7 +124,7 @@ void main() {
),
);
await channelClient.getReplies('messageid', pagination);
await channelClient?.getReplies('messageid', pagination);
verify(() => mockDio.get<String>('/messages/messageid/replies',
queryParameters: pagination.toJson())).called(1);
@@ -141,7 +141,7 @@ void main() {
httpClient: mockDio,
tokenProvider: (_) async => '',
);
final channelClient = client.channel('messaging', id: 'testid');
Channel channelClient = client.channel('messaging', id: 'testid');
when(() => mockDio.post<String>(
any(),
@@ -564,7 +564,11 @@ void main() {
'api-key',
httpClient: mockDio,
tokenProvider: (_) async => '',
)..state.user = OwnUser(id: 'test-id');
);
if (client != null) {
client.state?.user = OwnUser(id: 'test-id');
}
final channelClient = client.channel('messaging', id: 'testid');
const reactionType = 'test';
@@ -617,7 +621,11 @@ void main() {
'api-key',
httpClient: mockDio,
tokenProvider: (_) async => '',
)..state.user = OwnUser(id: 'test-id');
);
if (client != null) {
client.state?.user = OwnUser(id: 'test-id');
}
final channelClient = client.channel('messaging', id: 'testid');
@@ -1069,8 +1077,8 @@ void main() {
verify(() => mockDio.post<String>('/channels/messaging/query',
data: options)).called(1);
expect(channelClient.id, response.channel.id);
expect(channelClient.cid, response.channel.cid);
expect(channelClient.id, response?.channel?.id);
expect(channelClient.cid, response?.channel?.cid);
});
test('with id', () async {
@@ -1706,8 +1714,8 @@ void main() {
verify(() => mockDio.post<String>('/channels/messaging/query',
data: options)).called(1);
expect(channelClient.id, response.channel.id);
expect(channelClient.cid, response.channel.cid);
expect(channelClient.id, response?.channel?.id);
expect(channelClient.cid, response?.channel?.cid);
});
test('watch', () async {
@@ -2027,8 +2035,8 @@ void main() {
verify(() => mockDio.post<String>('/channels/messaging/query',
data: options)).called(1);
expect(channelClient.id, response.channel.id);
expect(channelClient.cid, response.channel.cid);
expect(channelClient.id, response.channel?.id);
expect(channelClient.cid, response.channel?.cid);
});
test('stopWatching', () async {
@@ -12,12 +12,10 @@ import 'package:web_socket_channel/web_socket_channel.dart';
class Functions {
WebSocketChannel connectFunc(
String url, {
Iterable<String> protocols,
Map<String, dynamic> headers,
Duration pingInterval,
String? url, {
Iterable<String>? protocols,
}) =>
null;
WebSocketChannel.connect(Uri());
void handleFunc(Event event) {}
}
@@ -94,7 +92,7 @@ void main() {
when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink());
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
final connect = ws.connect().then((_) {
final connect = ws.connect()?.then((_) {
streamController.sink.add('{}');
return Future.delayed(const Duration(milliseconds: 200));
}).then((value) {
@@ -130,7 +128,7 @@ void main() {
when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink());
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
final connect = ws.connect().then((_) {
final connect = ws.connect()?.then((_) {
streamController.sink.add('{}');
return Future.delayed(const Duration(milliseconds: 200));
}).then((value) {
@@ -208,7 +206,7 @@ void main() {
(_) => streamController.sink.add('{}'),
);
final connect = ws.connect().then((_) {
final connect = ws.connect()?.then((_) {
streamController.sink.add('{}');
return Future.delayed(const Duration(milliseconds: 200));
}).then((value) async {
@@ -249,7 +247,7 @@ void main() {
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
when(() => mockWSChannel.sink).thenReturn(mockWSSink);
final connect = ws.connect().then((_) {
final connect = ws.connect()?.then((_) {
streamController.sink.add('{}');
streamController.close();
streamController = StreamController<String>.broadcast();
@@ -292,7 +290,7 @@ void main() {
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
when(() => mockWSChannel.sink).thenReturn(mockWSSink);
final connect = ws.connect().then((_) {
final connect = ws.connect()?.then((_) {
streamController.sink.add('{}');
return Future.delayed(const Duration(milliseconds: 200));
}).then((value) async {
@@ -49,7 +49,7 @@ void main() {
'https://media0.giphy.com/media/3o7TKnCdBx5cMg0qti/giphy.gif',
);
expect(attachment.actions, hasLength(3));
expect(attachment.actions[0], isA<Action>());
expect(attachment.actions![0], isA<Action>());
});
test('should serialize to json correctly', () {
@@ -10,7 +10,8 @@ import 'package:stream_chat/stream_chat.dart';
void main() {
group('src/models/channel_state', () {
const jsonExample = '''{
const jsonExample = '''
{
"channel": {
"id": "dev",
"type": "team",
@@ -844,36 +845,36 @@ void main() {
test('should parse json correctly', () {
final channelState = ChannelState.fromJson(json.decode(jsonExample));
expect(channelState.channel.cid, 'team:dev');
expect(channelState.channel.id, 'dev');
expect(channelState.channel.team, 'test');
expect(channelState.channel.type, 'team');
expect(channelState.channel.config, isA<ChannelConfig>());
expect(channelState.channel.config, isNotNull);
expect(channelState.channel.config.commands, hasLength(1));
expect(channelState.channel.config.commands[0], isA<Command>());
expect(channelState.channel.lastMessageAt,
expect(channelState.channel?.cid, 'team:dev');
expect(channelState.channel?.id, 'dev');
expect(channelState.channel?.team, 'test');
expect(channelState.channel?.type, 'team');
expect(channelState.channel?.config, isA<ChannelConfig>());
expect(channelState.channel?.config, isNotNull);
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'));
expect(channelState.channel.createdAt,
expect(channelState.channel?.createdAt,
DateTime.parse('2019-04-03T18:43:33.213373Z'));
expect(channelState.channel.updatedAt,
expect(channelState.channel?.updatedAt,
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?.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'],
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], isA<Message>());
expect(channelState.messages![0], isNotNull);
expect(
channelState.messages[0].createdAt,
channelState.messages![0].createdAt,
DateTime.parse('2020-01-29T03:23:02.843948Z'),
);
expect(channelState.messages[0].user, isA<User>());
expect(channelState.messages![0].user, isA<User>());
expect(channelState.watcherCount, 5);
});
@@ -20,8 +20,8 @@ void main() {
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.extraData!['cats'], equals(true));
expect(channel.extraData!['fruit'], equals(['bananas', 'apples']));
});
test('should serialize to json correctly', () {
@@ -33,7 +33,7 @@ void main() {
expect(reaction.createdAt, DateTime.parse('2020-01-28T22:17:31.108742Z'));
expect(reaction.type, 'wow');
expect(
reaction.user.toJson(),
reaction.user?.toJson(),
User.init('2de0297c-f3f2-489d-b930-ef77342edccf', extraData: {
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
'name': 'Daisy Morgan'
@@ -19,7 +19,7 @@ void main() {
test('should parse json correctly', () {
final read = Read.fromJson(json.decode(jsonExample));
expect(read.lastRead, DateTime.parse('2020-01-28T22:17:30.966485504Z'));
expect(read.user.id, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e');
expect(read.user?.id, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e');
expect(read.unreadMessages, 10);
});