Skip to content

[ON HOLD] refactor: e2e-core and e2e-tests #14236

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

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
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
21 changes: 20 additions & 1 deletion packages/amplify-e2e-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,31 @@
},
"dependencies": {
"@aws-amplify/amplify-cli-core": "4.4.2",
"@aws-sdk/client-amplifybackend": "3.624.0",
"@aws-sdk/client-amplifyuibuilder": "3.624.0",
"@aws-sdk/client-appsync": "3.624.0",
"@aws-sdk/client-cloudformation": "3.624.0",
"@aws-sdk/client-cloudwatch-events": "3.624.0",
"@aws-sdk/client-cloudwatch-logs": "3.624.0",
"@aws-sdk/client-cognito-identity": "3.624.0",
"@aws-sdk/client-cognito-identity-provider": "3.624.0",
"@aws-sdk/client-dynamodb": "3.624.0",
"@aws-sdk/client-iam": "3.624.0",
"@aws-sdk/client-kinesis": "3.624.0",
"@aws-sdk/client-lambda": "3.624.0",
"@aws-sdk/client-lex-model-building-service": "3.624.0",
"@aws-sdk/client-location": "3.624.0",
"@aws-sdk/client-pinpoint": "3.624.0",
"@aws-sdk/client-rekognition": "3.624.0",
"@aws-sdk/client-s3": "3.624.0",
"@aws-sdk/client-ssm": "3.624.0",
"@aws-sdk/client-sts": "3.624.0",
"@aws-sdk/credential-providers": "3.624.0",
"@aws-sdk/lib-dynamodb": "3.624.0",
"amplify-headless-interface": "1.17.8",
"aws-amplify": "^5.3.16",
"aws-appsync": "^4.1.1",
"aws-sdk": "^2.1464.0",
"aws-sdk": "^2.1692.0",
"chalk": "^4.1.1",
"dotenv": "^8.2.0",
"execa": "^5.1.1",
Expand Down
13 changes: 5 additions & 8 deletions packages/amplify-e2e-core/src/categories/lambda-function.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW, getCLIPath, getProjectMeta, getBackendAmplifyMeta, invokeFunction } from '..';
import { Lambda } from 'aws-sdk';
import { InvokeCommandOutput } from '@aws-sdk/client-lambda';
import { singleSelect, multiSelect, moveUp, moveDown } from '../utils/selectors';
import { globSync } from 'glob';
import * as path from 'path';
Expand Down Expand Up @@ -636,21 +636,18 @@ export const functionMockAssert = (
});
};

