Skip to content

Commit bfe1e8f

Browse files
committed
chore: updated e2e tests
1 parent 777b525 commit bfe1e8f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

packages/logger/tests/e2e/sampleRate.decorator.test.FunctionCode.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,39 @@ import { Logger } from '../../src';
22
import { APIGatewayProxyEvent, Context } from 'aws-lambda';
33
import { LambdaInterface } from '@aws-lambda-powertools/commons';
44

5-
const SAMPLE_RATE = parseFloat(process.env.SAMPLE_RATE);
6-
const LOG_MSG = process.env.LOG_MSG;
5+
const SAMPLE_RATE = parseFloat(process.env.SAMPLE_RATE || '0.1');
6+
const LOG_MSG = process.env.LOG_MSG || 'Hello World';
77

88
const logger = new Logger({
99
sampleRateValue: SAMPLE_RATE,
1010
});
1111

1212
class Lambda implements LambdaInterface {
13+
private readonly logMsg: string;
14+
15+
public constructor() {
16+
this.logMsg = LOG_MSG;
17+
}
18+
1319
// Decorate your handler class method
1420
@logger.injectLambdaContext()
21+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
22+
// @ts-ignore
1523
public async handler(event: APIGatewayProxyEvent, context: Context): Promise<{requestId: string}> {
16-
logger.debug(LOG_MSG);
17-
logger.info(LOG_MSG);
18-
logger.warn(LOG_MSG);
19-
logger.error(LOG_MSG);
20-
24+
this.dummyMethod();
25+
2126
return {
2227
requestId: context.awsRequestId,
2328
};
2429
}
30+
31+
private dummyMethod() : void {
32+
logger.debug(this.logMsg);
33+
logger.info(this.logMsg);
34+
logger.warn(this.logMsg);
35+
logger.error(this.logMsg);
36+
}
2537
}
2638

2739
export const myFunction = new Lambda();
28-
export const handler = myFunction.handler;
40+
export const handler = myFunction.handler.bind(myFunction);

0 commit comments

Comments
 (0)