Skip to content

Commit 435ed0d

Browse files
author
aws-amplify-bot
committed
refactor: e2e-core and some e2e-test files
1 parent 998b553 commit 435ed0d

10 files changed

Lines changed: 1647 additions & 714 deletions

File tree

packages/amplify-e2e-core/package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,30 @@
2323
},
2424
"dependencies": {
2525
"@aws-amplify/amplify-cli-core": "4.4.1",
26+
"@aws-sdk/client-amplifybackend": "3.624.0",
27+
"@aws-sdk/client-amplifyuibuilder": "3.624.0",
28+
"@aws-sdk/client-appsync": "3.624.0",
29+
"@aws-sdk/client-cloudformation": "3.624.0",
30+
"@aws-sdk/client-cloudwatch-events": "3.624.0",
31+
"@aws-sdk/client-cloudwatch-logs": "3.624.0",
32+
"@aws-sdk/client-cognito-identity": "3.624.0",
33+
"@aws-sdk/client-cognito-identity-provider": "3.624.0",
34+
"@aws-sdk/client-dynamodb": "3.624.0",
35+
"@aws-sdk/client-iam": "3.624.0",
36+
"@aws-sdk/client-kinesis": "3.624.0",
37+
"@aws-sdk/client-lambda": "3.624.0",
38+
"@aws-sdk/client-lex-model-building-service": "3.624.0",
39+
"@aws-sdk/client-location": "3.624.0",
40+
"@aws-sdk/client-pinpoint": "3.624.0",
41+
"@aws-sdk/client-rekognition": "3.624.0",
42+
"@aws-sdk/client-s3": "3.624.0",
43+
"@aws-sdk/client-ssm": "3.624.0",
2644
"@aws-sdk/client-sts": "3.624.0",
2745
"@aws-sdk/credential-providers": "3.624.0",
46+
"@aws-sdk/lib-dynamodb": "3.624.0",
2847
"amplify-headless-interface": "1.17.7",
2948
"aws-amplify": "^5.3.16",
3049
"aws-appsync": "^4.1.1",
31-
"aws-sdk": "^2.1464.0",
3250
"chalk": "^4.1.1",
3351
"dotenv": "^8.2.0",
3452
"execa": "^5.1.1",

packages/amplify-e2e-core/src/categories/lambda-function.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW, getCLIPath, getProjectMeta, getBackendAmplifyMeta, invokeFunction } from '..';
2-
import { Lambda } from 'aws-sdk';
2+
import { InvokeCommandOutput } from '@aws-sdk/client-lambda';
33
import { singleSelect, multiSelect, moveUp, moveDown } from '../utils/selectors';
44
import { globSync } from 'glob';
55
import * as path from 'path';
@@ -636,21 +636,18 @@ export const functionMockAssert = (
636636
});
637637
};
638638

