From c1bffddc6f34b9eb3c834b127dac57b67d2c55ee Mon Sep 17 00:00:00 2001 From: Ammar <56042290+ammarkarachi@users.noreply.github.com> Date: Tue, 9 Nov 2021 12:53:02 -0800 Subject: [PATCH] fix: fixed import_auth test (#8755) --- .../src/categories/storage.ts | 79 ++++++++----------- .../amplify-e2e-core/src/utils/nexpect.ts | 2 +- .../src/__tests__/import_auth_2.test.ts | 3 +- .../__tests__/migration/node.function.test.ts | 2 +- 4 files changed, 37 insertions(+), 49 deletions(-) diff --git a/packages/amplify-e2e-core/src/categories/storage.ts b/packages/amplify-e2e-core/src/categories/storage.ts index b7b434aa1f7..35359ab5de9 100644 --- a/packages/amplify-e2e-core/src/categories/storage.ts +++ b/packages/amplify-e2e-core/src/categories/storage.ts @@ -1,9 +1,9 @@ import { singleSelect } from '../utils/selectors'; -import { getCLIPath, nspawn as spawn } from '..'; +import { getCLIPath, nspawn as spawn, RETURN } from '..'; export type AddStorageSettings = { - resourceName: string; - bucketName: string; + resourceName?: string; + bucketName?: string; }; export type AddDynamoDBSettings = { @@ -602,31 +602,32 @@ export function addS3StorageWithIdpAuth(projectDir: string): Promise { export function addS3Storage(projectDir: string): Promise { return new Promise((resolve, reject) => { let chain = spawn(getCLIPath(), ['add', 'storage'], { cwd: projectDir, stripColors: true }); - chain.wait('Select from one of the below mentioned services:') //'Content (Images, audio, video, etc.)' - .sendCarriageReturn() - .wait('Provide a friendly name for your resource that will be used to label this category in the project:') - .sendCarriageReturn() - .wait('Provide bucket name:') - .sendCarriageReturn() - .wait('Who should have access:') - .sendKeyDown() - .send(' ') //Auth and guest - .sendCarriageReturn() - .wait('What kind of access do you want for Authenticated users?')//Auth - .sendCtrlA() - .sendCarriageReturn() - .wait('What kind of access do you want for Guest users?')//Guest - .sendCtrlA() - .sendCarriageReturn() - .wait('Do you want to add a Lambda Trigger for your S3 Bucket?') - .sendConfirmNo() - .run((err: Error) => { - if (!err) { - resolve(); - } else { - reject(err); - } - }); + chain + .wait('Select from one of the below mentioned services:') //'Content (Images, audio, video, etc.)' + .sendCarriageReturn() + .wait('Provide a friendly name for your resource that will be used to label this category in the project:') + .sendCarriageReturn() + .wait('Provide bucket name:') + .sendCarriageReturn() + .wait('Who should have access:') + .sendKeyDown() + .send(' ') //Auth and guest + .sendCarriageReturn() + .wait('What kind of access do you want for Authenticated users?') //Auth + .sendCtrlA() + .sendCarriageReturn() + .wait('What kind of access do you want for Guest users?') //Guest + .sendCtrlA() + .sendCarriageReturn() + .wait('Do you want to add a Lambda Trigger for your S3 Bucket?') + .sendConfirmNo() + .run((err: Error) => { + if (!err) { + resolve(); + } else { + reject(err); + } + }); }); } @@ -658,29 +659,15 @@ export function addS3StorageWithSettings(projectDir: string, settings: AddStorag chain .wait('Provide a friendly name for your resource that will be used to label this category in the project:') - .sendLine(settings.resourceName) + .sendLine(settings.resourceName || RETURN) .wait('Provide bucket name:') - .sendLine(settings.bucketName); + .sendLine(settings.bucketName || RETURN); chain.wait('Who should have access:').sendKeyDown().send(' ').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?').sendCtrlA().sendCarriageReturn(); - chain - .wait('What kind of access do you want for Guest users?') - .send(' ') //'create/update' - .sendKeyDown() - .send(' ') //'read' - .sendKeyDown() - .send(' ') //'delete' - .sendCarriageReturn(); + chain.wait('What kind of access do you want for Guest users?').sendCtrlA().sendCarriageReturn(); chain.wait('Do you want to add a Lambda Trigger for your S3 Bucket?').sendConfirmNo(); diff --git a/packages/amplify-e2e-core/src/utils/nexpect.ts b/packages/amplify-e2e-core/src/utils/nexpect.ts index 264f0094711..049a1724137 100644 --- a/packages/amplify-e2e-core/src/utils/nexpect.ts +++ b/packages/amplify-e2e-core/src/utils/nexpect.ts @@ -23,7 +23,7 @@ import { join, parse } from 'path'; import * as fs from 'fs-extra'; import * as os from 'os'; import { getScriptRunnerPath, isTestingWithLatestCodebase } from '..'; -const RETURN = process.platform === 'win32' ? '\r' : EOL; +export const RETURN = process.platform === 'win32' ? '\r' : EOL; const DEFAULT_NO_OUTPUT_TIMEOUT = process.env.AMPLIFY_TEST_TIMEOUT_SEC ? Number.parseInt(process.env.AMPLIFY_TEST_TIMEOUT_SEC, 10) * 1000 : 5 * 60 * 1000; // 5 Minutes diff --git a/packages/amplify-e2e-tests/src/__tests__/import_auth_2.test.ts b/packages/amplify-e2e-tests/src/__tests__/import_auth_2.test.ts index 72762f73235..6f71c47e351 100644 --- a/packages/amplify-e2e-tests/src/__tests__/import_auth_2.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/import_auth_2.test.ts @@ -10,6 +10,7 @@ import { deleteProjectDir, getAppId, initJSProjectWithProfile, + addS3StorageWithSettings, } from 'amplify-e2e-core'; import { AuthProjectDetails, @@ -241,7 +242,7 @@ describe('auth import identity pool and userpool', () => { it('auth import, storage auth/guest access, push successful', async () => { await initJSProjectWithProfile(projectRoot, projectSettings); await importIdentityPoolAndUserPool(projectRoot, ogSettings.userPoolName, { native: '_app_client ', web: '_app_clientWeb' }); - await addS3Storage(projectRoot); + await addS3StorageWithSettings(projectRoot, {}); await amplifyPushAuth(projectRoot); await amplifyStatus(projectRoot, 'No Change'); diff --git a/packages/amplify-e2e-tests/src/__tests__/migration/node.function.test.ts b/packages/amplify-e2e-tests/src/__tests__/migration/node.function.test.ts index 48924ae12c6..4c0f8c7e736 100644 --- a/packages/amplify-e2e-tests/src/__tests__/migration/node.function.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/migration/node.function.test.ts @@ -51,8 +51,8 @@ describe('nodejs version migration tests', () => { 'amplify', 'backend', 'auth', - 'build', authResourceName, + 'build', `${authResourceName}-cloudformation-template.json`, ); let authStackContent = fs.readFileSync(authStackFileName).toString();