Skip to content

Commit aa73c2d

Browse files
author
Vieltojarvi
committed
refactor: e2e tests aside from resource clean up
1 parent 7741a45 commit aa73c2d

40 files changed

Lines changed: 480 additions & 230 deletions

packages/amplify-e2e-tests/functions/mutation-appsync.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22
require('isomorphic-fetch');
3-
const AWS = require('aws-sdk');
3+
const { fromNodeProviderChain } = require('@aws-sdk/credential-providers');
44
const AWSAppSyncClient = require('aws-appsync').default;
55
const { AUTH_TYPE } = require('aws-appsync');
66
const gql = require('graphql-tag');
@@ -11,7 +11,8 @@ const runGQLMutation = async (gql_url, mutation, variables) => {
1111
region: process.env.REGION,
1212
auth: {
1313
type: AUTH_TYPE.AWS_IAM,
14-
credentials: AWS.config.credentials,
14+
// See documentation here: https://www.npmjs.com/package/@aws-sdk/credential-providers
15+
credentials: fromNodeProviderChain(),
1516
},
1617
disableOffline: true,
1718
});
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const AWS = require('aws-sdk');
2-
const awsS3Client = new AWS.S3();
1+
const { S3Client, ListObjectsV2Command } = require('@aws-sdk/client-s3');
2+
const awsS3Client = new S3Client();
33
const bucketEnvVar = '{{bucketEnvVar}}'; // This value is replaced from test
44

55
exports.handler = async () => {
6-
const listObjects = await awsS3Client
7-
.listObjectsV2({
8-
Bucket: process.env[bucketEnvVar],
9-
})
10-
.promise();
6+
const command = new ListObjectsV2Command({
7+
Bucket: process.env[bucketEnvVar],
8+
});
9+
10+
const listObjects = await awsS3Client.send(command);
1111

1212
return listObjects;
1313
};

packages/amplify-e2e-tests/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@
3030
"@aws-amplify/amplify-e2e-core": "5.7.5",
3131
"@aws-amplify/amplify-opensearch-simulator": "1.7.20",
3232
"@aws-amplify/graphql-transformer-core": "^2.11.1",
33+
"@aws-sdk/client-amplify": "3.624.0",
34+
"@aws-sdk/client-amplifyuibuilder": "3.624.0",
3335
"@aws-sdk/client-appsync": "3.624.0",
36+
"@aws-sdk/client-cloudformation": "3.624.0",
37+
"@aws-sdk/client-cloudfront": "3.624.0",
38+
"@aws-sdk/client-codebuild": "3.624.0",
39+
"@aws-sdk/client-cognito-identity-provider": "3.624.0",
3440
"@aws-sdk/client-dynamodb": "3.624.0",
41+
"@aws-sdk/client-iam": "3.624.0",
42+
"@aws-sdk/client-organizations": "3.624.0",
43+
"@aws-sdk/client-pinpoint": "3.624.0",
3544
"@aws-sdk/client-s3": "3.624.0",
3645
"@aws-sdk/client-ssm": "3.624.0",
46+
"@aws-sdk/client-sts": "3.624.0",
47+
"@aws-sdk/credential-providers": "3.624.0",
48+
"@aws-sdk/lib-storage": "3.624.0",
3749
"@babel/core": "^7.23.2",
3850
"@babel/plugin-transform-modules-commonjs": "7.10.4",
3951
"amplify-dynamodb-simulator": "2.9.24",

