Skip to content

Commit

Permalink
test: fixes e2e function with api perm test (#6434)
Browse files Browse the repository at this point in the history
Fixes test introduced by #5342
  • Loading branch information
ammarkarachi committed Jan 20, 2021
1 parent 4f35e08 commit df74e0f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
35 changes: 20 additions & 15 deletions packages/amplify-e2e-core/src/categories/lambda-function.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW, getCLIPath, getProjectMeta, invokeFunction } from '..';
import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW, getCLIPath, getProjectMeta, getBackendAmplifyMeta, invokeFunction } from '..';
import { Lambda } from 'aws-sdk';
import { singleSelect, multiSelect, moveUp, moveDown } from '../utils/selectors';
import * as glob from 'glob';
import * as path from 'path';

import _ from 'lodash';
import { loadFeatureFlags } from '../utils/feature-flags';
type FunctionActions = 'create' | 'update';

type FunctionRuntimes = 'dotnetCore31' | 'go' | 'java' | 'nodejs' | 'python';
Expand Down Expand Up @@ -34,7 +35,11 @@ const nodeJSTemplateChoices = [

const pythonTemplateChoices = ['Hello World'];

const additionalPermissions = (chain: ExecutionContext, settings: any) => {
const crudOptions = ['create', 'read', 'update', 'delete'];

const appSyncOptions = ['query', 'mutation', 'subscription'];

const additionalPermissions = (cwd: string, chain: ExecutionContext, settings: any) => {
multiSelect(
chain.sendLine('y').wait('Select the categories you want this function to have access to'),
settings.additionalPermissions.permissions,
Expand All @@ -48,18 +53,18 @@ const additionalPermissions = (chain: ExecutionContext, settings: any) => {
settings.additionalPermissions.resourceChoices,
);
}

// n-resources repeated questions
settings.additionalPermissions.resources.forEach(elem =>
multiSelect(chain.wait(`Select the operations you want to permit on ${elem}`), settings.additionalPermissions.operations, [
'create',
'read',
'update',
'delete',
]),
);
settings.additionalPermissions.resources.forEach(elem => {
const service = _.get(getBackendAmplifyMeta(cwd), ['api', elem, 'service']);
const gqlpermff = !!_.get(loadFeatureFlags(cwd), ['features', 'appsync', 'generategraphqlpermissions']);
const isAppSyncApi = service === 'AppSync';
const allChoices = isAppSyncApi && gqlpermff ? appSyncOptions : crudOptions;
multiSelect(chain.wait(`Select the operations you want to permit on ${elem}`), settings.additionalPermissions.operations, allChoices);
});
};

const updateFunctionCore = (chain: ExecutionContext, settings: any) => {
const updateFunctionCore = (cwd: string, chain: ExecutionContext, settings: any) => {
singleSelect(
chain.wait('Which setting do you want to update?'),
settings.additionalPermissions
Expand All @@ -71,7 +76,7 @@ const updateFunctionCore = (chain: ExecutionContext, settings: any) => {
);
if (settings.additionalPermissions) {
// update permissions
additionalPermissions(chain, settings);
additionalPermissions(cwd, chain, settings);
} else if (settings.schedulePermissions) {
// update scheduling
if (
Expand Down Expand Up @@ -150,7 +155,7 @@ const coreFunction = (
chain.sendLine('y').wait('Do you want to access other resources in this project from your Lambda function?');
if (settings.additionalPermissions) {
// other permissions flow
additionalPermissions(chain, settings);
additionalPermissions(cwd, chain, settings);
} else {
chain.sendLine('n');
}
Expand All @@ -177,7 +182,7 @@ const coreFunction = (
chain.sendLine('n');
}
} else {
updateFunctionCore(chain, settings);
updateFunctionCore(cwd, chain, settings);
}

// edit function question
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-e2e-tests/src/__tests__/function_2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('nodejs', () => {
expect(payload2.ScannedCount).toBeDefined();
});

it('existing lambda updated with additional permissions should be able to scan ddb', async () => {
it.only('existing lambda updated with additional permissions should be able to scan ddb', async () => {
await initJSProjectWithProfile(projRoot, {});

const random = Math.floor(Math.random() * 10000);
Expand Down Expand Up @@ -361,6 +361,7 @@ describe('nodejs', () => {
await addFunction(
projRoot,
{
name: fnName,
functionTemplate: 'Hello World',
additionalPermissions: {
permissions: ['api'],
Expand Down

0 comments on commit df74e0f

Please sign in to comment.