fix(auth): set failure status on sendCodeSilently error
This commit is contained in:
@@ -153,7 +153,15 @@ class RegisterCubit extends Cubit<RegisterState> {
|
||||
}
|
||||
|
||||
Future<bool> resendCode() async {
|
||||
if (state.pendingEmail == null) return false;
|
||||
if (state.pendingEmail == null) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: FormzSubmissionStatus.failure,
|
||||
errorMessage: '验证码发送失败,请返回上一步重试',
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
emit(state.copyWith(status: FormzSubmissionStatus.inProgress));
|
||||
|
||||
@@ -200,7 +208,13 @@ class RegisterCubit extends Cubit<RegisterState> {
|
||||
);
|
||||
} catch (e) {
|
||||
final message = e is ApiException ? e.message : '验证码发送失败,请重试';
|
||||
emit(state.copyWith(isSending: false, errorMessage: message));
|
||||
emit(
|
||||
state.copyWith(
|
||||
isSending: false,
|
||||
status: FormzSubmissionStatus.failure,
|
||||
errorMessage: message,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ void main() {
|
||||
);
|
||||
|
||||
blocTest<RegisterCubit, RegisterState>(
|
||||
'restores isSending to false and sets errorMessage on error',
|
||||
'restores isSending to false and sets errorMessage and failure status on error',
|
||||
build: () => cubit,
|
||||
seed: () => RegisterState(
|
||||
username: const Username.dirty('testuser'),
|
||||
@@ -107,7 +107,9 @@ void main() {
|
||||
predicate<RegisterState>((state) => state.isSending == true),
|
||||
predicate<RegisterState>(
|
||||
(state) =>
|
||||
state.isSending == false && state.errorMessage == 'Network error',
|
||||
state.isSending == false &&
|
||||
state.errorMessage == 'Network error' &&
|
||||
state.status == FormzSubmissionStatus.failure,
|
||||
),
|
||||
],
|
||||
verify: (_) {
|
||||
@@ -148,6 +150,21 @@ void main() {
|
||||
});
|
||||
|
||||
group('resendCode', () {
|
||||
blocTest<RegisterCubit, RegisterState>(
|
||||
'returns false and sets failure status when pendingEmail is null',
|
||||
build: () => cubit,
|
||||
seed: () => RegisterState(pendingEmail: null),
|
||||
act: (c) => c.resendCode(),
|
||||
expect: () => [
|
||||
isA<RegisterState>()
|
||||
.having((s) => s.status, 'status', FormzSubmissionStatus.failure)
|
||||
.having((s) => s.errorMessage, 'errorMessage', '验证码发送失败,请返回上一步重试'),
|
||||
],
|
||||
verify: (_) {
|
||||
verifyNever(() => mockRepository.signupResend(any()));
|
||||
},
|
||||
);
|
||||
|
||||
blocTest<RegisterCubit, RegisterState>(
|
||||
'returns true and sets status on success',
|
||||
build: () => cubit,
|
||||
|
||||
Reference in New Issue
Block a user