forked from aws-amplify/amplify-flutter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(amplify_authenticator): authenticator phone OR email confirmation (…
…aws-amplify#1785) * fix(authenticator): move username selection state to authenticator state * chore; update imports * test: add integration tests for email or phone configs * chore: move username input enum
- Loading branch information
1 parent
640b276
commit 1c3d0e5
Showing
12 changed files
with
261 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
...s/amplify_authenticator/example/integration_test/confirm_sign_up_email_or_phone_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:amplify_api/amplify_api.dart'; | ||
import 'package:amplify_authenticator/amplify_authenticator.dart'; | ||
import 'package:amplify_flutter/amplify_flutter.dart'; | ||
import 'package:amplify_test/amplify_test.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import 'config.dart'; | ||
import 'pages/confirm_sign_up_page.dart'; | ||
import 'pages/sign_in_page.dart'; | ||
import 'pages/sign_up_page.dart'; | ||
import 'pages/test_utils.dart'; | ||
import 'utils/mock_data.dart'; | ||
|
||
void main() { | ||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
// resolves issue on iOS. See: https://github.com/flutter/flutter/issues/89651 | ||
binding.deferFirstFrame(); | ||
|
||
final isMobile = !kIsWeb && (Platform.isIOS || Platform.isAndroid); | ||
|
||
final authenticator = Authenticator( | ||
child: MaterialApp( | ||
builder: Authenticator.builder(), | ||
home: const Scaffold( | ||
body: Center( | ||
child: SignOutButton(), | ||
), | ||
), | ||
), | ||
); | ||
|
||
group( | ||
'confirm-sign-up', | ||
() { | ||
// Given I'm running the example with an "Email or Phone" config | ||
setUpAll(() async { | ||
await loadConfiguration( | ||
'email-or-phone', | ||
additionalConfigs: isMobile ? [AmplifyAPI()] : null, | ||
); | ||
}); | ||
|
||
setUp(signOut); | ||
|
||
tearDown(Amplify.Auth.deleteUser); | ||
|
||
// Scenario: Sign up & confirm account with email as username | ||
testWidgets( | ||
'Sign up & confirm account with email as username', | ||
(tester) async { | ||
final signUpPage = SignUpPage(tester: tester); | ||
final confirmSignUpPage = ConfirmSignUpPage(tester: tester); | ||
final signInPage = SignInPage(tester: tester); | ||
|
||
await loadAuthenticator(tester: tester, authenticator: authenticator); | ||
|
||
final email = generateEmail(); | ||
final phoneNumber = generateUSPhoneNumber(); | ||
final password = generatePassword(); | ||
|
||
final code = getOtpCode(email); | ||
|
||
await signInPage.navigateToSignUp(); | ||
|
||
// When I select email as a username | ||
await signUpPage.selectEmail(); | ||
|
||
// And I type my email address as a username | ||
await signUpPage.enterUsername(email); | ||
|
||
// And I type my password | ||
await signUpPage.enterPassword(password); | ||
|
||
// And I confirm my password | ||
await signUpPage.enterPasswordConfirmation(password); | ||
|
||
// And I enter my phone number | ||
await signUpPage.enterPhoneNumber(phoneNumber.withOutCountryCode()); | ||
|
||
// And I click the "Create Account" button | ||
await signUpPage.submitSignUp(); | ||
|
||
// And I see "Confirmation Code" | ||
confirmSignUpPage.expectConfirmationCodeIsPresent(); | ||
|
||
// And I type a valid confirmation code | ||
await confirmSignUpPage.enterCode(await code); | ||
|
||
// And I click the "Confirm" button | ||
await confirmSignUpPage.submitConfirmSignUp(); | ||
|
||
// Then I see "Sign out" | ||
await signInPage.expectAuthenticated(); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'Sign up & confirm account with phone number as username', | ||
(tester) async { | ||
final signUpPage = SignUpPage(tester: tester); | ||
final confirmSignUpPage = ConfirmSignUpPage(tester: tester); | ||
final signInPage = SignInPage(tester: tester); | ||
|
||
await loadAuthenticator(tester: tester, authenticator: authenticator); | ||
|
||
final email = generateEmail(); | ||
final phoneNumber = generateUSPhoneNumber(); | ||
final password = generatePassword(); | ||
|
||
final code = getOtpCode(email); | ||
|
||
await signInPage.navigateToSignUp(); | ||
|
||
// When I select phone number as a username | ||
await signUpPage.selectPhone(); | ||
|
||
// And I type my phone number as a username | ||
await signUpPage.enterUsername(phoneNumber.withOutCountryCode()); | ||
|
||
// And I type my password | ||
await signUpPage.enterPassword(password); | ||
|
||
// And I confirm my password | ||
await signUpPage.enterPasswordConfirmation(password); | ||
|
||
// And I enter my email address | ||
await signUpPage.enterEmail(email); | ||
|
||
// And I click the "Create Account" button | ||
await signUpPage.submitSignUp(); | ||
|
||
// And I see "Confirmation Code" | ||
confirmSignUpPage.expectConfirmationCodeIsPresent(); | ||
|
||
// And I type a valid confirmation code | ||
await confirmSignUpPage.enterCode(await code); | ||
|
||
// And I click the "Confirm" button | ||
await confirmSignUpPage.submitConfirmSignUp(); | ||
|
||
// Then I see "Sign out" | ||
await signInPage.expectAuthenticated(); | ||
}, | ||
); | ||
}, | ||
skip: !isMobile, | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/amplify_authenticator/example/integration_test/envs/auth_with_email_or_phone.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const amplifyconfig = ''' { | ||
"UserAgent": "aws-amplify-cli/2.0", | ||
"Version": "1.0" | ||
}'''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.