packages/amplify-e2e-tests/src/__tests__/api_1.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ describe('amplify add api (GraphQL)', () => {
5858
expect(graphqlApi).toBeDefined();
5959
expect(graphqlApi.apiId).toEqual(GraphQLAPIIdOutput);
6060
const tableName = `AmplifyDataStore-${graphqlApi.apiId}-${envName}`;
61-
const error = { message: null };
61+
let error: Error;
6262
try {
6363
const table = await getDDBTable(tableName, region);
64-
expect(table).toBeUndefined();
64+
expect(table.Table).toBeUndefined();
6565
} catch (ex) {
66-
Object.assign(error, ex);
66+
error = ex;
6767
}
6868
expect(error).toBeDefined();
6969
expect(error.message).toContain(`${tableName} not found`);
@@ -117,12 +117,12 @@ describe('amplify add api (GraphQL)', () => {
117117
expect(graphqlApi).toBeDefined();
118118
expect(graphqlApi.apiId).toEqual(GraphQLAPIIdOutput);
119119
const tableName = `AmplifyDataStore-${graphqlApi.apiId}-${envName}`;
120-
const error = { message: null };
120+
let error: Error;
121121
try {
122122
const table = await getDDBTable(tableName, region);
123-
expect(table).toBeUndefined();
123+
expect(table.Table).toBeUndefined();
124124
} catch (ex) {
125-
Object.assign(error, ex);
125+
error = ex;
126126
}
127127
expect(error).toBeDefined();
128128
expect(error.message).toContain(`${tableName} not found`);

packages/amplify-e2e-tests/src/__tests__/api_3.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ describe('amplify add api (GraphQL)', () => {
185185
await getAppSyncApi(GraphQLAPIIdOutput, meta.providers.awscloudformation.Region);
186186
expect(true).toBe(false); // expecting failure
187187
} catch (err) {
188-
expect(err.message).toBe(`GraphQL API ${GraphQLAPIIdOutput} not found.`);
188+
expect(err.message).toBe(`API not found.`);
189189
}
190190
});
191191
});

packages/amplify-e2e-tests/src/__tests__/api_7.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ describe('amplify add api (GraphQL)', () => {
5959
expect(graphqlApi).toBeDefined();
6060
expect(graphqlApi.apiId).toEqual(GraphQLAPIIdOutput);
6161
const tableName = `AmplifyDataStore-${graphqlApi.apiId}-${envName}`;
62-
const error = { message: null };
62+
let error: Error;
6363
try {
6464
const table = await getDDBTable(tableName, region);
65-
expect(table).toBeUndefined();
65+
expect(table.Table).toBeUndefined();
6666
} catch (ex) {
67-
Object.assign(error, ex);
67+
error = ex;
6868
}
6969
expect(error).toBeDefined();
7070
expect(error.message).toContain(`${tableName} not found`);

packages/amplify-e2e-tests/src/__tests__/api_9b.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ describe('amplify add api (GraphQL)', () => {
7474
expect(graphqlApi).toBeDefined();
7575
expect(graphqlApi.apiId).toEqual(GraphQLAPIIdOutput);
7676
const tableName = `Comment-${GraphQLAPIIdOutput}-integtest`;
77-
const error = { message: null };
77+
let error: Error;
7878
try {
7979
const table = await getDDBTable(tableName, region);
80-
expect(table).toBeUndefined();
80+
expect(table.Table).toBeUndefined();
8181
} catch (ex) {
82-
Object.assign(error, ex);
82+
error = ex;
8383
}
8484
expect(error).toBeDefined();
8585
expect(error.message).toContain(`${tableName} not found`);

packages/amplify-e2e-tests/src/__tests__/auth/admin-api.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('auth admin api tests', () => {
3131
};
3232
}
3333
const lambdaResponse = await invokeFunction(adminLambdaName, JSON.stringify(request), adminLambdaRegion);
34-
return JSON.parse(lambdaResponse.Payload.toString());
34+
return JSON.parse(lambdaResponse.Payload.transformToString());
3535
};
3636

3737
beforeAll(async () => {

packages/amplify-e2e-tests/src/__tests__/auth/hosted-ui.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ describe('hosted ui tests', () => {
135135
const updatedDomainRes = await getUserPoolDomain(hostedUIDomain, region);
136136
expect(updatedDomainRes).toBeDefined();
137137
const originalDomainRes = await getUserPoolDomain(originalHostedUIDomain, region);
138-
expect(originalDomainRes).toEqual({ DomainDescription: {} });
138+
// originalDomainRes has 2 properties $metadata and DomainDescription, we expect DomainDescription to be an empty object
139+
// $metadata property is common in SDK V3 objects
140+
expect(originalDomainRes.DomainDescription).toEqual({});
139141

140142
const deleteOriginalDomainRes = await deleteUserPoolDomain(originalHostedUIDomain, userPoolId, region);
141143
// undefined response as it throws InvalidParameterException: No such domain or user pool exists.

packages/amplify-e2e-tests/src/__tests__/auth_9.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
initJSProjectWithProfile,
1111
nspawn as spawn,
1212
} from '@aws-amplify/amplify-e2e-core';
13-
import { CognitoIdentityServiceProvider } from 'aws-sdk';
13+
import { DescribeUserPoolCommandOutput } from '@aws-sdk/client-cognito-identity-provider';
1414

1515
const defaultsSettings = {
1616
name: 'authTest',
@@ -35,10 +35,7 @@ describe('amplify auth with trigger', () => {
3535

3636
const meta = getProjectMeta(projRoot);
3737
const userPoolId = Object.keys(meta.auth).map((key) => meta.auth[key])[0].output.UserPoolId;
38-
let userPool = (await getUserPool(
39-
userPoolId,
40-
meta.providers.awscloudformation.Region,
41-
)) as CognitoIdentityServiceProvider.DescribeUserPoolResponse;
38+
let userPool = (await getUserPool(userPoolId, meta.providers.awscloudformation.Region)) as DescribeUserPoolCommandOutput;
4239

4340
expect(userPool.UserPool).toBeDefined();
4441
expect(userPool.UserPool.LambdaConfig).toBeDefined();
@@ -50,10 +47,7 @@ describe('amplify auth with trigger', () => {
5047

5148
await amplifyPushAuth(projRoot);
5249

53-
userPool = (await getUserPool(
54-
userPoolId,
55-
meta.providers.awscloudformation.Region,
56-
)) as CognitoIdentityServiceProvider.DescribeUserPoolResponse;
50+
userPool = (await getUserPool(userPoolId, meta.providers.awscloudformation.Region)) as DescribeUserPoolCommandOutput;
5751

5852
expect(userPool.UserPool).toBeDefined();
5953
expect(userPool.UserPool.EmailVerificationSubject).toBe('New code');

0 commit comments

Comments
 (0)