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

chore(test): use Amplify Gen 2 config in unit tests #5205

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api/amplify_api_dart/test/graphql_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void main() {
);

await Amplify.addPlugin(api);
await Amplify.configure(amplifyconfig);
await Amplify.configure(amplifyConfig);

hubEventsController = StreamController.broadcast();
hubEvents = hubEventsController.stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,12 @@ void main() {
APIAuthorizationType.iam.authProviderToken,
TestIamAuthProvider(),
);
// TODO(nikahsn): update to use AmplifyOutputs config
final config = AmplifyConfig.fromJson(
jsonDecode(amplifyconfig) as Map<String, Object?>,
final amplifyOutputs = AmplifyOutputs.fromJson(
jsonDecode(amplifyConfig) as Map<String, Object?>,
);
// ignore: invalid_use_of_internal_member
final amplifyOutputs = config.toAmplifyOutputs();
final configIamWithApiKey = AmplifyConfig.fromJson(
jsonDecode(amplifyconfigwithapikey) as Map<String, Object?>,
final amplifyOutputsIamWithApiKey = AmplifyOutputs.fromJson(
jsonDecode(amplifyConfigIamWithApiKey) as Map<String, Object?>,
);
// ignore: invalid_use_of_internal_member
final amplifyOutputsIamWithApiKey = configIamWithApiKey.toAmplifyOutputs();

group('AmplifyAPI plugin configuration', () {
test(
Expand Down
7 changes: 2 additions & 5 deletions packages/api/amplify_api_dart/test/rest_methods_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ void main() {
APIAuthorizationType.iam.authProviderToken,
TestIamAuthProvider(),
);
// TODO(nikahsn): update to use AmplifyOutputs config
final config = AmplifyConfig.fromJson(
jsonDecode(amplifyconfig) as Map<String, Object?>,
final amplifyOutputs = AmplifyOutputs.fromJson(
jsonDecode(amplifyConfig) as Map<String, Object?>,
);
// ignore: invalid_use_of_internal_member
final amplifyOutputs = config.toAmplifyOutputs();
await apiPlugin.configure(
config: amplifyOutputs,
authProviderRepo: authProviderRepo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,82 +1,45 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

const amplifyconfig = '''{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"api": {
"plugins": {
"awsAPIPlugin": {
"apiIntegrationTestGraphQL": {
"endpointType": "GraphQL",
"endpoint": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
"region": "us-east-1",
"authorizationType": "API_KEY",
"apiKey": "abc123"
},
"api123": {
"endpointType": "REST",
"endpoint": "https://abc123.execute-api.us-east-1.amazonaws.com/test",
"region": "us-east-1",
"authorizationType": "AWS_IAM"
}
}
}
},
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"AppSync": {
"Default": {
"ApiUrl": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
"Region": "us-east-1",
"AuthMode": "API_KEY",
"ApiKey": "abc123",
"ClientDatabasePrefix": "apiIntegrationTestGraphQL_API_KEY"
}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-east-1:abc123",
"Region": "us-east-1"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "us-east-1_abc123",
"AppClientId": "abc123",
"Region": "us-east-1"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [],
"usernameAttributes": [],
"signupAttributes": [
"EMAIL"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"EMAIL"
]
}
}
}
}
}
const amplifyConfig = '''{
"version": "1",
"auth": {
"aws_region": "us-east-1",
"user_pool_id": "us-east-1_abc123",
"user_pool_client_id": "abc123",
"identity_pool_id": "us-east-1:abc123",
"password_policy": {
"min_length": 8,
"require_numbers": false,
"require_lowercase": false,
"require_uppercase": false,
"require_symbols": false
},
"standard_required_attributes":[
"email"
],
"username_attributes":[],
"user_verification_types":[
"email"
],
"unauthenticated_identities_enabled": true,
"mfa_configuration": "NONE",
"mfa_methods":[
"SMS"
]
},
"data": {
"aws_region": "us-east-1",
"url": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
"api_key": "abc123",
"default_authorization_type": "API_KEY",
"authorization_types":[]
},
"rest_api": {
"api123": {
"aws_region": "us-east-1",
"url": "https://abc123.execute-api.us-east-1.amazonaws.com/test",
"authorization_type": "AWS_IAM"
}
}
}''';
Original file line number Diff line number Diff line change
@@ -1,81 +1,46 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

const amplifyconfigwithapikey = '''{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"api": {
"plugins": {
"awsAPIPlugin": {
"apiIntegrationTestGraphQL": {
"endpointType": "GraphQL",
"endpoint": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
"region": "us-east-1",
"authorizationType": "AWS_IAM",
"apiKey": "abc123"
},
"api123": {
"endpointType": "REST",
"endpoint": "https://abc123.execute-api.us-east-1.amazonaws.com/test",
"region": "us-east-1",
"authorizationType": "AWS_IAM"
}
}
}
},
const amplifyConfigIamWithApiKey = ''' {
"version": "1",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"AppSync": {
"Default": {
"ApiUrl": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
"Region": "us-east-1",
"AuthMode": "AWS_IAM",
"ClientDatabasePrefix": "apiIntegrationTestGraphQL_API_KEY"
}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-east-1:abc123",
"Region": "us-east-1"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "us-east-1_abc123",
"AppClientId": "abc123",
"Region": "us-east-1"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [],
"usernameAttributes": [],
"signupAttributes": [
"EMAIL"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"EMAIL"
]
}
}
}
}
"aws_region": "us-east-1",
"user_pool_id": "us-east-1_abc123",
"user_pool_client_id": "abc123",
"identity_pool_id": "us-east-1:abc123",
"password_policy": {
"min_length": 8,
"require_numbers": false,
"require_lowercase": false,
"require_uppercase": false,
"require_symbols": false
},
"standard_required_attributes":[
"email"
],
"username_attributes":[],
"user_verification_types":[
"email"
],
"unauthenticated_identities_enabled": true,
"mfa_configuration": "NONE",
"mfa_methods":[
"SMS"
]
},
"data": {
"aws_region": "us-east-1",
"url": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
"api_key": "abc123",
"default_authorization_type": "AWS_IAM",
"authorization_types":[]
},
"rest_api": {
"api123": {
"aws_region": "us-east-1",
"url": "https://abc123.execute-api.us-east-1.amazonaws.com/test",
"authorization_type": "AWS_IAM"
}
}
}''';
}
''';
Loading
Loading