From b924337d249d848b99caee4dfac13fd19d47fb62 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 Aug 2022 18:17:54 +0200 Subject: [PATCH] chore(llc): add more tests --- .../stream_chat/lib/src/client/client.dart | 2 - .../lib/src/core/api/call_api.dart | 1 - .../test/src/core/api/call_api_test.dart | 72 +++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 packages/stream_chat/test/src/core/api/call_api_test.dart diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 0654f837..73f0f95e 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -595,12 +595,10 @@ class StreamChatClient { required String callType, required String channelType, required String channelId, - Map? options, }) async { return _chatApi.call.createCall( callId: callId, callType: callType, - options: options, channelType: channelType, channelId: channelId, ); diff --git a/packages/stream_chat/lib/src/core/api/call_api.dart b/packages/stream_chat/lib/src/core/api/call_api.dart index d7deff1e..60fc6f88 100644 --- a/packages/stream_chat/lib/src/core/api/call_api.dart +++ b/packages/stream_chat/lib/src/core/api/call_api.dart @@ -24,7 +24,6 @@ class CallApi { required String callType, required String channelType, required String channelId, - Map? options, }) async { final response = await _client.post(_getChannelUrl(channelId, channelType), data: { diff --git a/packages/stream_chat/test/src/core/api/call_api_test.dart b/packages/stream_chat/test/src/core/api/call_api_test.dart new file mode 100644 index 00000000..36b173f9 --- /dev/null +++ b/packages/stream_chat/test/src/core/api/call_api_test.dart @@ -0,0 +1,72 @@ +import 'package:dio/dio.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:stream_chat/src/core/api/call_api.dart'; +import 'package:stream_chat/src/core/api/device_api.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:test/test.dart'; + +import '../../mocks.dart'; + +void main() { + Response successResponse(String path, {Object? data}) => Response( + data: data, + requestOptions: RequestOptions(path: path), + statusCode: 200, + ); + + late final client = MockHttpClient(); + late CallApi callApi; + + setUp(() { + callApi = CallApi(client); + }); + + test('getCallToken should work', () async { + const callId = 'test-call-id'; + const path = '/calls/$callId'; + + when(() => client.post( + path, + data: {}, + )) + .thenAnswer( + (_) async => successResponse(path, data: {})); + + final res = await callApi.getCallToken(callId); + + expect(res, isNotNull); + + verify(() => client.post(path, data: any(named: 'data'))).called(1); + verifyNoMoreInteractions(client); + }); + + test('createCall should work', () async { + const callId = 'test-call-id'; + const callType = 'test-call-type'; + const channelType = 'test-channel-type'; + const channelId = 'test-channel-id'; + const path = '/channels/$channelType/$channelId/call'; + + when(() => client.post( + path, + data: { + 'id': callId, + 'type': callType, + }, + )) + .thenAnswer( + (_) async => successResponse(path, data: {})); + + final res = await callApi.createCall( + callId: callId, + callType: callType, + channelType: channelType, + channelId: channelId, + ); + + expect(res, isNotNull); + + verify(() => client.post(path, data: any(named: 'data'))).called(1); + verifyNoMoreInteractions(client); + }); +}