From 6a22348b37c58d083c1328a9f4910eebbaaf69fb Mon Sep 17 00:00:00 2001 From: Kaustav Ghosh Date: Sat, 6 Nov 2021 18:45:45 -0700 Subject: [PATCH] test: fixing DDB E2E tests (#8707) * test: fixing DDB E2E tests * test: fix ddb import e2e test Co-authored-by: Ghosh --- .../dynamoDb-walkthrough.ts | 2 +- .../src/categories/storage.ts | 13 ++++++- .../overrides/override-storage-ddb.ts | 3 +- .../overrides/override-storage-s3.ts | 13 +++---- .../src/__tests__/storage-1.test.ts | 37 +++++++++---------- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/packages/amplify-category-storage/src/provider-utils/awscloudformation/service-walkthroughs/dynamoDb-walkthrough.ts b/packages/amplify-category-storage/src/provider-utils/awscloudformation/service-walkthroughs/dynamoDb-walkthrough.ts index 80befacebd8..c278bee32ab 100644 --- a/packages/amplify-category-storage/src/provider-utils/awscloudformation/service-walkthroughs/dynamoDb-walkthrough.ts +++ b/packages/amplify-category-storage/src/provider-utils/awscloudformation/service-walkthroughs/dynamoDb-walkthrough.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; -import uuid from 'uuid'; +import { v4 as uuid } from 'uuid'; import { alphanumeric, printer, prompter, Validator } from 'amplify-prompts'; import { $TSContext, AmplifyCategories, ResourceDoesNotExistError, exitOnNextTick, stateManager } from 'amplify-cli-core'; import { DynamoDBInputState } from './dynamoDB-input-state'; diff --git a/packages/amplify-e2e-core/src/categories/storage.ts b/packages/amplify-e2e-core/src/categories/storage.ts index c37050512db..fe77042c03e 100644 --- a/packages/amplify-e2e-core/src/categories/storage.ts +++ b/packages/amplify-e2e-core/src/categories/storage.ts @@ -270,7 +270,18 @@ export function addDynamoDBWithGSIWithSettings(projectDir: string, settings: Add const addColumn = (name, type) => { chain.wait('What would you like to name this column').sendLine(name); - singleSelect(chain.wait('Choose the data type'), type, ['string', 'number', 'binary', 'boolean', 'list', 'map', 'null']); + singleSelect(chain.wait('Choose the data type'), type, [ + 'string', + 'number', + 'binary', + 'boolean', + 'list', + 'map', + 'null', + 'string-set', + 'number-set', + 'binary-set', + ]); }; const addAnotherColumn = () => { diff --git a/packages/amplify-e2e-tests/overrides/override-storage-ddb.ts b/packages/amplify-e2e-tests/overrides/override-storage-ddb.ts index d80e8db9bda..77aa96fab46 100644 --- a/packages/amplify-e2e-tests/overrides/override-storage-ddb.ts +++ b/packages/amplify-e2e-tests/overrides/override-storage-ddb.ts @@ -1,6 +1,5 @@ -export function overrideProps(props: any) { +export function override(props: any) { props.dynamoDBTable.streamSpecification = { streamViewType: 'NEW_AND_OLD_IMAGES', }; - return props; } diff --git a/packages/amplify-e2e-tests/overrides/override-storage-s3.ts b/packages/amplify-e2e-tests/overrides/override-storage-s3.ts index e4d44b4880e..19203128d71 100644 --- a/packages/amplify-e2e-tests/overrides/override-storage-s3.ts +++ b/packages/amplify-e2e-tests/overrides/override-storage-s3.ts @@ -1,9 +1,6 @@ - -export function overrideProps(props: any) { - //Enable versioning on the bucket - props.s3Bucket.versioningConfiguration = { - status : "Enabled" - } - return props; +export function override(props: any) { + //Enable versioning on the bucket + props.s3Bucket.versioningConfiguration = { + status: 'Enabled', + }; } - \ No newline at end of file diff --git a/packages/amplify-e2e-tests/src/__tests__/storage-1.test.ts b/packages/amplify-e2e-tests/src/__tests__/storage-1.test.ts index 8753e1ad24b..961fa6c615b 100644 --- a/packages/amplify-e2e-tests/src/__tests__/storage-1.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/storage-1.test.ts @@ -1,31 +1,28 @@ -import { $TSAny, JSONUtilities } from 'amplify-cli-core'; -import { initJSProjectWithProfile, initFlutterProjectWithProfile, deleteProject, amplifyPushAuth } from 'amplify-e2e-core'; -import { addAuthWithDefault, addAuthWithGroupsAndAdminAPI } from 'amplify-e2e-core'; +import { $TSAny } from 'amplify-cli-core'; import { - addSimpleDDB, - overrideDDB, - buildOverrideStorage, - addDDBWithTrigger, - updateDDBWithTrigger, - addSimpleDDBwithGSI, - updateSimpleDDBwithGSI, - overrideS3, + addAuthWithDefault, + addAuthWithGroupsAndAdminAPI, addS3AndAuthWithAuthOnlyAccess, - addS3WithGuestAccess, addS3WithGroupAccess, + addS3WithGuestAccess, addS3WithTrigger, + amplifyPushAuth, + checkIfBucketExists, + createNewProjectDir, + deleteProject, + deleteProjectDir, + getProjectMeta, + initFlutterProjectWithProfile, + initJSProjectWithProfile, updateS3AddTrigger, } from 'amplify-e2e-core'; -import { createNewProjectDir, deleteProjectDir, getProjectMeta, getDDBTable, checkIfBucketExists } from 'amplify-e2e-core'; import * as fs from 'fs-extra'; import * as path from 'path'; -import uuid from 'uuid'; - -function getServiceMeta( projectRoot : string, category: string, service : string ): $TSAny { +function getServiceMeta(projectRoot: string, category: string, service: string): $TSAny { const meta = getProjectMeta(projectRoot); - for ( const storageResourceName of Object.keys(meta[category]) ){ - if ( meta.storage[storageResourceName].service.toUpperCase() === service.toUpperCase() ){ + for (const storageResourceName of Object.keys(meta[category])) { + if (meta.storage[storageResourceName].service.toUpperCase() === service.toUpperCase()) { return meta.storage[storageResourceName]; } } @@ -43,7 +40,7 @@ describe('amplify add/update storage(S3)', () => { }); async function validate(projRoot) { - const serviceMeta = getServiceMeta( projRoot, 'storage', 'S3'); + const serviceMeta = getServiceMeta(projRoot, 'storage', 'S3'); const { BucketName: bucketName, Region: region } = serviceMeta.output; expect(bucketName).toBeDefined(); @@ -92,7 +89,7 @@ describe('amplify add/update storage(S3)', () => { await amplifyPushAuth(projRoot); await validate(projRoot); }); - + it('init a project and add S3 bucket with user pool groups and then update S3 bucket to add trigger', async () => { await initJSProjectWithProfile(projRoot, {}); await addAuthWithGroupsAndAdminAPI(projRoot, {});