Skip to content

Commit

Permalink
test: add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpascual committed Oct 4, 2023
1 parent 52263f1 commit fbe90d8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"@yarn/plugin-typescript"
]
},
"packageManager": "[email protected].3",
"packageManager": "[email protected].4",
"resolutions": {
"aws-sdk": "^2.1464.0",
"cross-fetch": "^2.2.6",
Expand Down
32 changes: 26 additions & 6 deletions packages/amplify-e2e-core/src/categories/lambda-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,26 @@ const updateFunctionCore = (cwd: string, chain: ExecutionContext, settings: Core
}
}
if (settings.secretsConfig) {
if (settings.secretsConfig.operation === 'add') {
throw new Error('Secrets update walkthrough only supports update and delete');
}
// this walkthrough assumes 1 existing secret is configured for the function
const actions = ['Add a secret', 'Update a secret', 'Remove secrets', "I'm done"];
const action = settings.secretsConfig.operation === 'delete' ? actions[2] : actions[1];
const operation = settings.secretsConfig.operation;
let action: string;
if (operation === 'add') {
action = actions[0];
} else if (operation === 'delete') {
action = actions[2];
} else {
action = actions[1];
}
chain.wait('What do you want to do?');
singleSelect(chain, action, actions);
switch (settings.secretsConfig.operation) {
switch (operation) {
case 'add': {
chain.wait('Enter a secret name');
chain.sendLine(settings.secretsConfig.name);
chain.wait('Enter the value for');
chain.sendLine(settings.secretsConfig.value);
break;
}
case 'delete': {
chain.wait('Select the secrets to delete:');
chain.sendLine(' '); // assumes one secret
Expand All @@ -137,8 +148,17 @@ const updateFunctionCore = (cwd: string, chain: ExecutionContext, settings: Core
break;
}
}

chain.wait('What do you want to do?');
chain.sendCarriageReturn(); // "I'm done"

if (operation === 'add') {
// assumes function is already pushed to the cloud
chain.wait('This will immediately update secret values in the cloud');
chain.sendCarriageReturn(); // "Yes"
chain.wait('Do you want to edit the local lambda function now');
chain.sendCarriageReturn(); // "No"
}
}
};

Expand Down
56 changes: 55 additions & 1 deletion packages/amplify-e2e-tests/src/__tests__/function_7.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
setCategoryParameters,
updateFunction,
} from '@aws-amplify/amplify-e2e-core';
import { addEnvironmentYes, removeEnvironment } from '../environment/env';
import { addEnvironmentYes, checkoutEnvironment, removeEnvironment } from '../environment/env';

describe('function secret value', () => {
let projRoot: string;
Expand Down Expand Up @@ -279,6 +279,60 @@ describe('function secret value', () => {
// check that old value is removed and new one is added
await expectParams([{ name: 'A_NEW_SECRET', value: 'anewtestsecretvalue' }], ['TEST_SECRET'], region, appId, 'integtest', funcName);
});

it('keeps old secrets when pushing secrets added in another env', async () => {
// add func w/ secret
const envName = 'enva';
await initJSProjectWithProfile(projRoot, { envName, disableAmplifyAppCreation: false });
const funcName = `secretsTest${generateRandomShortId()}`;
const funcSecretName = 'TEST_SECRET';
await addFunction(
projRoot,
{
functionTemplate: 'Hello World',
name: funcName,
secretsConfig: {
operation: 'add',
name: funcSecretName,
value: 'testsecretvalue',
},
},
'nodejs',
);

await amplifyPushAuth(projRoot);

// add new env and add new secret to func
await addEnvironmentYes(projRoot, { envName: 'envb' });
await amplifyPushAuth(projRoot);
const newFuncSecretName = 'NEW_TEST_SECRET';
await updateFunction(
projRoot,
{
secretsConfig: {
operation: 'add',
name: newFuncSecretName,
value: 'testsecretvalue',
},
},
'nodejs',
);

// push updated func w/ new secret
await amplifyPushAuth(projRoot);

await checkoutEnvironment(projRoot, { envName });

// check contents of function-parameters.json for new secret
const expectedFuncSecrets = [funcSecretName, newFuncSecretName];
const funcParams = getCategoryParameters(projRoot, 'function', funcName);
expect(funcParams.secretNames).toEqual(expectedFuncSecrets);

// push with original env and assert all secrets are in function-parameters.json
await amplifyPushMissingFuncSecret(projRoot, 'anewtestsecretvalue');
const funcParamsPostPush = getCategoryParameters(projRoot, 'function', funcName);
expect(funcParamsPostPush.secretNames).toEqual(expectedFuncSecrets);
});
});

const expectParams = async (
Expand Down

0 comments on commit fbe90d8

Please sign in to comment.