Skip to content

Commit

Permalink
Merge pull request #2 from ykethan/APILambdaTemplates
Browse files Browse the repository at this point in the history
  • Loading branch information
ykethan authored Aug 5, 2022
2 parents a4ef0c9 + 36eaa20 commit e723f4b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 43 deletions.
6 changes: 6 additions & 0 deletions packages/amplify-e2e-core/src/categories/lambda-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const nodeJSTemplateChoices = [
'Hello World',
'Lambda trigger',
'Serverless ExpressJS function (Integration with API Gateway)',
'AppSync Todo',
];

const pythonTemplateChoices = ['Hello World'];
Expand Down Expand Up @@ -358,6 +359,11 @@ export const selectTemplate = (chain: ExecutionContext, functionTemplate: string
moveUp(chain, templateChoices.indexOf('Hello World'));

singleSelect(chain, functionTemplate, templateChoices);

if(functionTemplate === 'AppSync Todo'){
chain.wait('Pick a Auth type');
singleSelect(chain, 'API_KEY', ['API_KEY', 'IAM']);
}
};

export const removeFunction = (cwd: string, funcName: string) =>
Expand Down
10 changes: 5 additions & 5 deletions packages/amplify-e2e-tests/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ env VERBOSE_LOGGING_DO_NOT_USE_IN_CI_OR_YOU_WILL_BE_FIRED=true yarn e2e
```

```typescript
import { amplifyPush, deleteProject, initJSProjectWithProfile } from "../init";
import { createNewProjectDir, deleteProjectDir, getProjectMeta } from "../utils";
import { amplifyPush, deleteProject, initJSProjectWithProfile } from '../init';
import { createNewProjectDir, deleteProjectDir, getProjectMeta } from '../utils';

describe("amplify your test", () => {
describe('amplify your test', () => {
let projRoot: string;
beforeEach(() => {
projRoot = createNewProjectDir(); // create a new project for each test
Expand All @@ -50,8 +50,8 @@ describe("amplify your test", () => {
deleteProjectDir(projRoot); // delete the project directory
});

it("<your test>", async () => {
await initJSProjectWithProfile(projRoot, { name: "<project-name>" });
it('<your test>', async () => {
await initJSProjectWithProfile(projRoot, { name: '<project-name>' });
// add resources that you want to test
await amplifyPush(projRoot); // Push it to the cloud
const { output } = getProjectMeta(projRoot).api.simplemodel;
Expand Down
85 changes: 47 additions & 38 deletions packages/amplify-e2e-tests/src/__tests__/function_11.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
getBackendConfig,
initJSProjectWithProfile,
getProjectMeta,
getFunction
getFunction,
functionBuild,
amplifyPushAuth,
invokeFunction

} from "@aws-amplify/amplify-e2e-core";
import { v4 as uuid } from "uuid";
import path from "path";
Expand All @@ -30,54 +34,59 @@ describe("Lambda AppSync nodejs", () => {
});

it.only("add nodejs appsync function", async () => {

await initJSProjectWithProfile(projRoot, {});

await addApi(projRoot, {
'API key': {},
transformerVersion: 2
});
await amplifyPush(projRoot);

// await addApi(projRoot, {
// "API key": {},
// transformerVersion: 2
// });
// await amplifyPush(projRoot);

// expect(getBackendConfig(projRoot)).toBeDefined();
expect(getBackendConfig(projRoot)).toBeDefined();

// var beforeMeta = getBackendConfig(projRoot);
// console.log(beforeMeta);
// const apiName = Object.keys(beforeMeta.api)[0];
// console.log(apiName);

// expect(apiName + " abc").toContain("lambdaappsyncnodejs4");
var beforeMeta = getBackendConfig(projRoot);
console.log(beforeMeta);
console.log(Object.keys(beforeMeta.api.lambdaappsyncnodejsa.output))
const apiName = Object.keys(beforeMeta.api)[0];
console.log(apiName);

const [shortId] = uuid().split("-");
const funcName = `lambdaappsync${shortId}`;
expect(apiName).toBeDefined();


await addFunction(
projRoot,
{
name: funcName,
functionTemplate: "AppSync Todo"
// additionalPermissions: {
// permissions: ["api"],
// choices: ["api"],
// resources: ["api"],
// operations: ["Query"],
// actions: ["API_KEY"]
// }
},
"nodejs"
);

const beforeMeta = getBackendConfig(projRoot);
console.log(beforeMeta);
projRoot,
{
functionTemplate: 'AppSync Todo',
additionalPermissions: {
permissions: ['api'],
choices: ['api'],
resources: [apiName],
operations: ['Query'],
},
},
'nodejs'
);
await functionBuild(projRoot, {});
await amplifyPushAuth(projRoot);
const meta = getProjectMeta(projRoot);
const { Arn: functionArn, Name: functionName, Region: region, CloudWatchEventRule: ruleName } = Object.keys(meta.function).map(
key => meta.function[key]
)[0].output;
const { Arn: functionArn, Name: functionName, Region: region } = Object.keys(meta.function).map(key => meta.function[key])[0].output;
expect(functionArn).toBeDefined();
expect(functionName).toBeDefined();
expect(region).toBeDefined();
expect(ruleName).toBeUndefined();

const cloudFunction = await getFunction(functionName, region);
expect(cloudFunction.Configuration.FunctionArn).toEqual(functionArn);


const payloadObj = {test1: 'hello' };
const fnResponse = await invokeFunction(functionName, JSON.stringify(payloadObj), region);

console.log(fnResponse);
expect(fnResponse.StatusCode).toBe(200);
// expect(fnResponse.Payload).toBeDefined();
// const gqlResponse = JSON.parse(fnResponse.Payload as string);

// expect(gqlResponse.data).toBeDefined();
// expect(gqlResponse.data.createTodo.name).toEqual('todo');
});
});

0 comments on commit e723f4b

Please sign in to comment.