Skip to content

Commit

Permalink
check other dio exception
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Dec 5, 2023
1 parent f7a01d9 commit 68f8db3
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/service/activation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class ActivationService {
unawaited(_navigationService.showAirdropAlreadyClaimed());
break;
default:
unawaited(UIHelper.showActivationError(
_navigationService.navigatorKey.currentContext!,
unawaited(_navigationService.showActivationError(
e,
assetToken.id,
));
Expand Down
7 changes: 7 additions & 0 deletions lib/service/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ class NavigationService {
}
}

Future<void> showActivationError(Object e, String id) async {
if (navigatorKey.currentContext != null &&
navigatorKey.currentState?.mounted == true) {
await UIHelper.showActivationError(navigatorKey.currentContext!, e, id);
}
}

Future<void> showAirdropClaimFailed() async {
if (navigatorKey.currentContext != null &&
navigatorKey.currentState?.mounted == true) {
Expand Down
67 changes: 67 additions & 0 deletions test/services/activation_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions test/services/activation_service_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,22 @@ class MockNavigationService extends _i1.Mock implements _i9.NavigationService {
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);
@override
_i5.Future<void> showActivationError(
Object? e,
String? id,
) =>
(super.noSuchMethod(
Invocation.method(
#showActivationError,
[
e,
id,
],
),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);
@override
_i5.Future<void> showAirdropClaimFailed() => (super.noSuchMethod(
Invocation.method(
#showAirdropClaimFailed,
Expand Down

0 comments on commit 68f8db3

Please sign in to comment.