Skip to content

Commit

Permalink
test(authenticator): add golden tests for new configs (aws-amplify#1831)
Browse files Browse the repository at this point in the history
* chore: add stubs for auth cognito and amplify

* test: refactor tests, add tests for new configs

* chore: regenerate golden files

* chore: update comment, fix accidential cmd f change

* chore: add license headers

* chore: make internal mocks private
  • Loading branch information
Jordan-Nelson committed Dec 1, 2022
1 parent bc57d1d commit 263eeb7
Show file tree
Hide file tree
Showing 149 changed files with 1,022 additions and 316 deletions.
2 changes: 2 additions & 0 deletions packages/amplify_authenticator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dependencies:
dev_dependencies:
amplify_lints:
path: ../amplify_lints
amplify_test:
path: ../amplify_test
flutter_test:
sdk: flutter
mocktail: ^0.2.0
Expand Down
77 changes: 77 additions & 0 deletions packages/amplify_authenticator/test/ui/authenticator_app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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.

// ignore_for_file: diagnostic_describe_all_properties

import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_test/amplify_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

const authenticatorKey = Key('authenticator_app');
final authenticatorFinder = find.byKey(authenticatorKey);

/// Authenticator Test App, using Amplify and Auth stubs.
class AuthenticatorApp extends StatefulWidget {
const AuthenticatorApp({
Key? key,
required this.config,
this.lightTheme,
this.darkTheme,
this.initialStep = AuthenticatorStep.signIn,
}) : super(key: key);

final String config;
final ThemeData? lightTheme;
final ThemeData? darkTheme;
final AuthenticatorStep initialStep;

@override
State<AuthenticatorApp> createState() => _AuthenticatorAppState();
}

class _AuthenticatorAppState extends State<AuthenticatorApp> {
Future<void> _configureAmplify() async {
try {
Amplify = AmplifyStub();
await Amplify.addPlugin(AmplifyAuthCognitoStub());
await Amplify.configure(widget.config);
} on Exception catch (e) {
print(e);
}
}

@override
void initState() {
_configureAmplify();
super.initState();
}

@override
Widget build(BuildContext context) {
return Authenticator(
initialStep: widget.initialStep,
key: authenticatorKey,
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: widget.lightTheme,
darkTheme: widget.darkTheme,
themeMode: ThemeMode.system,
builder: Authenticator.builder(),
home: const SizedBox.shrink(),
),
);
}
}
36 changes: 0 additions & 36 deletions packages/amplify_authenticator/test/ui/configs/default_config.dart

This file was deleted.

53 changes: 53 additions & 0 deletions packages/amplify_authenticator/test/ui/configs/email_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const emailConfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "",
"Region": ""
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "",
"AppClientId": "",
"Region": ""
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [],
"usernameAttributes": [
"EMAIL"
],
"signupAttributes": [
"EMAIL"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"EMAIL"
]
}
}
}
}
}
}''';
53 changes: 53 additions & 0 deletions packages/amplify_authenticator/test/ui/configs/phone_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const phoneNumberConfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "",
"Region": ""
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "",
"AppClientId": "",
"Region": ""
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [],
"usernameAttributes": [
"PHONE_NUMBER"
],
"signupAttributes": [
"EMAIL"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"EMAIL"
]
}
}
}
}
}
}''';
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const socialProviderConfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "",
"Region": ""
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "",
"AppClientId": "",
"Region": ""
}
},
"Auth": {
"Default": {
"OAuth": {
"WebDomain": "",
"AppClientId": "",
"SignInRedirectURI": "",
"SignOutRedirectURI": "",
"Scopes": [
"phone",
"email",
"openid",
"profile",
"aws.cognito.signin.user.admin"
]
},
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [
"APPLE",
"AMAZON",
"FACEBOOK",
"GOOGLE"
],
"usernameAttributes": [
"EMAIL"
],
"signupAttributes": [
"EMAIL"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"EMAIL"
]
}
}
}
}
}
}''';
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const usernameWithAttributesConfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "",
"Region": ""
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "",
"AppClientId": "",
"Region": ""
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [],
"usernameAttributes": [],
"signupAttributes": [
"EMAIL",
"PREFERRED_USERNAME",
"BIRTHDATE"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"EMAIL"
]
}
}
}
}
}
}''';
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 263eeb7

Please sign in to comment.