-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! TF-2965 Add retry capability for OIDC check request
- Loading branch information
1 parent
892c38c
commit ce1a8fd
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
test/features/login/data/network/oidc_http_client_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>())); | ||
}); | ||
}); | ||
} |