better channel api tests
This commit is contained in:
@@ -76,7 +76,7 @@ class ChannelApi {
|
|||||||
|
|
||||||
// pagination
|
// pagination
|
||||||
...paginationParams.toJson()
|
...paginationParams.toJson()
|
||||||
})
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return QueryChannelsResponse.fromJson(response.data);
|
return QueryChannelsResponse.fromJson(response.data);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:mocktail/mocktail.dart';
|
import 'package:mocktail/mocktail.dart';
|
||||||
import 'package:stream_chat/src/core/api/channel_api.dart';
|
import 'package:stream_chat/src/core/api/channel_api.dart';
|
||||||
@@ -76,11 +78,24 @@ void main() {
|
|||||||
const path = '$channelPath/query';
|
const path = '$channelPath/query';
|
||||||
|
|
||||||
final channelState = _generateChannelState(channelId, channelType);
|
final channelState = _generateChannelState(channelId, channelType);
|
||||||
when(() => client.post(path, data: any(named: 'data')))
|
|
||||||
.thenAnswer((_) async => successResponse(
|
final data = {
|
||||||
path,
|
'state': true,
|
||||||
data: channelState.toJson(),
|
'watch': false,
|
||||||
));
|
'presence': false,
|
||||||
|
'data': channelData,
|
||||||
|
'messages': messagePagination,
|
||||||
|
'members': membersPagination,
|
||||||
|
'watchers': watchersPagination,
|
||||||
|
};
|
||||||
|
|
||||||
|
when(() => client.post(
|
||||||
|
path,
|
||||||
|
data: data,
|
||||||
|
)).thenAnswer((_) async => successResponse(
|
||||||
|
path,
|
||||||
|
data: channelState.toJson(),
|
||||||
|
));
|
||||||
|
|
||||||
final res = await channelApi.queryChannel(
|
final res = await channelApi.queryChannel(
|
||||||
channelType,
|
channelType,
|
||||||
@@ -115,13 +130,34 @@ void main() {
|
|||||||
const path = '/channels';
|
const path = '/channels';
|
||||||
|
|
||||||
final channelState = _generateChannelState(channelId, channelType);
|
final channelState = _generateChannelState(channelId, channelType);
|
||||||
when(() => client.get(path, queryParameters: any(named: 'queryParameters')))
|
|
||||||
.thenAnswer((_) async => successResponse(
|
final payload = jsonEncode({
|
||||||
path,
|
// default options
|
||||||
data: {
|
'state': true,
|
||||||
'channels': [channelState.toJson()]
|
'watch': true,
|
||||||
},
|
'presence': false,
|
||||||
));
|
|
||||||
|
// passed options
|
||||||
|
'sort': sort,
|
||||||
|
'filter_conditions': filter,
|
||||||
|
'member_limit': memberLimit,
|
||||||
|
'message_limit': messageLimit,
|
||||||
|
|
||||||
|
// pagination
|
||||||
|
...const PaginationParams().toJson()
|
||||||
|
});
|
||||||
|
|
||||||
|
when(() => client.get(
|
||||||
|
path,
|
||||||
|
queryParameters: {
|
||||||
|
'payload': payload,
|
||||||
|
},
|
||||||
|
)).thenAnswer((_) async => successResponse(
|
||||||
|
path,
|
||||||
|
data: {
|
||||||
|
'channels': [channelState.toJson()]
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
final res = await channelApi.queryChannels(
|
final res = await channelApi.queryChannels(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
@@ -166,11 +202,18 @@ void main() {
|
|||||||
extraData: data,
|
extraData: data,
|
||||||
);
|
);
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data')))
|
when(() => client.post(
|
||||||
.thenAnswer((_) async => successResponse(path, data: {
|
path,
|
||||||
'channel': channelModel.toJson(),
|
data: any(
|
||||||
'message': message.toJson(),
|
named: 'data',
|
||||||
}));
|
that: wrapMatcher((Map v) =>
|
||||||
|
containsPair('data', data).matches(v, {}) &&
|
||||||
|
contains('message').matches(v, {})),
|
||||||
|
),
|
||||||
|
)).thenAnswer((_) async => successResponse(path, data: {
|
||||||
|
'channel': channelModel.toJson(),
|
||||||
|
'message': message.toJson(),
|
||||||
|
}));
|
||||||
|
|
||||||
final res = await channelApi.updateChannel(
|
final res = await channelApi.updateChannel(
|
||||||
channelId,
|
channelId,
|
||||||
@@ -235,11 +278,16 @@ void main() {
|
|||||||
|
|
||||||
final path = _getChannelUrl(channelId, channelType);
|
final path = _getChannelUrl(channelId, channelType);
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data')))
|
when(() => client.post(
|
||||||
.thenAnswer((_) async => successResponse(path, data: {
|
path,
|
||||||
'channel': channelModel.toJson(),
|
data: {
|
||||||
'message': message.toJson(),
|
'accept_invite': true,
|
||||||
}));
|
'message': message,
|
||||||
|
},
|
||||||
|
)).thenAnswer((_) async => successResponse(path, data: {
|
||||||
|
'channel': channelModel.toJson(),
|
||||||
|
'message': message.toJson(),
|
||||||
|
}));
|
||||||
|
|
||||||
final res = await channelApi.acceptChannelInvite(
|
final res = await channelApi.acceptChannelInvite(
|
||||||
channelId,
|
channelId,
|
||||||
@@ -264,11 +312,16 @@ void main() {
|
|||||||
|
|
||||||
final path = _getChannelUrl(channelId, channelType);
|
final path = _getChannelUrl(channelId, channelType);
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data')))
|
when(() => client.post(
|
||||||
.thenAnswer((_) async => successResponse(path, data: {
|
path,
|
||||||
'channel': channelModel.toJson(),
|
data: {
|
||||||
'message': message.toJson(),
|
'reject_invite': true,
|
||||||
}));
|
'message': message,
|
||||||
|
},
|
||||||
|
)).thenAnswer((_) async => successResponse(path, data: {
|
||||||
|
'channel': channelModel.toJson(),
|
||||||
|
'message': message.toJson(),
|
||||||
|
}));
|
||||||
|
|
||||||
final res = await channelApi.rejectChannelInvite(
|
final res = await channelApi.rejectChannelInvite(
|
||||||
channelId,
|
channelId,
|
||||||
@@ -293,11 +346,16 @@ void main() {
|
|||||||
|
|
||||||
final path = _getChannelUrl(channelId, channelType);
|
final path = _getChannelUrl(channelId, channelType);
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data')))
|
when(() => client.post(
|
||||||
.thenAnswer((_) async => successResponse(path, data: {
|
path,
|
||||||
'channel': channelModel.toJson(),
|
data: {
|
||||||
'message': message.toJson(),
|
'invites': memberIds,
|
||||||
}));
|
'message': message,
|
||||||
|
},
|
||||||
|
)).thenAnswer((_) async => successResponse(path, data: {
|
||||||
|
'channel': channelModel.toJson(),
|
||||||
|
'message': message.toJson(),
|
||||||
|
}));
|
||||||
|
|
||||||
final res = await channelApi.inviteChannelMembers(
|
final res = await channelApi.inviteChannelMembers(
|
||||||
channelId,
|
channelId,
|
||||||
@@ -323,11 +381,16 @@ void main() {
|
|||||||
|
|
||||||
final path = _getChannelUrl(channelId, channelType);
|
final path = _getChannelUrl(channelId, channelType);
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data')))
|
when(() => client.post(
|
||||||
.thenAnswer((_) async => successResponse(path, data: {
|
path,
|
||||||
'channel': channelModel.toJson(),
|
data: {
|
||||||
'message': message.toJson(),
|
'add_members': memberIds,
|
||||||
}));
|
'message': message,
|
||||||
|
},
|
||||||
|
)).thenAnswer((_) async => successResponse(path, data: {
|
||||||
|
'channel': channelModel.toJson(),
|
||||||
|
'message': message.toJson(),
|
||||||
|
}));
|
||||||
|
|
||||||
final res = await channelApi.addMembers(
|
final res = await channelApi.addMembers(
|
||||||
channelId,
|
channelId,
|
||||||
@@ -353,11 +416,16 @@ void main() {
|
|||||||
|
|
||||||
final path = _getChannelUrl(channelId, channelType);
|
final path = _getChannelUrl(channelId, channelType);
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data')))
|
when(() => client.post(
|
||||||
.thenAnswer((_) async => successResponse(path, data: {
|
path,
|
||||||
'channel': channelModel.toJson(),
|
data: {
|
||||||
'message': message.toJson(),
|
'remove_members': memberIds,
|
||||||
}));
|
'message': message,
|
||||||
|
},
|
||||||
|
)).thenAnswer((_) async => successResponse(path, data: {
|
||||||
|
'channel': channelModel.toJson(),
|
||||||
|
'message': message.toJson(),
|
||||||
|
}));
|
||||||
|
|
||||||
final res = await channelApi.removeMembers(
|
final res = await channelApi.removeMembers(
|
||||||
channelId,
|
channelId,
|
||||||
@@ -381,7 +449,7 @@ void main() {
|
|||||||
|
|
||||||
final path = '${_getChannelUrl(channelId, channelType)}/event';
|
final path = '${_getChannelUrl(channelId, channelType)}/event';
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
|
when(() => client.post(path, data: {'event': event})).thenAnswer(
|
||||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
(_) async => successResponse(path, data: <String, dynamic>{}));
|
||||||
|
|
||||||
final res = await channelApi.sendEvent(channelId, channelType, event);
|
final res = await channelApi.sendEvent(channelId, channelType, event);
|
||||||
@@ -432,8 +500,14 @@ void main() {
|
|||||||
|
|
||||||
final path = '${_getChannelUrl(channelId, channelType)}/hide';
|
final path = '${_getChannelUrl(channelId, channelType)}/hide';
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
|
when(
|
||||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
() => client.post(
|
||||||
|
path,
|
||||||
|
data: {
|
||||||
|
'clear_history': false,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
|
||||||
|
|
||||||
final res = await channelApi.hideChannel(channelId, channelType);
|
final res = await channelApi.hideChannel(channelId, channelType);
|
||||||
|
|
||||||
@@ -443,6 +517,33 @@ void main() {
|
|||||||
verifyNoMoreInteractions(client);
|
verifyNoMoreInteractions(client);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('hideChannel with clear_history: true', () async {
|
||||||
|
const channelId = 'test-channel-id';
|
||||||
|
const channelType = 'test-channel-type';
|
||||||
|
|
||||||
|
final path = '${_getChannelUrl(channelId, channelType)}/hide';
|
||||||
|
|
||||||
|
when(
|
||||||
|
() => client.post(
|
||||||
|
path,
|
||||||
|
data: {
|
||||||
|
'clear_history': true,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
|
||||||
|
|
||||||
|
final res = await channelApi.hideChannel(
|
||||||
|
channelId,
|
||||||
|
channelType,
|
||||||
|
clearHistory: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(res, isNotNull);
|
||||||
|
|
||||||
|
verify(() => client.post(path, data: any(named: 'data'))).called(1);
|
||||||
|
verifyNoMoreInteractions(client);
|
||||||
|
});
|
||||||
|
|
||||||
test('showChannel', () async {
|
test('showChannel', () async {
|
||||||
const channelId = 'test-channel-id';
|
const channelId = 'test-channel-id';
|
||||||
const channelType = 'test-channel-type';
|
const channelType = 'test-channel-type';
|
||||||
@@ -467,8 +568,14 @@ void main() {
|
|||||||
|
|
||||||
final path = '${_getChannelUrl(channelId, channelType)}/read';
|
final path = '${_getChannelUrl(channelId, channelType)}/read';
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
|
when(() => client.post(
|
||||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
path,
|
||||||
|
data: {
|
||||||
|
'message_id': messageId,
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.thenAnswer(
|
||||||
|
(_) async => successResponse(path, data: <String, dynamic>{}));
|
||||||
|
|
||||||
final res = await channelApi.markRead(
|
final res = await channelApi.markRead(
|
||||||
channelId,
|
channelId,
|
||||||
|
|||||||
@@ -35,10 +35,17 @@ void main() {
|
|||||||
final events =
|
final events =
|
||||||
List.generate(3, (index) => Event(type: 'test-event-type-$index'));
|
List.generate(3, (index) => Event(type: 'test-event-type-$index'));
|
||||||
|
|
||||||
when(() => client.post(path, data: any(named: 'data')))
|
final data = {
|
||||||
.thenAnswer((_) async => successResponse(path, data: {
|
'channel_cids': cids,
|
||||||
'events': [...events.map((it) => it.toJson())]
|
'last_sync_at': lastSyncAt.toUtc().toIso8601String(),
|
||||||
}));
|
};
|
||||||
|
|
||||||
|
when(() => client.post(
|
||||||
|
path,
|
||||||
|
data: data,
|
||||||
|
)).thenAnswer((_) async => successResponse(path, data: {
|
||||||
|
'events': [...events.map((it) => it.toJson())]
|
||||||
|
}));
|
||||||
|
|
||||||
final res = await generalApi.sync(cids, lastSyncAt);
|
final res = await generalApi.sync(cids, lastSyncAt);
|
||||||
|
|
||||||
@@ -87,8 +94,20 @@ void main() {
|
|||||||
|
|
||||||
const path = '/search';
|
const path = '/search';
|
||||||
|
|
||||||
|
final payload = jsonEncode({
|
||||||
|
'filter_conditions': filter,
|
||||||
|
'sort': sort,
|
||||||
|
'query': query,
|
||||||
|
...pagination.toJson(),
|
||||||
|
});
|
||||||
|
|
||||||
when(
|
when(
|
||||||
() => client.get(path, queryParameters: any(named: 'queryParameters')),
|
() => client.get(
|
||||||
|
path,
|
||||||
|
queryParameters: {
|
||||||
|
'payload': payload,
|
||||||
|
},
|
||||||
|
),
|
||||||
).thenAnswer((_) async => successResponse(path, data: {'results': []}));
|
).thenAnswer((_) async => successResponse(path, data: {'results': []}));
|
||||||
|
|
||||||
final res = await generalApi.searchMessages(
|
final res = await generalApi.searchMessages(
|
||||||
@@ -115,8 +134,20 @@ void main() {
|
|||||||
|
|
||||||
const path = '/search';
|
const path = '/search';
|
||||||
|
|
||||||
|
final payload = jsonEncode({
|
||||||
|
'filter_conditions': filter,
|
||||||
|
'sort': sort,
|
||||||
|
'message_filter_conditions': messageFilter,
|
||||||
|
...pagination.toJson(),
|
||||||
|
});
|
||||||
|
|
||||||
when(
|
when(
|
||||||
() => client.get(path, queryParameters: any(named: 'queryParameters')),
|
() => client.get(
|
||||||
|
path,
|
||||||
|
queryParameters: {
|
||||||
|
'payload': payload,
|
||||||
|
},
|
||||||
|
),
|
||||||
).thenAnswer((_) async => successResponse(path, data: {'results': []}));
|
).thenAnswer((_) async => successResponse(path, data: {'results': []}));
|
||||||
|
|
||||||
final res = await generalApi.searchMessages(
|
final res = await generalApi.searchMessages(
|
||||||
|
|||||||
Reference in New Issue
Block a user