From 68f8db3e25b4ae7080fb4a9a326cc1131dc6a6e3 Mon Sep 17 00:00:00 2001 From: phuoc Date: Tue, 5 Dec 2023 17:01:40 +0700 Subject: [PATCH] check other dio exception Signed-off-by: phuoc --- lib/service/activation_service.dart | 3 +- lib/service/navigation_service.dart | 7 ++ test/services/activation_service_test.dart | 67 +++++++++++++++++++ .../activation_service_test.mocks.dart | 16 +++++ 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/lib/service/activation_service.dart b/lib/service/activation_service.dart index 33ef9b2ba..f65ee9206 100644 --- a/lib/service/activation_service.dart +++ b/lib/service/activation_service.dart @@ -56,8 +56,7 @@ class ActivationService { unawaited(_navigationService.showAirdropAlreadyClaimed()); break; default: - unawaited(UIHelper.showActivationError( - _navigationService.navigatorKey.currentContext!, + unawaited(_navigationService.showActivationError( e, assetToken.id, )); diff --git a/lib/service/navigation_service.dart b/lib/service/navigation_service.dart index 5c874232d..891d02b99 100644 --- a/lib/service/navigation_service.dart +++ b/lib/service/navigation_service.dart @@ -373,6 +373,13 @@ class NavigationService { } } + Future showActivationError(Object e, String id) async { + if (navigatorKey.currentContext != null && + navigatorKey.currentState?.mounted == true) { + await UIHelper.showActivationError(navigatorKey.currentContext!, e, id); + } + } + Future showAirdropClaimFailed() async { if (navigatorKey.currentContext != null && navigatorKey.currentState?.mounted == true) { diff --git a/test/services/activation_service_test.dart b/test/services/activation_service_test.dart index 87551ada9..337745790 100644 --- a/test/services/activation_service_test.dart +++ b/test/services/activation_service_test.dart @@ -99,6 +99,73 @@ void main() async { .called(1); }); + test('claimActivation: case 400', () async { + final error = activationService.claimActivation( + request: ActivationApiMock.claimDioException4xx.req, + assetToken: TokenServiceMockData.anyAssetToken); + expect(error, throwsA(ActivationApiMock.claimDioException4xx.res)); + verify(mockActivationApi + .claim(ActivationApiMock.claimDioException4xx.req)) + .called(1); + }); + + test('claimActivation: case 500', () async { + final error = activationService + .claimActivation( + request: ActivationApiMock.claimDioException5xx.req, + assetToken: TokenServiceMockData.anyAssetToken) + .then((value) { + verify(mockNavigationService.showActivationError( + value, TokenServiceMockData.anyAssetToken.id)) + .called(1); + }); + expect(error, throwsA(ActivationApiMock.claimDioException5xx.res)); + verify(mockActivationApi + .claim(ActivationApiMock.claimDioException5xx.req)) + .called(1); + }); + + test('claimActivation: case connectionTimeout', () async { + final error = activationService.claimActivation( + request: ActivationApiMock.claimConnectionTimeout.req, + assetToken: TokenServiceMockData.anyAssetToken).then((value) { + verify(mockNavigationService.showActivationError( + value, TokenServiceMockData.anyAssetToken.id)) + .called(1); + }); + expect(error, throwsA(ActivationApiMock.claimConnectionTimeout.res)); + verify(mockActivationApi + .claim(ActivationApiMock.claimConnectionTimeout.req)) + .called(1); + }); + + test('claimActivation: case receiveTimeout', () async { + final error = activationService.claimActivation( + request: ActivationApiMock.claimReceiveTimeout.req, + assetToken: TokenServiceMockData.anyAssetToken).then((value) { + verify(mockNavigationService.showActivationError( + value, TokenServiceMockData.anyAssetToken.id)) + .called(1); + }); + expect(error, throwsA(ActivationApiMock.claimReceiveTimeout.res)); + verify(mockActivationApi.claim(ActivationApiMock.claimReceiveTimeout.req)) + .called(1); + }); + + test('claimActivation: case exceptionOther', () async { + final error = activationService.claimActivation( + request: ActivationApiMock.claimDioExceptionOther.req, + assetToken: TokenServiceMockData.anyAssetToken).then((value) { + verify(mockNavigationService.showActivationError( + value, TokenServiceMockData.anyAssetToken.id)) + .called(0); + }); + expect(error, throwsA(ActivationApiMock.claimDioExceptionOther.res)); + verify(mockActivationApi + .claim(ActivationApiMock.claimDioExceptionOther.req)) + .called(1); + }); + test('claimActivation: error self claim', () async { final error = activationService .claimActivation( diff --git a/test/services/activation_service_test.mocks.dart b/test/services/activation_service_test.mocks.dart index e17058623..375f5630c 100644 --- a/test/services/activation_service_test.mocks.dart +++ b/test/services/activation_service_test.mocks.dart @@ -513,6 +513,22 @@ class MockNavigationService extends _i1.Mock implements _i9.NavigationService { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); @override + _i5.Future showActivationError( + Object? e, + String? id, + ) => + (super.noSuchMethod( + Invocation.method( + #showActivationError, + [ + e, + id, + ], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + @override _i5.Future showAirdropClaimFailed() => (super.noSuchMethod( Invocation.method( #showAirdropClaimFailed,