Skip to content

Commit c9af6b7

Browse files
committed
add unit test for creating new lambda from code param
1 parent f16cab4 commit c9af6b7

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

packages/rest-api-construct/src/construct.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { App, Stack } from 'aws-cdk-lib';
44
import { Template } from 'aws-cdk-lib/assertions';
55
import * as lambda from 'aws-cdk-lib/aws-lambda';
66

7-
void describe('RestApiConstruct', () => {
8-
void it('loads a function if the folder is specified', () => {
7+
void describe('RestApiConstruct Lambda Handling', () => {
8+
void it('loads an existing local lambda function if the directory is specified', () => {
99
const app = new App();
1010
const stack = new Stack(app);
1111
new RestApiConstruct(stack, 'RestApiLambdaTest', {
@@ -26,6 +26,30 @@ void describe('RestApiConstruct', () => {
2626
Handler: 'index.handler',
2727
});
2828
});
29+
30+
void it('creates a new lambda function if the code is specified', () => {
31+
const app = new App();
32+
const stack = new Stack(app);
33+
new RestApiConstruct(stack, 'RestApiNewLambdaTest', {
34+
apiName: 'RestApiNewLambda',
35+
apiProps: [
36+
{
37+
path: 'items',
38+
routes: ['GET'],
39+
lambdaEntry: {
40+
runtime: lambda.Runtime.NODEJS_22_X,
41+
source: {
42+
code: "export const handler = () => {return 'Hello World! This is a new lambda function.';};",
43+
},
44+
},
45+
},
46+
],
47+
});
48+
const template = Template.fromStack(stack);
49+
template.hasResourceProperties('AWS::Lambda::Function', {
50+
Handler: 'index.handler',
51+
});
52+
});
2953
});
3054

3155
void describe('RestApiConstruct', () => {

0 commit comments

Comments
 (0)