I have a function
final class API {
func forgotPassword(
username: String
) -> Future<ConfirmationStatus, Never> {
Future { _ in
AWSMobileClient.default().forgotPassword(
username: username
) { forgotPasswordResult, error in
if let forgotPasswordResult = forgotPasswordResult {
switch forgotPasswordResult.forgotPasswordState {
case .confirmationCodeSent:
// show an alert to a user here
break
default:
logger.error("Error: Invalid case.")
}
} else if let error = error {
logger.error("Error occurred: \(error.localizedDescription)")
}
}
}.onFailure {
logger.error($0)
}
}
}
that will be called when a user tap on a button. I want to test it. I understand in general how should I test it. I should create a function that will be called instead of AWSMobileClient.default().forgotPassword() and it I should use it in forgotPassword test. It might be function in a extension on a protocol. And AWSMobileClient should conform to this protocol.
How should I test API.forgotPassword?
I used BrightFuture to make asynchronous requests.
Aucun commentaire:
Enregistrer un commentaire