better moderation api tests

This commit is contained in:
Salvatore Giordano
2021-06-26 13:41:41 +02:00
parent 9857db0635
commit ddfe015513
2 changed files with 72 additions and 23 deletions
@@ -3,18 +3,17 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:stream_chat/src/core/error/error.dart';
import 'package:stream_chat/src/core/http/connection_id_manager.dart';
import 'package:stream_chat/src/core/http/interceptor/auth_interceptor.dart';
import 'package:stream_chat/src/core/http/interceptor/connection_id_interceptor.dart';
import 'package:stream_chat/src/core/http/interceptor/logging_interceptor.dart';
import 'package:stream_chat/src/core/http/stream_chat_dio_error.dart';
import 'package:stream_chat/src/core/http/token_manager.dart';
import 'package:stream_chat/src/core/error/error.dart';
import 'package:stream_chat/src/location.dart';
import 'package:stream_chat/src/core/platform_detector/platform_detector.dart';
import 'package:stream_chat/src/location.dart';
import 'package:stream_chat/version.dart';
import 'package:stream_chat/src/core/http/connection_id_manager.dart';
part 'stream_http_client_options.dart';
/// This is where we configure the base url, headers,
@@ -24,8 +24,12 @@ void main() {
const path = '/moderation/mute';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(
() => client.post(
path,
data: {'target_id': userId},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.muteUser(userId);
@@ -40,8 +44,12 @@ void main() {
const path = '/moderation/unmute';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(
() => client.post(
path,
data: {'target_id': userId},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unmuteUser(userId);
@@ -57,8 +65,15 @@ void main() {
const path = '/moderation/mute/channel';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'channel_cid': channelCid,
'expiration': expiration.inMilliseconds,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.muteChannel(
channelCid,
@@ -76,8 +91,12 @@ void main() {
const path = '/moderation/unmute/channel';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {'channel_cid': channelCid},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unmuteChannel(channelCid);
@@ -92,8 +111,14 @@ void main() {
const path = '/moderation/flag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'target_message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.flagMessage(messageId);
@@ -108,8 +133,14 @@ void main() {
const path = '/moderation/unflag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'target_message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unflagMessage(messageId);
@@ -124,8 +155,11 @@ void main() {
const path = '/moderation/flag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(path, data: {
'target_user_id': userId,
}))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.flagUser(userId);
@@ -140,8 +174,14 @@ void main() {
const path = '/moderation/unflag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'target_user_id': userId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unflagUser(userId);
@@ -157,8 +197,12 @@ void main() {
const path = '/moderation/ban';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(path, data: {
'target_user_id': targetUserId,
...options,
}))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.banUser(targetUserId, options: options);
@@ -175,7 +219,13 @@ void main() {
const path = '/moderation/ban';
when(
() => client.delete(path, queryParameters: any(named: 'queryParameters')),
() => client.delete(
path,
queryParameters: {
'target_user_id': targetUserId,
...options,
},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unbanUser(targetUserId, options: options);