639-
export const functionCloudInvoke = async (
640-
cwd: string,
641-
settings: { funcName: string; payload: string },
642-
): Promise<Lambda.InvocationResponse> => {
639+
export const functionCloudInvoke = async (cwd: string, settings: { funcName: string; payload: string }): Promise<InvokeCommandOutput> => {
643640
const meta = getProjectMeta(cwd);
644641
const lookupName = settings.funcName;
645642
expect(meta.function[lookupName]).toBeDefined();
646643
const { Name: functionName, Region: region } = meta.function[lookupName].output;
647644
expect(functionName).toBeDefined();
648645
expect(region).toBeDefined();
649646
const result = await invokeFunction(functionName, settings.payload, region);
650-
if (!result.$response.data) {
651-
throw new Error('No data in lambda response');
647+
if (!result.Payload) {
648+
throw new Error('No payload in lambda response');
652649
}
653-
return result.$response.data as Lambda.InvocationResponse;
650+
return result;
654651
};
655652

656653
const getTemplateChoices = (runtime: FunctionRuntimes) => {

packages/amplify-e2e-core/src/utils/auth-utils.ts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { Amplify, Auth } from 'aws-amplify';
22
import AWSAppSyncClient, { AUTH_TYPE } from 'aws-appsync';
3-
import { CognitoIdentityServiceProvider } from 'aws-sdk';
3+
import {
4+
CognitoIdentityProviderClient,
5+
AdminCreateUserCommand,
6+
AdminAddUserToGroupCommand,
7+
} from '@aws-sdk/client-cognito-identity-provider';
48
import fs from 'fs-extra';
59
import path from 'path';
610
import { getAwsAndroidConfig, getAwsIOSConfig, getBackendAmplifyMeta, getCLIInputs, getProjectMeta, setCLIInputs } from './projectMeta';
@@ -19,53 +23,48 @@ export async function setupUser(
1923
region?: string,
2024
): Promise<void> {
2125
const cognitoClient = getConfiguredCognitoClient(region);
22-
await cognitoClient
23-
.adminCreateUser({
24-
UserPoolId: userPoolId,
25-
UserAttributes: [{ Name: 'email', Value: 'username@amazon.com' }],
26-
Username: username,
27-
MessageAction: 'SUPPRESS',
28-
TemporaryPassword: tempPassword,
29-
})
30-
.promise();
26+
const createUserCommand = new AdminCreateUserCommand({
27+
UserPoolId: userPoolId,
28+
UserAttributes: [{ Name: 'email', Value: 'username@amazon.com' }],
29+
Username: username,
30+
MessageAction: 'SUPPRESS',
31+
TemporaryPassword: tempPassword,
32+
});
33+
await cognitoClient.send(createUserCommand);
3134

3235
await authenticateUser(username, tempPassword, password);
3336

3437
if (groupName) {
35-
await cognitoClient
36-
.adminAddUserToGroup({
37-
UserPoolId: userPoolId,
38-
Username: username,
39-
GroupName: groupName,
40-
})
41-
.promise();
38+
const addToGroupCommand = new AdminAddUserToGroupCommand({
39+
UserPoolId: userPoolId,
40+
Username: username,
41+
GroupName: groupName,
42+
});
43+
await cognitoClient.send(addToGroupCommand);
4244
}
4345
}
4446

4547
export async function addUserToGroup(userPoolId: string, username: string, groupName: string, region?: string): Promise<void> {
4648
const cognitoClient = getConfiguredCognitoClient(region);
47-
await cognitoClient
48-
.adminAddUserToGroup({
49-
UserPoolId: userPoolId,
50-
Username: username,
51-
GroupName: groupName,
52-
})
53-
.promise();
49+
const command = new AdminAddUserToGroupCommand({
50+
UserPoolId: userPoolId,
51+
Username: username,
52+
GroupName: groupName,
53+
});
54+
await cognitoClient.send(command);
5455
}
5556

56-
export function getConfiguredCognitoClient(region = process.env.CLI_REGION): CognitoIdentityServiceProvider {
57-
const cognitoClient = new CognitoIdentityServiceProvider({ apiVersion: '2016-04-19', region });
58-
57+
export function getConfiguredCognitoClient(region = process.env.CLI_REGION): CognitoIdentityProviderClient {
5958
const awsconfig = {
60-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
61-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
62-
sessionToken: process.env.AWS_SESSION_TOKEN,
59+
credentials: {
60+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
61+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
62+
sessionToken: process.env.AWS_SESSION_TOKEN,
63+
},
6364
region,
6465
};
6566

66-
cognitoClient.config.update(awsconfig);
67-
68-
return cognitoClient;
67+
return new CognitoIdentityProviderClient(awsconfig);
6968
}
7069

7170
export function getConfiguredAppsyncClientCognitoAuth(url: string, region: string, user: any) {

packages/amplify-e2e-core/src/utils/pinpoint.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Pinpoint } from 'aws-sdk';
1+
import { PinpointClient, GetAppCommand } from '@aws-sdk/client-pinpoint';
22
import { EOL } from 'os';
33
import { getCLIPath, nspawn as spawn, singleSelect, amplifyRegions, addCircleCITags, KEY_DOWN_ARROW } from '..';
44

@@ -25,24 +25,25 @@ const settings = {
2525
export async function pinpointAppExist(pinpointProjectId: string, region: string): Promise<boolean> {
2626
let result = false;
2727

28-
const pinpointClient = new Pinpoint({
29-
accessKeyId: settings.accessKeyId,
30-
secretAccessKey: settings.secretAccessKey,
31-
sessionToken: settings.sessionToken,
28+
const pinpointClient = new PinpointClient({
29+
credentials: {
30+
accessKeyId: settings.accessKeyId,
31+
secretAccessKey: settings.secretAccessKey,
32+
sessionToken: settings.sessionToken,
33+
},
3234
region,
3335
});
3436

3537
try {
36-
const response = await pinpointClient
37-
.getApp({
38-
ApplicationId: pinpointProjectId,
39-
})
40-
.promise();
41-
if (response.ApplicationResponse.Id === pinpointProjectId) {
38+
const command = new GetAppCommand({
39+
ApplicationId: pinpointProjectId,
40+
});
41+
const response = await pinpointClient.send(command);
42+
if (response.ApplicationResponse?.Id === pinpointProjectId) {
4243
result = true;
4344
}
4445
} catch (err) {
45-
if (err.code === 'NotFoundException') {
46+
if (err.name === 'NotFoundException') {
4647
result = false;
4748
} else {
4849
throw err;

0 commit comments

Comments
 (0)