Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Provide documentation for testing with Amplify #1256

Open
Jordan-Nelson opened this issue Jan 11, 2022 · 10 comments
Open

[Docs] Provide documentation for testing with Amplify #1256

Jordan-Nelson opened this issue Jan 11, 2022 · 10 comments
Labels
Documentation Improvements or fixes to public documentation (docs.amplify.aws, pub.dev, readmes). feature-request A request for a new feature or an enhancement to an existing API or category.

Comments

@Jordan-Nelson
Copy link
Member

Context

There have been a few issues opened asking questions about testing flutter apps with Amplify (unit and integration). The amplify flutter docs currently don't offer much guidance on testing.

Request

At a minimum:

  • Add basic documentation for writing unit tests and integration tests with Amplify Flutter. A simple example and link to the flutter docs may be sufficient.
  • Callout any known limitations (hosted UI)

Ideally:

  • Provide info on writing integration tests with hosted UI. Currently this is a limitation, and a work around would need to be identified. See: How to write integration test for social login #950
  • Provide suggested solutions to some of the challenging aspects of writing integration tests with Amplify (confirmation codes) that we have already solved for our own integration testing needs.

Related issues

@Jordan-Nelson Jordan-Nelson changed the title [Feature Request] Provide documentation for testing with Amplify [Docs] Provide documentation for testing with Amplify Jan 11, 2022
@Jordan-Nelson Jordan-Nelson added Documentation Improvements or fixes to public documentation (docs.amplify.aws, pub.dev, readmes). and removed docs labels Jan 18, 2022
@94Sip
Copy link

94Sip commented Aug 7, 2024

did this documentation ever get created? If so, can you point me to it? I'd like to understand how to do integration testing when using the Amplify Authenticator component and other Amplify libraries needing Auth (storage and API, in particular).

Thank you.

@Jordan-Nelson
Copy link
Member Author

@94Sip no, I don't believe there are any public docs on integration or end to end testing. Are you looking to write tests that make network calls to AWS services (a full end to end test), or are you looking to stub/mock some portion to test your application logic?

@94Sip
Copy link

94Sip commented Aug 8, 2024

I am looking to do end-to-end testing - I am using the Authenticator UI component, and all my API calls are AWS_IAM authorization. @Jordan-Nelson

@Jordan-Nelson
Copy link
Member Author

Got it. Is there a particular challenge you are facing with the tests? One common problem with Auth is creating new users, as by default that requires sending a confirmation code either via phone or email.

@94Sip
Copy link

94Sip commented Aug 8, 2024

nothing in general, but I would like to see how it is done. Meaning, do I just load my app (just like all the integration test scenarios show), let Amplify configure() happen and then wait for pump and settle for the Authenticator to show the login form, and then proceed as usual? I guess just seeing some working code, or even pseudo code for this type of scenario would be helpful. Do I need to do anything so that the IAM authorization works as expected in an integration testing setup?

And thank you for helping with this @Jordan-Nelson !

@94Sip
Copy link

94Sip commented Aug 12, 2024

Update @Jordan-Nelson - I was able to get it to work! Its probably worth saying that I had to spend a good bit of time hunting in the Widget Explorer to figure out the widgets/types that I needed to interact with that are part of the Authenticator UI component. That was easily the hardest part.

After typing in my thoughts above, I figured why not just try it out, and sure enough, it worked.

Caveat: I did not create a integration test for creating new users.

@Jordan-Nelson
Copy link
Member Author

Got it. Most of the widgets in the Authenticator have specific Keys, which we use for our own widget tests. These are not part of the public API and could change in the future, but could be helpful for testing.

@94Sip
Copy link

94Sip commented Aug 14, 2024

yes! I looked thru Widget explored to identify those keys - i didn't realize they were documented in source, as you linked.

Question @Jordan-Nelson - back to one of your previous questions: how do I integration test user signup where a confirmation code is sent by Cognito?

@Jordan-Nelson
Copy link
Member Author

@94Sip there are a couple options you could use in a testing environment. You would not want to use any of these options in a production environment.

  1. Automatically confirm the user, removing the need for confirmation via code. See this post for an example of how to do that. This is probably the easiest option if you aren't too concerned about including the confirmation flow in your test.
  2. Use a Cognito lambda trigger to capture and store the confirmation code. Cognito offers triggers (lambdas) that can be set up to run on many different events. One of those events is a Custom Email Sender or a Customer SMS Sender. These lambda triggers will run each time Cognito would normally send a email or SMS. You can use this to intercept the code and store it somewhere (for example AppSync) and then your automated test can fetch it. This is how we test the full sign up process in our end to end tests in Amplify. Setting this up is fairly involved. I would only recommend this if you had a good reason to test this flow as part of your e2e tests. You can see how we use the AWS CDK to set up these triggers in our e2e tests here: https://github.com/aws-amplify/amplify-flutter/tree/main/infra-gen2/infra-common/src/auth-user-extensions. That directory has some other utils for creating and deleting users as well.

@94Sip
Copy link

94Sip commented Aug 15, 2024

Extremely helpful @Jordan-Nelson thank you!

@Jordan-Nelson Jordan-Nelson added the feature-request A request for a new feature or an enhancement to an existing API or category. label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or fixes to public documentation (docs.amplify.aws, pub.dev, readmes). feature-request A request for a new feature or an enhancement to an existing API or category.
Projects
None yet
Development

No branches or pull requests

2 participants