I have an iOS app with Cognito authentication implemented very similar to CognitoYourUserPoolsSample. Most important fragments are in SignInViewController.swift:
When user taps Sign In, asynch task is added:
var passwordAuthenticationCompletion: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>? ... @IBAction func signInPressed<...> { ... let authDetails = AWSCognitoIdentityPasswordAuthenticationDetails(username: self.username.text!, password: self.password.text! ) self.passwordAuthenticationCompletion?.set(result: authDetails) ...
Later we get either success or error response:
extension SignInViewController: AWSCognitoIdentityPasswordAuthentication { public func getDetails<...> { DispatchQueue.main.async { // do something in case of success ... public func didCompleteStepWithError<...> { DispatchQueue.main.async { // do something in case of failure ...
I also have a UI test, which fills username and password, clicks Sign In and validates response:
class MyAppUITests: XCTestCase {
...
func loginTest() {
let usernameField = <...>
usernameField.tap()
usernameField.typeText("user@domain.com")
...
// same for password field
// then click Sign In
<...>.buttons["Sign In"].tap()
Currently this test is working against the actual AWS infrastructure, which is not ideal for many reasons. What I want is to simulate various responses from AWS instead.
How can I do that?
I think the best would be mocking or stabbing task queue, but I'm not sure how to approach that. Any direction will be much appreciated. If you handled similar task in an alternative way, I'd like to hear your ideas too, thanks.