refactor(llc): remove dio deprecated methods

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2022-05-20 17:07:49 +05:30
committed by xsahil03x
parent e51b7b171e
commit 00bad6b7e8
3 changed files with 1 additions and 31 deletions
@@ -8,7 +8,7 @@ import 'package:stream_chat/src/core/http/token_manager.dart';
/// Authentication interceptor that refreshes the token if
/// an auth error is received
class AuthInterceptor extends Interceptor {
class AuthInterceptor extends QueuedInterceptor {
/// Initialize a new auth interceptor
AuthInterceptor(this._client, this._tokenManager);
@@ -57,9 +57,7 @@ class AuthInterceptor extends Interceptor {
final error = ErrorResponse.fromJson(data);
if (error.code == ChatErrorCode.tokenExpired.code) {
if (_tokenManager.isStatic) return handler.next(err);
_client.lock();
await _tokenManager.loadToken(refresh: true);
_client.unlock();
try {
final options = err.requestOptions;
final response = await _client.request(
@@ -76,20 +76,6 @@ class StreamHttpClient {
@visibleForTesting
final Dio httpClient;
/// Lock the current [StreamHttpClient] instance.
///
/// [StreamHttpClient] will enqueue the incoming request tasks instead
/// send them directly when [interceptor.requestOptions] is locked.
void lock() => httpClient.lock();
/// Unlock the current [StreamHttpClient] instance.
///
/// [StreamHttpClient] instance dequeue the request task。
void unlock() => httpClient.unlock();
/// Clear the current [StreamHttpClient] instance waiting queue.
void clear() => httpClient.clear();
/// Shuts down the [StreamHttpClient].
///
/// If [force] is `false` the [StreamHttpClient] will be kept alive
@@ -93,14 +93,10 @@ void main() {
when(() => tokenManager.isStatic).thenReturn(false);
when(() => client.lock()).thenReturn(() {});
final token = Token.development('test-user-id');
when(() => tokenManager.loadToken(refresh: true))
.thenAnswer((_) async => token);
when(() => client.unlock()).thenReturn(() {});
when(() => client.request(
path,
data: options.data,
@@ -127,12 +123,9 @@ void main() {
verify(() => tokenManager.isStatic).called(1);
verify(() => client.lock()).called(1);
verify(() => tokenManager.loadToken(refresh: true)).called(1);
verifyNoMoreInteractions(tokenManager);
verify(() => client.unlock()).called(1);
verify(() => client.request(
path,
data: options.data,
@@ -163,14 +156,10 @@ void main() {
when(() => tokenManager.isStatic).thenReturn(false);
when(() => client.lock()).thenReturn(() {});
final token = Token.development('test-user-id');
when(() => tokenManager.loadToken(refresh: true))
.thenAnswer((_) async => token);
when(() => client.unlock()).thenReturn(() {});
when(() => client.request(
path,
data: options.data,
@@ -193,12 +182,9 @@ void main() {
verify(() => tokenManager.isStatic).called(1);
verify(() => client.lock()).called(1);
verify(() => tokenManager.loadToken(refresh: true)).called(1);
verifyNoMoreInteractions(tokenManager);
verify(() => client.unlock()).called(1);
verify(() => client.request(
path,
data: options.data,