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

test(amplify_authenticator): sign in with email and reset password tests #1174

Conversation

haverchuck
Copy link
Member

Description of changes:

  • sign_in_with_email test
  • reset password test

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@haverchuck haverchuck requested a review from a team as a code owner December 3, 2021 06:20
Comment on lines 108 to 131
final Stream<GraphQLResponse<String>> operation = Amplify.API.subscribe(
GraphQLRequest<String>(document: subscriptionDocument),
onEstablished: () {},
);

// TODO: Relable way to wait for subscription
await Future.delayed(const Duration(seconds: 2), () {});

operation.listen((event) async {
Map<dynamic, dynamic> parsedMap = jsonDecode(event.data);
String codeId = parsedMap['onCreateConfirmSignUpTestRun']['id'];
var codeQuery = Amplify.API.query(
request: GraphQLRequest<String>(
document: queryDocument,
variables: <String, String>{'id': codeId}));

var response = await codeQuery.response;

ConfirmationCodeTestRun result =
ConfirmationCodeTestRun.fromJson(response.data);

code = result.code!;
codeCompleter.complete(result);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final Stream<GraphQLResponse<String>> operation = Amplify.API.subscribe(
GraphQLRequest<String>(document: subscriptionDocument),
onEstablished: () {},
);
// TODO: Relable way to wait for subscription
await Future.delayed(const Duration(seconds: 2), () {});
operation.listen((event) async {
Map<dynamic, dynamic> parsedMap = jsonDecode(event.data);
String codeId = parsedMap['onCreateConfirmSignUpTestRun']['id'];
var codeQuery = Amplify.API.query(
request: GraphQLRequest<String>(
document: queryDocument,
variables: <String, String>{'id': codeId}));
var response = await codeQuery.response;
ConfirmationCodeTestRun result =
ConfirmationCodeTestRun.fromJson(response.data);
code = result.code!;
codeCompleter.complete(result);
});
final subscriptionEstablished = Completer<void>();
final Stream<GraphQLResponse<String>> operation = Amplify.API.subscribe(
GraphQLRequest<String>(document: subscriptionDocument),
onEstablished: subscriptionEstablished.complete,
);
// Wait for subscription to establish with server, to ensure no errors
// in connection.
await subscriptionEstablished.future;
final codeFuture = operation.first.then((event) async {
Map<dynamic, dynamic> parsedMap = jsonDecode(event.data);
String codeId = parsedMap['onCreateConfirmSignUpTestRun']['id'];
var codeQuery = Amplify.API.query(
request: GraphQLRequest<String>(
document: queryDocument,
variables: <String, String>{'id': codeId}));
var response = await codeQuery.response;
ConfirmationCodeTestRun result =
ConfirmationCodeTestRun.fromJson(response.data);
return result.code!;
});
// ...
/// And I type a valid confirmation code
final code = await codeFuture;
await confirmSignUpPage.enterCode(code.trim());

additionalConfigs: [AmplifyAPI()]);
});

tearDownAll(() async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to do this in loadConfiguration so that it's the first thing done in all tests.

Copy link
Member Author

@haverchuck haverchuck Dec 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - but I think we will want to eventually add tests where the app starts up with a logged in use

@haverchuck haverchuck force-pushed the sign-in-with-email-and-reset-password branch from 658ee22 to bba3ae2 Compare December 3, 2021 17:30

/// Then I see "Forgot Password"
Future<void> expectForgotPassword() async {
final currentScreen = tester.widget<AuthenticatorScreen>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: currentScreen could be a getter on AuthenticatorPage

@haverchuck haverchuck merged commit 254eb16 into aws-amplify:amplify-authenticator Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants