fix(auth): improve resendCode with status tracking and return value
This commit is contained in:
@@ -21,6 +21,7 @@ void main() {
|
||||
registerFallbackValue(
|
||||
SignupStartRequest(username: '', email: '', password: ''),
|
||||
);
|
||||
registerFallbackValue(SignupResendRequest(email: ''));
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
@@ -145,4 +146,61 @@ void main() {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('resendCode', () {
|
||||
blocTest<RegisterCubit, RegisterState>(
|
||||
'returns true and sets status on success',
|
||||
build: () => cubit,
|
||||
seed: () => RegisterState(pendingEmail: 'test@example.com'),
|
||||
setUp: () {
|
||||
when(() => mockRepository.signupResend(any())).thenAnswer(
|
||||
(_) async => SignupStartResponse(
|
||||
status: 'ok',
|
||||
email: 'test@example.com',
|
||||
message: 'Code sent',
|
||||
),
|
||||
);
|
||||
},
|
||||
act: (c) => c.resendCode(),
|
||||
expect: () => [
|
||||
isA<RegisterState>().having(
|
||||
(s) => s.status,
|
||||
'status',
|
||||
FormzSubmissionStatus.inProgress,
|
||||
),
|
||||
isA<RegisterState>().having(
|
||||
(s) => s.status,
|
||||
'status',
|
||||
FormzSubmissionStatus.success,
|
||||
),
|
||||
],
|
||||
verify: (_) {
|
||||
verify(() => mockRepository.signupResend(any())).called(1);
|
||||
},
|
||||
);
|
||||
|
||||
blocTest<RegisterCubit, RegisterState>(
|
||||
'returns false on error',
|
||||
build: () => cubit,
|
||||
seed: () => RegisterState(pendingEmail: 'test@example.com'),
|
||||
setUp: () {
|
||||
when(
|
||||
() => mockRepository.signupResend(any()),
|
||||
).thenThrow(ServerException('Network error'));
|
||||
},
|
||||
act: (c) => c.resendCode(),
|
||||
expect: () => [
|
||||
isA<RegisterState>().having(
|
||||
(s) => s.status,
|
||||
'status',
|
||||
FormzSubmissionStatus.inProgress,
|
||||
),
|
||||
isA<RegisterState>().having(
|
||||
(s) => s.status,
|
||||
'status',
|
||||
FormzSubmissionStatus.failure,
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user