Skip to content

Commit

Permalink
test(deriv_auth): add test cases for reset pass refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sahani-deriv committed Jan 31, 2024
1 parent c75906c commit afa42b3
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:deriv_auth/deriv_auth.dart';
import 'package:deriv_auth/features/reset_password/services/base_reset_password_service.dart';
import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart';
import 'package:flutter_deriv_api/api/models/base_exception_model.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';
Expand Down Expand Up @@ -77,6 +79,25 @@ void main() {
});
});

test(
'Should emit [DerivResetPassErrorState] with isLinkExpired true if chagePassword is unsuccessful.',
() async {
when(() => service.resetPassword(
verificationCode: any(named: 'verificationCode'),
newPassword: any(named: 'newPassword')))
.thenAnswer((_) async => Future<bool>.value(false));

await resetPassCubit.changePassword(
token: '123', newPassword: 'newpassword');
expect(
resetPassCubit.state,
isA<DerivResetPassErrorState>().having(
(DerivResetPassErrorState state) => state.isLinkExpired,
'reset password link expired',
true,
));
});

test(
'Should emit [DerivResetPassErrorState] if chagePassword throws an exception.',
() async {
Expand All @@ -88,4 +109,27 @@ void main() {
token: '123', newPassword: 'newpassword');
expect(resetPassCubit.state, isA<DerivResetPassErrorState>());
});

test('''Should emit [DerivResetPassErrorState] with isLinkExpired set to true
if chagePassword throws an [BaseAPIException] with error code InvalidToken.''',
() async {
when(() =>
service.resetPassword(
verificationCode: any(named: 'verificationCode'),
newPassword: any(named: 'newPassword'))).thenThrow(BaseAPIException(
baseExceptionModel: BaseExceptionModel(
code: 'InvalidToken',
)));

await resetPassCubit.changePassword(
token: '123', newPassword: 'newpassword');

expect(
resetPassCubit.state,
isA<DerivResetPassErrorState>().having(
(DerivResetPassErrorState state) => state.isLinkExpired,
'reset password link expired',
true,
));
});
}

0 comments on commit afa42b3

Please sign in to comment.