TF-2965 Add retry capability for OIDC check request

This commit is contained in:
DatDang
2024-09-12 16:05:06 +07:00
committed by Dat H. Pham
parent 2739a284d8
commit 0d4c266300
11 changed files with 192 additions and 18 deletions
@@ -0,0 +1,68 @@
import 'package:core/data/network/dio_client.dart';
import 'package:dio/dio.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:model/oidc/request/oidc_request.dart';
import 'package:tmail_ui_user/features/login/data/network/oidc_error.dart';
import 'package:tmail_ui_user/features/login/data/network/oidc_http_client.dart';
import 'oidc_http_client_test.mocks.dart';
@GenerateNiceMocks([MockSpec<DioClient>()])
void main() {
final dioClient = MockDioClient();
final oidcHttpClient = OIDCHttpClient(dioClient);
final requestOptions = RequestOptions();
final oidcRequest = OIDCRequest(baseUrl: '', resourceUrl: '');
group('oidc http client test:', () {
test(
'should throw CanNotFoundOIDCLinks '
'when checkOIDCIsAvailable() is called '
'and dioClient throw DioError '
'and status code is 404',
() {
// arrange
when(dioClient.get(any)).thenThrow(DioError(
requestOptions: requestOptions,
response: Response(requestOptions: requestOptions, statusCode: 404)));
// assert
expect(
() => oidcHttpClient.checkOIDCIsAvailable(oidcRequest),
throwsA(isA<CanNotFoundOIDCLinks>()));
});
test(
'should throw CanRetryOIDCException '
'when checkOIDCIsAvailable() is called '
'and dioClient throw DioError '
'and status code is not 404',
() {
// arrange
when(dioClient.get(any)).thenThrow(DioError(
requestOptions: requestOptions,
response: Response(requestOptions: requestOptions, statusCode: 403)));
// assert
expect(
() => oidcHttpClient.checkOIDCIsAvailable(oidcRequest),
throwsA(isA<CanRetryOIDCException>()));
});
test(
'should throw CanRetryOIDCException '
'when checkOIDCIsAvailable() is called '
'and dioClient throw exception that is not DioError',
() {
// arrange
when(dioClient.get(any)).thenThrow(Exception());
// assert
expect(
() => oidcHttpClient.checkOIDCIsAvailable(oidcRequest),
throwsA(isA<CanRetryOIDCException>()));
});
});
}