Skip to content

Commit bb24e90

Browse files
authored
chore(test): use Amplify Gen 2 config in unit tests (#5205)
1 parent f8f9e5f commit bb24e90

18 files changed

+300
-426
lines changed

packages/api/amplify_api_dart/test/graphql_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void main() {
9797
);
9898

9999
await Amplify.addPlugin(api);
100-
await Amplify.configure(amplifyconfig);
100+
await Amplify.configure(amplifyConfig);
101101

102102
hubEventsController = StreamController.broadcast();
103103
hubEvents = hubEventsController.stream;

packages/api/amplify_api_dart/test/plugin_configuration_test.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,12 @@ void main() {
6161
APIAuthorizationType.iam.authProviderToken,
6262
TestIamAuthProvider(),
6363
);
64-
// TODO(nikahsn): update to use AmplifyOutputs config
65-
final config = AmplifyConfig.fromJson(
66-
jsonDecode(amplifyconfig) as Map<String, Object?>,
64+
final amplifyOutputs = AmplifyOutputs.fromJson(
65+
jsonDecode(amplifyConfig) as Map<String, Object?>,
6766
);
68-
// ignore: invalid_use_of_internal_member
69-
final amplifyOutputs = config.toAmplifyOutputs();
70-
final configIamWithApiKey = AmplifyConfig.fromJson(
71-
jsonDecode(amplifyconfigwithapikey) as Map<String, Object?>,
67+
final amplifyOutputsIamWithApiKey = AmplifyOutputs.fromJson(
68+
jsonDecode(amplifyConfigIamWithApiKey) as Map<String, Object?>,
7269
);
73-
// ignore: invalid_use_of_internal_member
74-
final amplifyOutputsIamWithApiKey = configIamWithApiKey.toAmplifyOutputs();
7570

7671
group('AmplifyAPI plugin configuration', () {
7772
test(

packages/api/amplify_api_dart/test/rest_methods_test.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@ void main() {
4040
APIAuthorizationType.iam.authProviderToken,
4141
TestIamAuthProvider(),
4242
);
43-
// TODO(nikahsn): update to use AmplifyOutputs config
44-
final config = AmplifyConfig.fromJson(
45-
jsonDecode(amplifyconfig) as Map<String, Object?>,
43+
final amplifyOutputs = AmplifyOutputs.fromJson(
44+
jsonDecode(amplifyConfig) as Map<String, Object?>,
4645
);
47-
// ignore: invalid_use_of_internal_member
48-
final amplifyOutputs = config.toAmplifyOutputs();
4946
await apiPlugin.configure(
5047
config: amplifyOutputs,
5148
authProviderRepo: authProviderRepo,
Lines changed: 41 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,45 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
const amplifyconfig = '''{
5-
"UserAgent": "aws-amplify-cli/2.0",
6-
"Version": "1.0",
7-
"api": {
8-
"plugins": {
9-
"awsAPIPlugin": {
10-
"apiIntegrationTestGraphQL": {
11-
"endpointType": "GraphQL",
12-
"endpoint": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
13-
"region": "us-east-1",
14-
"authorizationType": "API_KEY",
15-
"apiKey": "abc123"
16-
},
17-
"api123": {
18-
"endpointType": "REST",
19-
"endpoint": "https://abc123.execute-api.us-east-1.amazonaws.com/test",
20-
"region": "us-east-1",
21-
"authorizationType": "AWS_IAM"
22-
}
23-
}
24-
}
25-
},
26-
"auth": {
27-
"plugins": {
28-
"awsCognitoAuthPlugin": {
29-
"UserAgent": "aws-amplify-cli/0.1.0",
30-
"Version": "0.1.0",
31-
"IdentityManager": {
32-
"Default": {}
33-
},
34-
"AppSync": {
35-
"Default": {
36-
"ApiUrl": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
37-
"Region": "us-east-1",
38-
"AuthMode": "API_KEY",
39-
"ApiKey": "abc123",
40-
"ClientDatabasePrefix": "apiIntegrationTestGraphQL_API_KEY"
41-
}
42-
},
43-
"CredentialsProvider": {
44-
"CognitoIdentity": {
45-
"Default": {
46-
"PoolId": "us-east-1:abc123",
47-
"Region": "us-east-1"
48-
}
49-
}
50-
},
51-
"CognitoUserPool": {
52-
"Default": {
53-
"PoolId": "us-east-1_abc123",
54-
"AppClientId": "abc123",
55-
"Region": "us-east-1"
56-
}
57-
},
58-
"Auth": {
59-
"Default": {
60-
"authenticationFlowType": "USER_SRP_AUTH",
61-
"socialProviders": [],
62-
"usernameAttributes": [],
63-
"signupAttributes": [
64-
"EMAIL"
65-
],
66-
"passwordProtectionSettings": {
67-
"passwordPolicyMinLength": 8,
68-
"passwordPolicyCharacters": []
69-
},
70-
"mfaConfiguration": "OFF",
71-
"mfaTypes": [
72-
"SMS"
73-
],
74-
"verificationMechanisms": [
75-
"EMAIL"
76-
]
77-
}
78-
}
79-
}
80-
}
81-
}
4+
const amplifyConfig = '''{
5+
"version": "1",
6+
"auth": {
7+
"aws_region": "us-east-1",
8+
"user_pool_id": "us-east-1_abc123",
9+
"user_pool_client_id": "abc123",
10+
"identity_pool_id": "us-east-1:abc123",
11+
"password_policy": {
12+
"min_length": 8,
13+
"require_numbers": false,
14+
"require_lowercase": false,
15+
"require_uppercase": false,
16+
"require_symbols": false
17+
},
18+
"standard_required_attributes":[
19+
"email"
20+
],
21+
"username_attributes":[],
22+
"user_verification_types":[
23+
"email"
24+
],
25+
"unauthenticated_identities_enabled": true,
26+
"mfa_configuration": "NONE",
27+
"mfa_methods":[
28+
"SMS"
29+
]
30+
},
31+
"data": {
32+
"aws_region": "us-east-1",
33+
"url": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
34+
"api_key": "abc123",
35+
"default_authorization_type": "API_KEY",
36+
"authorization_types":[]
37+
},
38+
"rest_api": {
39+
"api123": {
40+
"aws_region": "us-east-1",
41+
"url": "https://abc123.execute-api.us-east-1.amazonaws.com/test",
42+
"authorization_type": "AWS_IAM"
43+
}
44+
}
8245
}''';
Lines changed: 41 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,46 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
const amplifyconfigwithapikey = '''{
5-
"UserAgent": "aws-amplify-cli/2.0",
6-
"Version": "1.0",
7-
"api": {
8-
"plugins": {
9-
"awsAPIPlugin": {
10-
"apiIntegrationTestGraphQL": {
11-
"endpointType": "GraphQL",
12-
"endpoint": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
13-
"region": "us-east-1",
14-
"authorizationType": "AWS_IAM",
15-
"apiKey": "abc123"
16-
},
17-
"api123": {
18-
"endpointType": "REST",
19-
"endpoint": "https://abc123.execute-api.us-east-1.amazonaws.com/test",
20-
"region": "us-east-1",
21-
"authorizationType": "AWS_IAM"
22-
}
23-
}
24-
}
25-
},
4+
const amplifyConfigIamWithApiKey = ''' {
5+
"version": "1",
266
"auth": {
27-
"plugins": {
28-
"awsCognitoAuthPlugin": {
29-
"UserAgent": "aws-amplify-cli/0.1.0",
30-
"Version": "0.1.0",
31-
"IdentityManager": {
32-
"Default": {}
33-
},
34-
"AppSync": {
35-
"Default": {
36-
"ApiUrl": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
37-
"Region": "us-east-1",
38-
"AuthMode": "AWS_IAM",
39-
"ClientDatabasePrefix": "apiIntegrationTestGraphQL_API_KEY"
40-
}
41-
},
42-
"CredentialsProvider": {
43-
"CognitoIdentity": {
44-
"Default": {
45-
"PoolId": "us-east-1:abc123",
46-
"Region": "us-east-1"
47-
}
48-
}
49-
},
50-
"CognitoUserPool": {
51-
"Default": {
52-
"PoolId": "us-east-1_abc123",
53-
"AppClientId": "abc123",
54-
"Region": "us-east-1"
55-
}
56-
},
57-
"Auth": {
58-
"Default": {
59-
"authenticationFlowType": "USER_SRP_AUTH",
60-
"socialProviders": [],
61-
"usernameAttributes": [],
62-
"signupAttributes": [
63-
"EMAIL"
64-
],
65-
"passwordProtectionSettings": {
66-
"passwordPolicyMinLength": 8,
67-
"passwordPolicyCharacters": []
68-
},
69-
"mfaConfiguration": "OFF",
70-
"mfaTypes": [
71-
"SMS"
72-
],
73-
"verificationMechanisms": [
74-
"EMAIL"
75-
]
76-
}
77-
}
78-
}
79-
}
7+
"aws_region": "us-east-1",
8+
"user_pool_id": "us-east-1_abc123",
9+
"user_pool_client_id": "abc123",
10+
"identity_pool_id": "us-east-1:abc123",
11+
"password_policy": {
12+
"min_length": 8,
13+
"require_numbers": false,
14+
"require_lowercase": false,
15+
"require_uppercase": false,
16+
"require_symbols": false
17+
},
18+
"standard_required_attributes":[
19+
"email"
20+
],
21+
"username_attributes":[],
22+
"user_verification_types":[
23+
"email"
24+
],
25+
"unauthenticated_identities_enabled": true,
26+
"mfa_configuration": "NONE",
27+
"mfa_methods":[
28+
"SMS"
29+
]
30+
},
31+
"data": {
32+
"aws_region": "us-east-1",
33+
"url": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql",
34+
"api_key": "abc123",
35+
"default_authorization_type": "AWS_IAM",
36+
"authorization_types":[]
37+
},
38+
"rest_api": {
39+
"api123": {
40+
"aws_region": "us-east-1",
41+
"url": "https://abc123.execute-api.us-east-1.amazonaws.com/test",
42+
"authorization_type": "AWS_IAM"
43+
}
8044
}
81-
}''';
45+
}
46+
''';

0 commit comments

Comments
 (0)