export const functionCloudInvoke = async (
cwd: string,
settings: { funcName: string; payload: string },
): Promise<Lambda.InvocationResponse> => {
export const functionCloudInvoke = async (cwd: string, settings: { funcName: string; payload: string }): Promise<InvokeCommandOutput> => {
const meta = getProjectMeta(cwd);
const lookupName = settings.funcName;
expect(meta.function[lookupName]).toBeDefined();
const { Name: functionName, Region: region } = meta.function[lookupName].output;
expect(functionName).toBeDefined();
expect(region).toBeDefined();
const result = await invokeFunction(functionName, settings.payload, region);
if (!result.$response.data) {
throw new Error('No data in lambda response');
if (!result.Payload) {
throw new Error('No payload in lambda response');
}
return result.$response.data as Lambda.InvocationResponse;
return result;
};

const getTemplateChoices = (runtime: FunctionRuntimes) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AmplifyUIBuilder } from 'aws-sdk';
import { CreateComponentData } from '@aws-sdk/client-amplifyuibuilder';

// FormCheckout used from AmplifyUIKit
// Source: https://www.figma.com/community/file/1047600760128127424

export const formCheckoutComponent: AmplifyUIBuilder.CreateComponentData = {
export const formCheckoutComponent: CreateComponentData = {
name: 'FormCheckout',
componentType: 'Flex',
schemaVersion: '1.0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AmplifyUIBuilder } from 'aws-sdk';
import { CreateComponentData } from '@aws-sdk/client-amplifyuibuilder';

// MyIcon used from AmplifyUIKit
// Source: https://www.figma.com/community/file/1047600760128127424

export const myIconComponent: AmplifyUIBuilder.CreateComponentData = {
export const myIconComponent: CreateComponentData = {
name: 'MyIcon',
componentType: 'Icon',
schemaVersion: '1.0',
Expand Down
65 changes: 32 additions & 33 deletions packages/amplify-e2e-core/src/utils/auth-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Amplify, Auth } from 'aws-amplify';
import AWSAppSyncClient, { AUTH_TYPE } from 'aws-appsync';
import { CognitoIdentityServiceProvider } from 'aws-sdk';
import {
CognitoIdentityProviderClient,
AdminCreateUserCommand,
AdminAddUserToGroupCommand,
} from '@aws-sdk/client-cognito-identity-provider';
import fs from 'fs-extra';
import path from 'path';
import { getAwsAndroidConfig, getAwsIOSConfig, getBackendAmplifyMeta, getCLIInputs, getProjectMeta, setCLIInputs } from './projectMeta';
Expand All @@ -19,53 +23,48 @@ export async function setupUser(
region?: string,
): Promise<void> {
const cognitoClient = getConfiguredCognitoClient(region);
await cognitoClient
.adminCreateUser({
UserPoolId: userPoolId,
UserAttributes: [{ Name: 'email', Value: 'username@amazon.com' }],
Username: username,
MessageAction: 'SUPPRESS',
TemporaryPassword: tempPassword,
})
.promise();
const createUserCommand = new AdminCreateUserCommand({
UserPoolId: userPoolId,
UserAttributes: [{ Name: 'email', Value: 'username@amazon.com' }],
Username: username,
MessageAction: 'SUPPRESS',
TemporaryPassword: tempPassword,
});
await cognitoClient.send(createUserCommand);

await authenticateUser(username, tempPassword, password);

if (groupName) {
await cognitoClient
.adminAddUserToGroup({
UserPoolId: userPoolId,
Username: username,
GroupName: groupName,
})
.promise();
const addToGroupCommand = new AdminAddUserToGroupCommand({
UserPoolId: userPoolId,
Username: username,
GroupName: groupName,
});
await cognitoClient.send(addToGroupCommand);
}
}

export async function addUserToGroup(userPoolId: string, username: string, groupName: string, region?: string): Promise<void> {
const cognitoClient = getConfiguredCognitoClient(region);
await cognitoClient
.adminAddUserToGroup({
UserPoolId: userPoolId,
Username: username,
GroupName: groupName,
})
.promise();
const command = new AdminAddUserToGroupCommand({
UserPoolId: userPoolId,
Username: username,
GroupName: groupName,
});
await cognitoClient.send(command);
}

export function getConfiguredCognitoClient(region = process.env.CLI_REGION): CognitoIdentityServiceProvider {
const cognitoClient = new CognitoIdentityServiceProvider({ apiVersion: '2016-04-19', region });

export function getConfiguredCognitoClient(region = process.env.CLI_REGION): CognitoIdentityProviderClient {
const awsconfig = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN,
},
region,
};

cognitoClient.config.update(awsconfig);

return cognitoClient;
return new CognitoIdentityProviderClient(awsconfig);
}

export function getConfiguredAppsyncClientCognitoAuth(url: string, region: string, user: any) {
Expand Down
25 changes: 13 additions & 12 deletions packages/amplify-e2e-core/src/utils/pinpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pinpoint } from 'aws-sdk';
import { PinpointClient, GetAppCommand } from '@aws-sdk/client-pinpoint';
import { EOL } from 'os';
import { getCLIPath, nspawn as spawn, singleSelect, amplifyRegions, addCircleCITags, KEY_DOWN_ARROW } from '..';

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

const pinpointClient = new Pinpoint({
accessKeyId: settings.accessKeyId,
secretAccessKey: settings.secretAccessKey,
sessionToken: settings.sessionToken,
const pinpointClient = new PinpointClient({
credentials: {
accessKeyId: settings.accessKeyId,
secretAccessKey: settings.secretAccessKey,
sessionToken: settings.sessionToken,
},
region,
});

try {
const response = await pinpointClient
.getApp({
ApplicationId: pinpointProjectId,
})
.promise();
if (response.ApplicationResponse.Id === pinpointProjectId) {
const command = new GetAppCommand({
ApplicationId: pinpointProjectId,
});
const response = await pinpointClient.send(command);
if (response.ApplicationResponse?.Id === pinpointProjectId) {
result = true;
}
} catch (err) {
if (err.code === 'NotFoundException') {
if (err.name === 'NotFoundException') {
result = false;
} else {
throw err;
Expand Down
Loading
Loading