Skip to content

Commit

Permalink
fixup! TF-2965 Add retry capability for OIDC check request
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora committed Sep 16, 2024
1 parent 892c38c commit ce1a8fd
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/features/login/data/network/oidc_http_client_test.dart
Original file line number Diff line number Diff line change
@@ -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>()));
});
});
}

0 comments on commit ce1a8fd

Please sign in to comment.