Skip to content

Commit 7b11fcb

Browse files
committed
fix sonarqube issues
1 parent c94e214 commit 7b11fcb

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

packages/event-handler/src/rest/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function compilePath(path: Path): CompiledRoute {
4646
PARAM_PATTERN,
4747
(_match, paramName) => {
4848
paramNames.push(paramName);
49-
return `(?<${paramName}>[${SAFE_CHARS}${UNSAFE_CHARS}\\w]+)`;
49+
return String.raw`(?<${paramName}>[${SAFE_CHARS}${UNSAFE_CHARS}\w]+)`;
5050
}
5151
);
5252

packages/event-handler/tests/unit/rest/helpers.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ export const createTestEvent = (
4141
resource: '',
4242
});
4343

44+
const createAlbBody = (httpMethod: string, body: JSONValue): string | null => {
45+
// ALB events represent GET and PATCH request bodies as empty strings
46+
if (httpMethod === HttpVerbs.GET || httpMethod === HttpVerbs.PATCH) {
47+
return '';
48+
}
49+
if (body === null) {
50+
return null;
51+
}
52+
return JSON.stringify(body);
53+
};
54+
4455
export const createTestEventV2 = (
4556
rawPath: string,
4657
method: string,
@@ -76,36 +87,23 @@ export const createTestALBEvent = (
7687
path: string,
7788
httpMethod: string,
7889
headers: Record<string, string> = {},
79-
body: string | JSONValue = null
80-
): ALBEvent => {
81-
const stringBody =
82-
typeof body === 'string'
83-
? body
84-
: body !== null
85-
? JSON.stringify(body)
86-
: null;
87-
88-
return {
89-
path,
90-
httpMethod,
91-
headers,
92-
// ALB events represent GET and PATCH request bodies as empty strings
93-
body:
94-
httpMethod === HttpVerbs.GET || httpMethod === HttpVerbs.PATCH
95-
? ''
96-
: stringBody,
97-
multiValueHeaders: {},
98-
isBase64Encoded: false,
99-
queryStringParameters: undefined,
100-
multiValueQueryStringParameters: undefined,
101-
requestContext: {
102-
elb: {
103-
targetGroupArn:
104-
'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test/50dc6c495c0c9188',
105-
},
90+
body: JSONValue = null
91+
): ALBEvent => ({
92+
path,
93+
httpMethod,
94+
headers,
95+
body: createAlbBody(httpMethod, body),
96+
multiValueHeaders: {},
97+
isBase64Encoded: false,
98+
queryStringParameters: undefined,
99+
multiValueQueryStringParameters: undefined,
100+
requestContext: {
101+
elb: {
102+
targetGroupArn:
103+
'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test/50dc6c495c0c9188',
106104
},
107-
};
108-
};
105+
},
106+
});
109107

110108
export const createTrackingMiddleware = (
111109
name: string,

0 commit comments

Comments
 (0)