Skip to content

Commit

Permalink
test: update ignore pattern for build-tests, fix import ddb tests (#8744
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jhockett authored and kaustavghosh06 committed Nov 11, 2021
1 parent 069e43a commit c1fbba6
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 74 deletions.
63 changes: 34 additions & 29 deletions packages/amplify-e2e-core/src/categories/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCLIPath, KEY_DOWN_ARROW, nspawn as spawn } from '..';
import { singleSelect } from '../utils/selectors';
import { getCLIPath, nspawn as spawn } from '..';

export type AddStorageSettings = {
resourceName: string;
Expand All @@ -16,7 +16,8 @@ export function addSimpleDDB(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['add', 'storage'], { cwd, stripColors: true })
.wait('Select from one of the below mentioned services')
.sendLine(KEY_DOWN_ARROW)
.sendKeyDown()
.sendCarriageReturn()
.wait('Provide a friendly name')
.sendLine(settings.name || '\r')
.wait('Provide table name')
Expand Down Expand Up @@ -56,7 +57,8 @@ export function addDDBWithTrigger(cwd: string, settings: { ddbResourceName?: str
return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), ['add', 'storage'], { cwd, stripColors: true })
.wait('Select from one of the below mentioned services')
.sendLine(KEY_DOWN_ARROW)
.sendKeyDown()
.sendCarriageReturn()
.wait('Provide a friendly name');
if (settings.ddbResourceName) {
chain.sendLine(settings.ddbResourceName);
Expand Down Expand Up @@ -88,7 +90,8 @@ export function addDDBWithTrigger(cwd: string, settings: { ddbResourceName?: str
.wait('Do you want to add a Lambda Trigger for your Table')
.sendConfirmYes()
.wait('Select from the following options')
.sendLine(KEY_DOWN_ARROW)
.sendKeyDown()
.sendCarriageReturn()
.wait('Do you want to edit the local')
.sendConfirmNo()
.sendEof()
Expand All @@ -106,7 +109,8 @@ export function updateDDBWithTrigger(cwd: string, settings: any): Promise<void>
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['update', 'storage'], { cwd, stripColors: true })
.wait('Select from one of the below mentioned services')
.sendLine(KEY_DOWN_ARROW)
.sendKeyDown()
.sendCarriageReturn()
.wait('Specify the resource that you would want to update')
.sendCarriageReturn()
.wait('Would you like to add another column')
Expand All @@ -116,7 +120,8 @@ export function updateDDBWithTrigger(cwd: string, settings: any): Promise<void>
.wait('Do you want to add a Lambda Trigger for your Table')
.sendConfirmYes()
.wait('Select from the following options')
.sendLine(KEY_DOWN_ARROW)
.sendKeyDown()
.sendCarriageReturn()
.wait('Do you want to edit the local')
.sendLine('n')
.sendEof()
Expand All @@ -134,7 +139,7 @@ export function updateSimpleDDBwithGSI(cwd: string, settings: any): Promise<void
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['update', 'storage'], { cwd, stripColors: true })
.wait('Select from one of the below mentioned services')
.send(KEY_DOWN_ARROW)
.sendKeyDown()
.sendCarriageReturn()
.wait('Specify the resource that you would want to update')
.sendCarriageReturn()
Expand Down Expand Up @@ -177,7 +182,7 @@ export function addSimpleDDBwithGSI(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['add', 'storage'], { cwd, stripColors: true })
.wait('Select from one of the below mentioned services')
.send(KEY_DOWN_ARROW)
.sendKeyDown()
.sendCarriageReturn()
.wait('Provide a friendly name')
.sendCarriageReturn()
Expand All @@ -204,7 +209,7 @@ export function addSimpleDDBwithGSI(cwd: string, settings: any): Promise<void> {
.wait('Provide the GSI name')
.sendLine('gsi1')
.wait('Choose partition key for the GSI')
.send(KEY_DOWN_ARROW)
.sendKeyDown()
.sendCarriageReturn()
.wait('Do you want to add a sort key to your global secondary index?')
.sendConfirmNo()
Expand Down Expand Up @@ -245,15 +250,14 @@ export function buildOverrideStorage(cwd: string, settings: {}) {
return new Promise((resolve, reject) => {
// Add 'storage' as a category param once implemented
const args = ['build'];
const chain = spawn(getCLIPath(), args, { cwd, stripColors: true })
chain
.run((err: Error) => {
if (!err) {
resolve({});
} else {
reject(err);
}
});
const chain = spawn(getCLIPath(), args, { cwd, stripColors: true });
chain.run((err: Error) => {
if (!err) {
resolve({});
} else {
reject(err);
}
});
});
}

Expand Down Expand Up @@ -309,11 +313,11 @@ export function addDynamoDBWithGSIWithSettings(projectDir: string, settings: Add
.wait('Provide the GSI name')
.sendLine(settings.gsiName);

chain.wait('Choose partition key for the GSI').send(KEY_DOWN_ARROW).send(KEY_DOWN_ARROW).sendCarriageReturn(); // choose gsi-pk
chain.wait('Choose partition key for the GSI').sendKeyDown(2).sendCarriageReturn(); // choose gsi-pk

chain.wait('Do you want to add a sort key to your global secondary index').sendConfirmYes();

chain.wait('Choose sort key for the GSI').send(KEY_DOWN_ARROW).send(KEY_DOWN_ARROW).sendCarriageReturn(); // choose gsi-sk
chain.wait('Choose sort key for the GSI').sendKeyDown(2).sendCarriageReturn(); // choose gsi-sk

chain
.wait('Do you want to add more global secondary indexes to your table')
Expand Down Expand Up @@ -442,9 +446,9 @@ export function addS3WithGroupAccess(cwd: string, settings: any): Promise<void>
.sendKeyDown()
.sendCarriageReturn() // Individual groups
.wait('Select groups')
.send(' ') //select Admin
.send(' ') // select Admin
.sendKeyDown()
.send(' ')//select User
.send(' ') // select User
.sendCarriageReturn()
.wait('What kind of access do you want') // for <UserGroup1> users?
.sendCtrlA() // Select all permissions
Expand Down Expand Up @@ -574,13 +578,14 @@ export function addS3StorageWithIdpAuth(projectDir: string): Promise<void> {
.wait('Who should have access:')
.sendCarriageReturn();

chain.wait('What kind of access do you want for Authenticated users?')
.send(' ') //'create/update'
.sendKeyDown()
.send(' ') //'read'
.sendKeyDown()
.send(' ') //'delete'
.sendCarriageReturn()
chain
.wait('What kind of access do you want for Authenticated users?')
.send(' ') //'create/update'
.sendKeyDown()
.send(' ') //'read'
.sendKeyDown()
.send(' ') //'delete'
.sendCarriageReturn();

chain.wait('Do you want to add a Lambda Trigger for your S3 Bucket?').sendConfirmNo();

Expand Down
6 changes: 3 additions & 3 deletions packages/amplify-e2e-core/src/utils/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const addHeadlessAuth = async (cwd: string, request: AddAuthRequest): Pro
return await executeHeadlessCommand(cwd, 'auth', 'add', request);
};

export const updateHeadlessAuth = async (cwd: string, request: UpdateAuthRequest, settings: any): Promise<ExecaChildProcess<String>> => {
export const updateHeadlessAuth = async (cwd: string, request: UpdateAuthRequest, settings?: any): Promise<ExecaChildProcess<String>> => {
return await executeHeadlessCommand(cwd, 'auth', 'update', request, settings);
};

Expand Down Expand Up @@ -75,8 +75,8 @@ const executeHeadlessCommand = async (
request: AnyHeadlessRequest,
reject: boolean = true,
allowDestructiveUpdates: boolean = false,
settings:any = {testingWithLatestCodebase : true },
): Promise<any> => {
settings = { testingWithLatestCodebase: true },
) => {
const args = [operation, category, '--headless'];
if (allowDestructiveUpdates) {
args.push('--allow-destructive-graphql-schema-updates');
Expand Down
30 changes: 12 additions & 18 deletions packages/amplify-e2e-tests/src/__tests__/import_dynamodb_1.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { $TSObject, JSONUtilities } from 'amplify-cli-core';
import {
addAuthWithDefault,
Expand All @@ -13,32 +11,28 @@ import {
deleteProject,
deleteProjectDir,
getAppId,
getTeamProviderInfo,
initJSProjectWithProfile,
} from 'amplify-e2e-core';
import { randomizedFunctionName } from '../schema-api-directives/functionTester';
import { addEnvironmentWithImportedAuth, checkoutEnvironment, removeEnvironment } from '../environment/env';
import * as fs from 'fs-extra';
import * as path from 'path';
import {
createDynamoDBSettings,
DynamoDBProjectDetails,
expectDynamoDBLocalAndOGMetaFilesOutputMatching,
expectDynamoDBProjectDetailsMatch,
expectLocalAndCloudMetaFilesMatching,
expectLocalAndPulledBackendConfigMatching,
getShortId,
readRootStack,
expectNoStorageInMeta,
expectLocalTeamInfoHasOnlyAuthCategoryAndNoStorage,
headlessPullExpectError,
headlessPull,
createDynamoDBSettings,
DynamoDBProjectDetails,
getOGDynamoDBProjectDetails,
importDynamoDBTable,
expectNoStorageInMeta,
getDynamoDBProjectDetails,
expectDynamoDBProjectDetailsMatch,
getDynamoDBResourceName,
expectDynamoDBLocalAndOGMetaFilesOutputMatching,
getOGDynamoDBProjectDetails,
getShortId,
importDynamoDBTable,
readRootStack,
removeImportedDynamoDBWithDefault,
} from '../import-helpers';

const profileName = 'amplify-integ-test-user';
import { randomizedFunctionName } from '../schema-api-directives/functionTester';

describe('dynamodb import', () => {
const projectPrefix = 'ddbimp';
Expand Down
24 changes: 6 additions & 18 deletions packages/amplify-e2e-tests/src/__tests__/import_dynamodb_2.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { $TSObject, JSONUtilities } from 'amplify-cli-core';
import {
addAuthWithDefault,
AddDynamoDBSettings,
addDynamoDBWithGSIWithSettings,
addFunction,
amplifyPull,
amplifyPushAuth,
amplifyStatus,
createNewProjectDir,
Expand All @@ -16,26 +11,19 @@ import {
getTeamProviderInfo,
initJSProjectWithProfile,
} from 'amplify-e2e-core';
import { randomizedFunctionName } from '../schema-api-directives/functionTester';
import { addEnvironmentWithImportedAuth, checkoutEnvironment, removeEnvironment } from '../environment/env';
import {
createDynamoDBSettings,
DynamoDBProjectDetails,
expectDynamoDBLocalAndOGMetaFilesOutputMatching,
expectLocalAndCloudMetaFilesMatching,
expectLocalAndPulledBackendConfigMatching,
getDynamoDBProjectDetails,
getOGDynamoDBProjectDetails,
getShortId,
readRootStack,
expectNoStorageInMeta,
expectLocalTeamInfoHasOnlyAuthCategoryAndNoStorage,
headlessPullExpectError,
headlessPull,
createDynamoDBSettings,
DynamoDBProjectDetails,
getOGDynamoDBProjectDetails,
headlessPullExpectError,
importDynamoDBTable,
getDynamoDBProjectDetails,
expectDynamoDBProjectDetailsMatch,
getDynamoDBResourceName,
expectDynamoDBLocalAndOGMetaFilesOutputMatching,
removeImportedDynamoDBWithDefault,
} from '../import-helpers';

const profileName = 'amplify-integ-test-user';
Expand Down
32 changes: 29 additions & 3 deletions packages/amplify-e2e-tests/src/__tests__/storage-5.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import { $TSAny, JSONUtilities } from 'amplify-cli-core';
import { addAuthWithDefault, addDDBWithTrigger, addS3WithGuestAccess, addSimpleDDB, addSimpleDDBwithGSI, amplifyPushAuth, buildOverrideStorage, checkIfBucketExists, createNewProjectDir, deleteProject, deleteProjectDir, getDDBTable, getProjectMeta, initJSProjectWithProfile, overrideDDB, overrideS3, updateDDBWithTrigger, updateSimpleDDBwithGSI } from 'amplify-e2e-core';
import {
addAuthWithDefault,
addDDBWithTrigger,
addS3WithGuestAccess,
addSimpleDDB,
addSimpleDDBwithGSI,
amplifyPushAuth,
buildOverrideStorage,
checkIfBucketExists,
createNewProjectDir,
deleteProject,
deleteProjectDir,
getDDBTable,
getProjectMeta,
initJSProjectWithProfile,
overrideDDB,
overrideS3,
updateDDBWithTrigger,
updateSimpleDDBwithGSI,
} from 'amplify-e2e-core';
import * as fs from 'fs-extra';
import * as path from 'path';
import uuid from 'uuid';
Expand Down Expand Up @@ -128,7 +147,6 @@ describe('amplify add/update storage(DDB)', () => {
});
});


describe('ddb override tests', () => {
let projRoot: string;
beforeEach(async () => {
Expand All @@ -148,7 +166,15 @@ describe('ddb override tests', () => {

const srcOverrideFilePath = path.join(__dirname, '..', '..', 'overrides', 'override-storage-ddb.ts');
const destOverrideFilePath = path.join(projRoot, 'amplify', 'backend', 'storage', resourceName, 'override.ts');
const cfnFilePath = path.join(projRoot, 'amplify', 'backend', 'storage', resourceName, 'build', `${resourceName}-cloudformation-template.json`);
const cfnFilePath = path.join(
projRoot,
'amplify',
'backend',
'storage',
resourceName,
'build',
`${resourceName}-cloudformation-template.json`,
);

fs.copyFileSync(srcOverrideFilePath, destOverrideFilePath);
await buildOverrideStorage(projRoot, {});
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-e2e-tests/src/import-helpers/expects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ export const expectDynamoDBLocalAndOGMetaFilesOutputMatching = (projectRoot: str
expect(storageMeta.output.Name).toEqual(ogStorageMeta.output.Name);
expect(storageMeta.output.Region).toEqual(ogStorageMeta.output.Region);
expect(storageMeta.output.PartitionKeyName).toEqual(ogStorageMeta.output.PartitionKeyName);
expect(storageMeta.output.PartitionKeyType).toEqual(ddbAttrTypeMapping[ogStorageMeta.output.PartitionKeyType]);
expect(storageMeta.output.PartitionKeyType).toEqual(ogStorageMeta.output.PartitionKeyType);
expect(storageMeta.output.SortKeyName).toEqual(ogStorageMeta.output.SortKeyName);
expect(storageMeta.output.SortKeyType).toEqual(ddbAttrTypeMapping[ogStorageMeta.output.SortKeyType]);
expect(storageMeta.output.SortKeyType).toEqual(ogStorageMeta.output.SortKeyType);
expect(storageMeta.output.Arn).toEqual(ogStorageMeta.output.Arn);
expect(storageMeta.output.StreamArn).toEqual(ogStorageMeta.output.StreamArn);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-tests/tsconfig.tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"typeRoots": ["../../node_modules/@types", "node_modules/@types", "./typings"]
},
"references": [{ "path": "../amplify-e2e-core" }],
"exclude": ["node_modules", "lib", "__tests__"]
"exclude": ["node_modules", "lib", "__tests__", "custom-resources", "overrides"]
}

0 comments on commit c1fbba6

Please sign in to comment.