diff --git a/packages/event-handler/src/appsync-events/Router.ts b/packages/event-handler/src/appsync-events/Router.ts index 38e189d65d..1298c82937 100644 --- a/packages/event-handler/src/appsync-events/Router.ts +++ b/packages/event-handler/src/appsync-events/Router.ts @@ -1,6 +1,9 @@ import type { GenericLogger } from '@aws-lambda-powertools/commons/types'; import { isRecord } from '@aws-lambda-powertools/commons/typeutils'; -import { getStringFromEnv, isDevMode } from '@aws-lambda-powertools/commons/utils/env'; +import { + getStringFromEnv, + isDevMode, +} from '@aws-lambda-powertools/commons/utils/env'; import type { OnPublishHandler, OnSubscribeHandler, @@ -31,7 +34,7 @@ class Router { * Whether the router is running in development mode. */ protected readonly isDev: boolean = false; - + public constructor(options?: RouterOptions) { const alcLogLevel = getStringFromEnv({ key: 'AWS_LAMBDA_LOG_LEVEL', diff --git a/packages/event-handler/src/appsync-graphql/AppSyncGraphQLResolver.ts b/packages/event-handler/src/appsync-graphql/AppSyncGraphQLResolver.ts index a338ef9c5b..6aede4c554 100644 --- a/packages/event-handler/src/appsync-graphql/AppSyncGraphQLResolver.ts +++ b/packages/event-handler/src/appsync-graphql/AppSyncGraphQLResolver.ts @@ -152,11 +152,7 @@ class AppSyncGraphQLResolver extends Router { * @param context - The AWS Lambda context object. * @param options - Optional parameters for the resolver, such as the scope of the handler. */ - public async resolve( - event: unknown, - context: Context, - options?: ResolveOptions - ): Promise { + public resolve(event: unknown, context: Context, options?: ResolveOptions) { if (Array.isArray(event)) { if (event.some((e) => !isAppSyncGraphQLEvent(e))) { this.logger.warn( @@ -194,10 +190,10 @@ class AppSyncGraphQLResolver extends Router { * @param options - Optional resolve options for customizing resolver behavior. */ async #withErrorHandling( - fn: () => Promise, + fn: () => unknown, event: AppSyncResolverEvent>, options?: ResolveOptions - ): Promise { + ) { try { return await fn(); } catch (error) { @@ -377,11 +373,11 @@ class AppSyncGraphQLResolver extends Router { * @param options - Optional parameters for the resolver, such as the scope of the handler. * @throws {ResolverNotFoundException} If no resolver is registered for the given field and type. */ - async #executeSingleResolver( + #executeSingleResolver( event: AppSyncResolverEvent>, context: Context, options?: ResolveOptions - ): Promise { + ): unknown { const { fieldName, parentTypeName: typeName } = event.info; const resolverHandlerOptions = this.resolverRegistry.resolve( diff --git a/packages/event-handler/src/appsync-graphql/index.ts b/packages/event-handler/src/appsync-graphql/index.ts index 9fe91122f4..bffc35bad1 100644 --- a/packages/event-handler/src/appsync-graphql/index.ts +++ b/packages/event-handler/src/appsync-graphql/index.ts @@ -1,7 +1,7 @@ export { AppSyncGraphQLResolver } from './AppSyncGraphQLResolver.js'; export { - ResolverNotFoundException, InvalidBatchResponseException, + ResolverNotFoundException, } from './errors.js'; export { awsDate, diff --git a/packages/event-handler/src/bedrock-agent/BedrockAgentFunctionResolver.ts b/packages/event-handler/src/bedrock-agent/BedrockAgentFunctionResolver.ts index 5211ddade3..37e186dc69 100644 --- a/packages/event-handler/src/bedrock-agent/BedrockAgentFunctionResolver.ts +++ b/packages/event-handler/src/bedrock-agent/BedrockAgentFunctionResolver.ts @@ -146,7 +146,7 @@ class BedrockAgentFunctionResolver { public tool>( fn: ToolFunction, config: Configuration - ): undefined { + ) { const { name } = config; if (this.#tools.has(name)) { this.#logger.warn( diff --git a/packages/event-handler/src/rest/converters.ts b/packages/event-handler/src/rest/converters.ts index d47302ebf6..6f8a1706f3 100644 --- a/packages/event-handler/src/rest/converters.ts +++ b/packages/event-handler/src/rest/converters.ts @@ -36,11 +36,11 @@ export const proxyEventToWebRequest = ( const { domainName } = event.requestContext; const headers = new Headers(); - for (const [name, value] of Object.entries(event.headers ?? {})) { - if (value != null) headers.set(name, value); + for (const [name, value] of Object.entries(event.headers)) { + if (value !== undefined) headers.set(name, value); } - for (const [name, values] of Object.entries(event.multiValueHeaders ?? {})) { + for (const [name, values] of Object.entries(event.multiValueHeaders)) { for (const value of values ?? []) { const headerValue = headers.get(name); if (!headerValue?.includes(value)) { diff --git a/packages/event-handler/src/rest/middleware/cors.ts b/packages/event-handler/src/rest/middleware/cors.ts index 25c780e39b..3a7d9b5f55 100644 --- a/packages/event-handler/src/rest/middleware/cors.ts +++ b/packages/event-handler/src/rest/middleware/cors.ts @@ -35,6 +35,7 @@ import { * })); * ``` * + * @param options - Configuration options for CORS * @param options.origin - The origin to allow requests from * @param options.allowMethods - The HTTP methods to allow * @param options.allowHeaders - The headers to allow diff --git a/packages/event-handler/src/rest/utils.ts b/packages/event-handler/src/rest/utils.ts index e8fbd1e5d0..69636bd25b 100644 --- a/packages/event-handler/src/rest/utils.ts +++ b/packages/event-handler/src/rest/utils.ts @@ -150,7 +150,7 @@ export const isAPIGatewayProxyResult = ( * ``` */ export const composeMiddleware = (middleware: Middleware[]): Middleware => { - return async ({ reqCtx, next }): Promise => { + return async ({ reqCtx, next }) => { let index = -1; let result: HandlerResponse | undefined; diff --git a/packages/event-handler/src/types/bedrock-agent.ts b/packages/event-handler/src/types/bedrock-agent.ts index c649e1200d..8d99735cef 100644 --- a/packages/event-handler/src/types/bedrock-agent.ts +++ b/packages/event-handler/src/types/bedrock-agent.ts @@ -51,7 +51,10 @@ type ToolFunction> = ( event: BedrockAgentFunctionEvent; context: Context; } -) => Promise; +) => + | Promise + | JSONValue + | BedrockFunctionResponse; /** * Tool in the Bedrock Agent Function Resolver. @@ -159,7 +162,7 @@ type ResolverOptions = { * * When no logger is provided, we'll only log warnings and errors using the global `console` object. */ - logger?: GenericLogger; + logger?: Pick; }; export type { diff --git a/packages/event-handler/src/types/rest.ts b/packages/event-handler/src/types/rest.ts index 1c9925ce22..9a7ddb5ddd 100644 --- a/packages/event-handler/src/types/rest.ts +++ b/packages/event-handler/src/types/rest.ts @@ -24,6 +24,7 @@ type ErrorHandler = ( ) => Promise; interface ErrorConstructor { + // biome-ignore lint/suspicious/noExplicitAny: this is a generic type that is intentionally open new (...args: any[]): T; prototype: T; } @@ -57,7 +58,7 @@ type HandlerResponse = Response | JSONObject; type RouteHandler = ( reqCtx: RequestContext -) => Promise; +) => Promise | TReturn; type HttpMethod = keyof typeof HttpVerbs; @@ -78,12 +79,14 @@ type RestRouteOptions = { middleware?: Middleware[]; }; +// biome-ignore lint/suspicious/noConfusingVoidType: To ensure next function is awaited type NextFunction = () => Promise; type Middleware = (args: { reqCtx: RequestContext; next: NextFunction; -}) => Promise; + // biome-ignore lint/suspicious/noConfusingVoidType: To ensure next function is awaited +}) => Promise; type RouteRegistryOptions = { /** @@ -176,4 +179,5 @@ export type { RouteRegistryOptions, ValidationResult, CompressionOptions, + NextFunction, }; diff --git a/packages/event-handler/tests/unit/appsync-events/AppSyncEventsResolver.test.ts b/packages/event-handler/tests/unit/appsync-events/AppSyncEventsResolver.test.ts index 16da12ce63..512ff7a095 100644 --- a/packages/event-handler/tests/unit/appsync-events/AppSyncEventsResolver.test.ts +++ b/packages/event-handler/tests/unit/appsync-events/AppSyncEventsResolver.test.ts @@ -87,7 +87,7 @@ describe('Class: AppSyncEventsResolver', () => { public scope = 'scoped'; @app.onPublish('/foo', { aggregate }) - public async handleFoo(payloads: OnPublishAggregatePayload) { + public handleFoo(payloads: OnPublishAggregatePayload) { return payloads.map((payload) => { return { id: payload.id, @@ -97,15 +97,15 @@ describe('Class: AppSyncEventsResolver', () => { } @app.onPublish('/bar') - public async handleBar(payload: string) { + public handleBar(payload: string) { return `${this.scope} ${payload}`; } - public async handler(event: unknown, context: Context) { + public handler(event: unknown, context: Context) { return this.stuff(event, context); } - async stuff(event: unknown, context: Context) { + stuff(event: unknown, context: Context) { return app.resolve(event, context, { scope: this }); } } @@ -146,15 +146,15 @@ describe('Class: AppSyncEventsResolver', () => { public scope = 'scoped'; @app.onSubscribe('/foo') - public async handleFoo(payload: AppSyncEventsSubscribeEvent) { + public handleFoo(payload: AppSyncEventsSubscribeEvent) { console.debug(`${this.scope} ${payload.info.channel.path}`); } - public async handler(event: unknown, context: Context) { + public handler(event: unknown, context: Context) { return this.stuff(event, context); } - async stuff(event: unknown, context: Context) { + stuff(event: unknown, context: Context) { return app.resolve(event, context, { scope: this }); } } @@ -222,7 +222,7 @@ describe('Class: AppSyncEventsResolver', () => { async ({ error, message }) => { // Prepare const app = new AppSyncEventsResolver({ logger: console }); - app.onSubscribe('/foo', async () => { + app.onSubscribe('/foo', () => { throw error; }); @@ -242,7 +242,7 @@ describe('Class: AppSyncEventsResolver', () => { it('throws an UnauthorizedException when thrown by the handler', async () => { // Prepare const app = new AppSyncEventsResolver({ logger: console }); - app.onSubscribe('/foo', async () => { + app.onSubscribe('/foo', () => { throw new UnauthorizedException('nah'); }); @@ -258,7 +258,7 @@ describe('Class: AppSyncEventsResolver', () => { it('returns the response of the onPublish handler', async () => { // Prepare const app = new AppSyncEventsResolver({ logger: console }); - app.onPublish('/foo', async (payload) => { + app.onPublish('/foo', (payload) => { if (payload === 'foo') { return true; } @@ -303,7 +303,7 @@ describe('Class: AppSyncEventsResolver', () => { const app = new AppSyncEventsResolver({ logger: console }); app.onPublish( '/foo', - async (payloads) => { + (payloads) => { return payloads.map((payload) => ({ id: payload.id, payload: true, @@ -353,7 +353,7 @@ describe('Class: AppSyncEventsResolver', () => { const app = new AppSyncEventsResolver({ logger: console }); app.onPublish( '/foo', - async () => { + () => { throw new Error('Error in handler'); }, { aggregate: true } @@ -379,7 +379,7 @@ describe('Class: AppSyncEventsResolver', () => { const app = new AppSyncEventsResolver({ logger: console }); app.onPublish( '/foo', - async () => { + () => { throw new UnauthorizedException('nah'); }, { aggregate: true } @@ -400,7 +400,7 @@ describe('Class: AppSyncEventsResolver', () => { const app = new AppSyncEventsResolver(); app.onPublish( '/foo', - async () => { + () => { throw new Error('Error in handler'); }, { aggregate: true } diff --git a/packages/event-handler/tests/unit/appsync-graphql/AppSyncGraphQLResolver.test.ts b/packages/event-handler/tests/unit/appsync-graphql/AppSyncGraphQLResolver.test.ts index 06b653fcd9..1100a41005 100644 --- a/packages/event-handler/tests/unit/appsync-graphql/AppSyncGraphQLResolver.test.ts +++ b/packages/event-handler/tests/unit/appsync-graphql/AppSyncGraphQLResolver.test.ts @@ -93,7 +93,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver({ logger: console }); app.resolver<{ id: string }>( - async ({ id }) => { + ({ id }) => { return { id, title: 'Post Title', @@ -123,7 +123,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver({ logger: console }); app.resolver<{ title: string; content: string }>( - async ({ title, content }) => { + ({ title, content }) => { return { id: '123', title, @@ -166,7 +166,7 @@ describe('Class: AppSyncGraphQLResolver', () => { const app = new AppSyncGraphQLResolver(); app.onMutation<{ title: string; content: string }>( 'addPost', - async ({ title, content }) => { + ({ title, content }) => { return { id: '123', title, @@ -196,16 +196,13 @@ describe('Class: AppSyncGraphQLResolver', () => { it('resolver function has access to event and context', async () => { // Prepare const app = new AppSyncGraphQLResolver({ logger: console }); - app.onQuery<{ id: string }>( - 'getPost', - async ({ id }, { event, context }) => { - return { - id, - event, - context, - }; - } - ); + app.onQuery<{ id: string }>('getPost', ({ id }, { event, context }) => { + return { + id, + event, + context, + }; + }); // Act const event = onGraphqlEventFactory('getPost', 'Query', { id: '123' }); @@ -227,7 +224,7 @@ describe('Class: AppSyncGraphQLResolver', () => { public scope = 'scoped'; @app.onQuery('getPost') - public async handleGetPost({ id }: { id: string }) { + public handleGetPost({ id }: { id: string }) { return { id, scope: `${this.scope} id=${id}`, @@ -235,7 +232,7 @@ describe('Class: AppSyncGraphQLResolver', () => { } @app.onMutation('addPost') - public async handleAddPost({ + public handleAddPost({ title, content, }: { @@ -250,11 +247,11 @@ describe('Class: AppSyncGraphQLResolver', () => { }; } - public async handler(event: unknown, context: Context) { + public handler(event: unknown, context: Context) { return this.stuff(event, context); } - async stuff(event: unknown, context: Context) { + stuff(event: unknown, context: Context) { return app.resolve(event, context, { scope: this }); } } @@ -295,9 +292,7 @@ describe('Class: AppSyncGraphQLResolver', () => { public scope = 'scoped'; @app.batchResolver({ fieldName: 'batchGet' }) - public async handleBatchGet( - events: AppSyncResolverEvent<{ id: number }>[] - ) { + public handleBatchGet(events: AppSyncResolverEvent<{ id: number }>[]) { const ids = events.map((event) => event.arguments.id); return ids.map((id) => ({ id, @@ -305,7 +300,7 @@ describe('Class: AppSyncGraphQLResolver', () => { })); } - public async handler(event: unknown, context: Context) { + public handler(event: unknown, context: Context) { return app.resolve(event, context, { scope: this }); } } @@ -351,14 +346,14 @@ describe('Class: AppSyncGraphQLResolver', () => { throwOnError, aggregate: false, }) - public async handleBatchGet({ id }: { id: string }) { + public handleBatchGet({ id }: { id: string }) { return { id, scope: `${this.scope} id=${id} throwOnError=${throwOnError} aggregate=false`, }; } - public async handler(event: unknown, context: Context) { + public handler(event: unknown, context: Context) { return app.resolve(event, context, { scope: this }); } } @@ -395,7 +390,7 @@ describe('Class: AppSyncGraphQLResolver', () => { class Lambda { @app.resolver({ fieldName: 'getPost' }) - public async handleGetPost({ id }: { id: string }) { + public handleGetPost({ id }: { id: string }) { return { id, title: 'Post Title', @@ -403,7 +398,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; } - public async handler(event: unknown, context: Context) { + public handler(event: unknown, context: Context) { return app.resolve(event, context, { scope: this }); } } @@ -445,7 +440,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver({ logger: console }); app.resolver( - async () => { + () => { throw error; }, { @@ -677,9 +672,7 @@ describe('Class: AppSyncGraphQLResolver', () => { @app.onBatchQuery('batchGet', { throwOnError, }) - public async handleBatchGet( - events: AppSyncResolverEvent<{ id: number }>[] - ) { + public handleBatchGet(events: AppSyncResolverEvent<{ id: number }>[]) { const ids = events.map((event) => event.arguments.id); return ids.map((id) => ({ id, @@ -690,13 +683,11 @@ describe('Class: AppSyncGraphQLResolver', () => { @app.onBatchMutation('batchPut', { throwOnError, }) - public async handleBatchPut( - _events: AppSyncResolverEvent<{ id: number }>[] - ) { + public handleBatchPut(_events: AppSyncResolverEvent<{ id: number }>[]) { return [this.scope, this.scope]; } - public async handler(event: unknown, context: Context) { + public handler(event: unknown, context: Context) { return app.resolve(event, context, { scope: this }); } } @@ -776,9 +767,9 @@ describe('Class: AppSyncGraphQLResolver', () => { errorName: err.constructor.name, })); - app.onQuery('getUser', async () => { + app.onQuery('getUser', () => { throw errorClass === AggregateError - ? new errorClass([new Error()], message) + ? new errorClass([new Error('test error')], message) : new errorClass(message); }); @@ -800,7 +791,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver(); - app.exceptionHandler(ValidationError, async (error) => { + app.exceptionHandler(ValidationError, (error) => { return { message: 'Validation failed', details: error.message, @@ -808,7 +799,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; }); - app.exceptionHandler(NotFoundError, async (error) => { + app.exceptionHandler(NotFoundError, (error) => { return { message: 'Resource not found', details: error.message, @@ -816,7 +807,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; }); - app.onQuery<{ id: string }>('getUser', async ({ id }) => { + app.onQuery<{ id: string }>('getUser', ({ id }) => { if (!id) { throw new ValidationError('User ID is required'); } @@ -853,7 +844,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver(); - app.exceptionHandler(Error, async (error) => { + app.exceptionHandler(Error, (error) => { return { message: 'Generic error occurred', details: error.message, @@ -861,7 +852,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; }); - app.exceptionHandler(ValidationError, async (error) => { + app.exceptionHandler(ValidationError, (error) => { return { message: 'Validation failed', details: error.message, @@ -869,7 +860,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; }); - app.onQuery('getUser', async () => { + app.onQuery('getUser', () => { throw new ValidationError('Specific validation error'); }); @@ -891,7 +882,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver(); - app.exceptionHandler(AssertionError, async (error) => { + app.exceptionHandler(AssertionError, (error) => { return { message: 'Validation failed', details: error.message, @@ -899,7 +890,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; }); - app.onQuery('getUser', async () => { + app.onQuery('getUser', () => { throw new DatabaseError('Database connection failed'); }); @@ -920,11 +911,11 @@ describe('Class: AppSyncGraphQLResolver', () => { const app = new AppSyncGraphQLResolver({ logger: console }); const errorToBeThrown = new Error('Exception handler failed'); - app.exceptionHandler(ValidationError, async () => { + app.exceptionHandler(ValidationError, () => { throw errorToBeThrown; }); - app.onQuery('getUser', async () => { + app.onQuery('getUser', () => { throw new ValidationError('Original error'); }); @@ -962,7 +953,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; }); - app.onQuery('getUser', async () => { + app.onQuery('getUser', () => { throw new ValidationError('Sync error test'); }); @@ -984,7 +975,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver(); - app.exceptionHandler(RangeError, async (error) => { + app.exceptionHandler(RangeError, (error) => { return { message: 'This should not be called', details: error.message, @@ -1009,7 +1000,7 @@ describe('Class: AppSyncGraphQLResolver', () => { public readonly scope = 'scoped'; @app.exceptionHandler(ValidationError) - async handleValidationError(error: ValidationError) { + handleValidationError(error: ValidationError) { return { message: 'Decorator validation failed', details: error.message, @@ -1029,7 +1020,7 @@ describe('Class: AppSyncGraphQLResolver', () => { } @app.onQuery('getUser') - async getUser({ id, name }: { id: string; name: string }) { + getUser({ id, name }: { id: string; name: string }) { if (!id) { throw new ValidationError('Decorator error test'); } @@ -1039,7 +1030,7 @@ describe('Class: AppSyncGraphQLResolver', () => { return { id, name }; } - async handler(event: unknown, context: Context) { + handler(event: unknown, context: Context) { return app.resolve(event, context, { scope: this, }); @@ -1078,7 +1069,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver({ logger: console }); - app.exceptionHandler([ValidationError, NotFoundError], async (error) => { + app.exceptionHandler([ValidationError, NotFoundError], (error) => { return { message: 'User service error', details: error.message, @@ -1087,7 +1078,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; }); - app.onQuery<{ id: string }>('getId', async ({ id }) => { + app.onQuery<{ id: string }>('getId', ({ id }) => { if (!id) { throw new ValidationError('User ID is required for retrieval'); } @@ -1146,7 +1137,7 @@ describe('Class: AppSyncGraphQLResolver', () => { public readonly serviceName = 'OrderService'; @app.exceptionHandler([ValidationError, NotFoundError]) - async handleOrderErrors(error: ValidationError | NotFoundError) { + handleOrderErrors(error: ValidationError | NotFoundError) { return { message: `${this.serviceName} encountered an error`, details: error.message, @@ -1157,7 +1148,7 @@ describe('Class: AppSyncGraphQLResolver', () => { } @app.onQuery('getOrder') - async getOrderById({ orderId }: { orderId: string }) { + getOrderById({ orderId }: { orderId: string }) { if (!orderId) { throw new ValidationError('Order ID is required'); } @@ -1170,7 +1161,7 @@ describe('Class: AppSyncGraphQLResolver', () => { return { orderId, status: 'found', service: this.serviceName }; } - async handler(event: unknown, context: Context) { + handler(event: unknown, context: Context) { const resolved = app.resolve(event, context, { scope: this, }); @@ -1228,7 +1219,7 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver(); - app.exceptionHandler([ValidationError, TypeError], async (error) => { + app.exceptionHandler([ValidationError, TypeError], (error) => { return { message: 'Payment validation error', details: error.message, @@ -1237,7 +1228,7 @@ describe('Class: AppSyncGraphQLResolver', () => { }; }); - app.exceptionHandler(ValidationError, async (error) => { + app.exceptionHandler(ValidationError, (error) => { return { message: 'Specific payment validation error', details: error.message, @@ -1248,7 +1239,7 @@ describe('Class: AppSyncGraphQLResolver', () => { app.onQuery<{ amount: number; currency: string }>( 'getPayment', - async ({ amount, currency }) => { + ({ amount, currency }) => { if (!amount || amount <= 0) { throw new ValidationError('Invalid payment amount'); } @@ -1304,14 +1295,14 @@ describe('Class: AppSyncGraphQLResolver', () => { // Prepare const app = new AppSyncGraphQLResolver({ logger: console }); - app.exceptionHandler([], async (error) => { + app.exceptionHandler([], (error) => { return { message: 'This should never be called', details: error.message, }; }); - app.onQuery<{ requestId: string }>('getId', async ({ requestId }) => { + app.onQuery<{ requestId: string }>('getId', ({ requestId }) => { if (requestId === 'validation-error') { throw new ValidationError('Invalid request format'); } diff --git a/packages/event-handler/tests/unit/bedrock-agent/BedrockAgentFunctionResolver.test.ts b/packages/event-handler/tests/unit/bedrock-agent/BedrockAgentFunctionResolver.test.ts index 1b21f6694c..ae2e34b452 100644 --- a/packages/event-handler/tests/unit/bedrock-agent/BedrockAgentFunctionResolver.test.ts +++ b/packages/event-handler/tests/unit/bedrock-agent/BedrockAgentFunctionResolver.test.ts @@ -82,7 +82,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { const app = new BedrockAgentFunctionResolver(); app.tool( - async (params: { arg: string }) => { + (params: { arg: string }) => { return params.arg; }, { @@ -101,7 +101,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { const app = new BedrockAgentFunctionResolver(); app.tool( - async (params: { arg: string }) => { + (params: { arg: string }) => { return params.arg; }, { @@ -132,7 +132,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { ]); app.tool( - async (params: { a: number; b: number }) => { + (params: { a: number; b: number }) => { return params.a + params.b; }, { @@ -148,7 +148,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { ); app.tool( - async (params: { a: number; b: number }) => { + (params: { a: number; b: number }) => { return params.a * params.b; }, { @@ -176,7 +176,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { const app = new BedrockAgentFunctionResolver({ logger }); app.tool( - async (params: { arg: string }) => { + (params: { arg: string }) => { return params.arg; }, { @@ -186,7 +186,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { ); app.tool( - async (params: { arg: string }) => { + (params: { arg: string }) => { return params.arg; }, { @@ -196,8 +196,8 @@ describe('Class: BedrockAgentFunctionResolver', () => { ); app.tool( - async (_params) => { - throw new Error(); + () => { + throw new Error('test error'); }, { name: 'error', @@ -220,7 +220,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { const app = new BedrockAgentFunctionResolver(); app.tool( - async (_params, options) => { + (_params, options) => { return options?.event; }, { @@ -332,7 +332,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { const app = new BedrockAgentFunctionResolver(); app.tool( - async () => { + () => { return new BedrockFunctionResponse({ body: 'I am not sure', responseState: 'REPROMPT', @@ -535,7 +535,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { const app = new BedrockAgentFunctionResolver(); app.tool( - async (_params, _options) => { + (_params, _options) => { throw toThrow; }, { @@ -564,7 +564,7 @@ describe('Class: BedrockAgentFunctionResolver', () => { const app = new BedrockAgentFunctionResolver(); app.tool( - async (params, _options) => { + (params, _options) => { return `Hello, ${params.name}!`; }, { diff --git a/packages/event-handler/tests/unit/rest/RouteHandlerRegistry.test.ts b/packages/event-handler/tests/unit/rest/RouteHandlerRegistry.test.ts index 42dccf5f24..f27671fd38 100644 --- a/packages/event-handler/tests/unit/rest/RouteHandlerRegistry.test.ts +++ b/packages/event-handler/tests/unit/rest/RouteHandlerRegistry.test.ts @@ -1,5 +1,8 @@ import { describe, expect, it } from 'vitest'; -import { HttpVerbs } from '../../../src/rest/index.js'; +import { + HttpVerbs, + ParameterValidationError, +} from '../../../src/rest/index.js'; import { Route } from '../../../src/rest/Route.js'; import { RouteHandlerRegistry } from '../../../src/rest/RouteHandlerRegistry.js'; import type { Path } from '../../../src/types/rest.js'; @@ -570,20 +573,20 @@ describe('Class: RouteHandlerRegistry', () => { it('throws ParameterValidationError with multiple error messages for multiple invalid parameters', () => { // Prepare const registry = new RouteHandlerRegistry({ logger: console }); - const handler = async () => ({ message: 'test' }); + const handler = () => ({ message: 'test' }); registry.register( new Route(HttpVerbs.GET, '/api/:version/:resource/:id', handler) ); // Act & Assess - expect(async () => { + expect(() => { registry.resolve(HttpVerbs.GET, '/api/%20/users/%20'); - }).rejects.toMatchObject({ - issues: [ + }).toThrow( + new ParameterValidationError([ "Parameter 'version' cannot be empty", "Parameter 'id' cannot be empty", - ], - }); + ]) + ); }); }); }); diff --git a/packages/event-handler/tests/unit/rest/Router/basic-routing.test.ts b/packages/event-handler/tests/unit/rest/Router/basic-routing.test.ts index d4dffadb44..7ca29c9e2f 100644 --- a/packages/event-handler/tests/unit/rest/Router/basic-routing.test.ts +++ b/packages/event-handler/tests/unit/rest/Router/basic-routing.test.ts @@ -89,7 +89,7 @@ describe('Class: Router - Basic Routing', () => { const app = new Router(); const testEvent = createTestEvent('/test', 'GET'); - app.get('/test', async (reqCtx) => { + app.get('/test', (reqCtx) => { return { hasRequest: reqCtx.req instanceof Request, hasEvent: reqCtx.event === testEvent, @@ -107,7 +107,7 @@ describe('Class: Router - Basic Routing', () => { expect(actual.hasContext).toBe(true); }); - it('throws an internal server error for non-API Gateway events', async () => { + it('throws an internal server error for non-API Gateway events', () => { // Prepare const app = new Router(); const nonApiGatewayEvent = { Records: [] }; // SQS-like event @@ -123,10 +123,10 @@ describe('Class: Router - Basic Routing', () => { const app = new Router({ prefix: '/todos', }); - app.post('/', async () => { + app.post('/', () => { return { actualPath: '/todos' }; }); - app.get('/:todoId', async (reqCtx) => { + app.get('/:todoId', (reqCtx) => { return { actualPath: `/todos/${reqCtx.params.todoId}` }; }); diff --git a/packages/event-handler/tests/unit/rest/Router/decorators.test.ts b/packages/event-handler/tests/unit/rest/Router/decorators.test.ts index 0528e7a963..98c0ab7c5b 100644 --- a/packages/event-handler/tests/unit/rest/Router/decorators.test.ts +++ b/packages/event-handler/tests/unit/rest/Router/decorators.test.ts @@ -17,41 +17,41 @@ describe('Class: Router - Decorators', () => { class Lambda { @app.get('/test') - public async getTest() { + public getTest() { return { result: 'get-test' }; } @app.post('/test') - public async postTest() { + public postTest() { return { result: 'post-test' }; } @app.put('/test') - public async putTest() { + public putTest() { return { result: 'put-test' }; } @app.patch('/test') - public async patchTest() { + public patchTest() { return { result: 'patch-test' }; } @app.delete('/test') - public async deleteTest() { + public deleteTest() { return { result: 'delete-test' }; } @app.head('/test') - public async headTest() { + public headTest() { return { result: 'head-test' }; } @app.options('/test') - public async optionsTest() { + public optionsTest() { return { result: 'options-test' }; } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context); } } @@ -96,12 +96,12 @@ describe('Class: Router - Decorators', () => { public scope = 'class-scope'; @app.get('/test', [middleware]) - public async getTest() { + public getTest() { executionOrder.push('handler'); return { result: `${this.scope}: decorator-with-middleware` }; } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context, { scope: this }); } } @@ -149,41 +149,41 @@ describe('Class: Router - Decorators', () => { class Lambda { @app.get('/test', [middleware]) - public async getTest() { + public getTest() { return { result: 'get-decorator-middleware' }; } @app.post('/test', [middleware]) - public async postTest() { + public postTest() { return { result: 'post-decorator-middleware' }; } @app.put('/test', [middleware]) - public async putTest() { + public putTest() { return { result: 'put-decorator-middleware' }; } @app.patch('/test', [middleware]) - public async patchTest() { + public patchTest() { return { result: 'patch-decorator-middleware' }; } @app.delete('/test', [middleware]) - public async deleteTest() { + public deleteTest() { return { result: 'delete-decorator-middleware' }; } @app.head('/test', [middleware]) - public async headTest() { + public headTest() { return { result: 'head-decorator-middleware' }; } @app.options('/test', [middleware]) - public async optionsTest() { + public optionsTest() { return { result: 'options-decorator-middleware' }; } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context); } } @@ -218,7 +218,7 @@ describe('Class: Router - Decorators', () => { class Lambda { @app.errorHandler(BadRequestError) - public async handleBadRequest(error: BadRequestError) { + public handleBadRequest(error: BadRequestError) { return { statusCode: HttpStatusCodes.BAD_REQUEST, error: 'Bad Request', @@ -227,11 +227,11 @@ describe('Class: Router - Decorators', () => { } @app.get('/test') - public async getTest() { + public getTest() { throw new BadRequestError('test error'); } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context); } } @@ -265,7 +265,7 @@ describe('Class: Router - Decorators', () => { public scope = 'scoped'; @app.notFound() - public async handleNotFound(error: NotFoundError) { + public handleNotFound(error: NotFoundError) { return { statusCode: HttpStatusCodes.NOT_FOUND, error: 'Not Found', @@ -273,7 +273,7 @@ describe('Class: Router - Decorators', () => { }; } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context, { scope: this }); } } @@ -306,7 +306,7 @@ describe('Class: Router - Decorators', () => { class Lambda { @app.methodNotAllowed() - public async handleMethodNotAllowed(error: MethodNotAllowedError) { + public handleMethodNotAllowed(error: MethodNotAllowedError) { return { statusCode: HttpStatusCodes.METHOD_NOT_ALLOWED, error: 'Method Not Allowed', @@ -315,11 +315,11 @@ describe('Class: Router - Decorators', () => { } @app.get('/test') - public async getTest() { + public getTest() { throw new MethodNotAllowedError('POST not allowed'); } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context); } } @@ -353,7 +353,7 @@ describe('Class: Router - Decorators', () => { public scope = 'scoped'; @app.errorHandler(BadRequestError) - public async handleBadRequest(error: BadRequestError) { + public handleBadRequest(error: BadRequestError) { return { statusCode: HttpStatusCodes.BAD_REQUEST, error: 'Bad Request', @@ -362,11 +362,11 @@ describe('Class: Router - Decorators', () => { } @app.get('/test') - public async getTest() { + public getTest() { throw new BadRequestError('test error'); } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context, { scope: this }); } } @@ -399,7 +399,7 @@ describe('Class: Router - Decorators', () => { class Lambda { @app.get('/test') - public async getTest(reqCtx: RequestContext) { + public getTest(reqCtx: RequestContext) { return { hasRequest: reqCtx.req instanceof Request, hasEvent: reqCtx.event === testEvent, @@ -407,7 +407,7 @@ describe('Class: Router - Decorators', () => { }; } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context); } } @@ -431,7 +431,7 @@ describe('Class: Router - Decorators', () => { class Lambda { @app.errorHandler(BadRequestError) - public async handleBadRequest( + public handleBadRequest( error: BadRequestError, reqCtx: RequestContext ) { @@ -446,11 +446,11 @@ describe('Class: Router - Decorators', () => { } @app.get('/test') - public async getTest() { + public getTest() { throw new BadRequestError('test error'); } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context); } } @@ -475,13 +475,13 @@ describe('Class: Router - Decorators', () => { public scope = 'scoped'; @app.get('/test') - public async getTest() { + public getTest() { return { message: `${this.scope}: success`, }; } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context, { scope: this }); } } diff --git a/packages/event-handler/tests/unit/rest/Router/error-handling.test.ts b/packages/event-handler/tests/unit/rest/Router/error-handling.test.ts index f3921aa42b..87bc657628 100644 --- a/packages/event-handler/tests/unit/rest/Router/error-handling.test.ts +++ b/packages/event-handler/tests/unit/rest/Router/error-handling.test.ts @@ -107,7 +107,7 @@ describe('Class: Router - Error Handling', () => { vi.stubEnv('POWERTOOLS_DEV', ''); const app = new Router(); - app.errorHandler(BadRequestError, async () => { + app.errorHandler(BadRequestError, () => { throw new Error('Handler failed'); }); @@ -486,7 +486,7 @@ describe('Class: Router - Error Handling', () => { // Prepare const app = new Router(); - app.errorHandler(BadRequestError, async () => { + app.errorHandler(BadRequestError, () => { throw new NotFoundError('This error is thrown from the error handler'); }); @@ -514,7 +514,7 @@ describe('Class: Router - Error Handling', () => { // Prepare const app = new Router(); - app.errorHandler(BadRequestError, async () => { + app.errorHandler(BadRequestError, () => { throw new MethodNotAllowedError( 'This error is thrown from the error handler' ); @@ -545,7 +545,7 @@ describe('Class: Router - Error Handling', () => { vi.stubEnv('POWERTOOLS_DEV', 'true'); const app = new Router(); - app.errorHandler(BadRequestError, async () => { + app.errorHandler(BadRequestError, () => { throw new Error('This error is thrown from the error handler'); }); diff --git a/packages/event-handler/tests/unit/rest/Router/middleware.test.ts b/packages/event-handler/tests/unit/rest/Router/middleware.test.ts index 4d66055914..93b6abc230 100644 --- a/packages/event-handler/tests/unit/rest/Router/middleware.test.ts +++ b/packages/event-handler/tests/unit/rest/Router/middleware.test.ts @@ -57,7 +57,7 @@ describe('Class: Router - Middleware', () => { } ); - app.get(path as Path, middleware, async () => { + app.get(path as Path, middleware, () => { executionOrder.push('handler'); return { success: true }; }); @@ -79,7 +79,7 @@ describe('Class: Router - Middleware', () => { app.use(createTrackingMiddleware('middleware1', executionOrder)); app.use(createTrackingMiddleware('middleware2', executionOrder)); - app.get('/test', async () => { + app.get('/test', () => { executionOrder.push('handler'); return { success: true }; }); @@ -111,7 +111,7 @@ describe('Class: Router - Middleware', () => { ) ); - app.get('/test', async () => { + app.get('/test', () => { executionOrder.push('handler'); return { success: true }; }); @@ -190,7 +190,7 @@ describe('Class: Router - Middleware', () => { await next(); }); - app.use(async ({ next }) => { + app.use(({ next }) => { next(); }); @@ -221,7 +221,7 @@ describe('Class: Router - Middleware', () => { ); app.use(createTrackingMiddleware('middleware2', executionOrder)); - app.get('/test', async () => { + app.get('/test', () => { executionOrder.push('handler'); return { success: true }; }); @@ -249,7 +249,7 @@ describe('Class: Router - Middleware', () => { throw new Error('Cleanup error'); }); - app.get('/test', async () => { + app.get('/test', () => { executionOrder.push('handler'); return { success: true }; }); @@ -277,7 +277,7 @@ describe('Class: Router - Middleware', () => { app.use(createTrackingMiddleware('middleware1', executionOrder)); app.use(createTrackingMiddleware('middleware2', executionOrder)); - app.get('/test', async () => { + app.get('/test', () => { executionOrder.push('handler'); throw new Error('Handler error'); }); @@ -305,7 +305,7 @@ describe('Class: Router - Middleware', () => { app.use(createNoNextMiddleware('middleware1', executionOrder)); app.use(createTrackingMiddleware('middleware2', executionOrder)); - app.get('/test', async () => { + app.get('/test', () => { executionOrder.push('handler'); return { success: true }; }); @@ -334,7 +334,7 @@ describe('Class: Router - Middleware', () => { }) ); - app.get('/test', async () => { + app.get('/test', () => { executionOrder.push('handler'); return { success: true }; }); @@ -369,7 +369,7 @@ describe('Class: Router - Middleware', () => { reqCtx.res.headers.set('x-request-id', '12345'); }); - app.get('/test', async () => ({ success: true })); + app.get('/test', () => ({ success: true })); // Act const result = await app.resolve( @@ -457,7 +457,7 @@ describe('Class: Router - Middleware', () => { await next(); }); - app.get('/handler-precedence', async () => { + app.get('/handler-precedence', () => { const response = Response.json({ success: true }); response.headers.set('x-before-handler', 'handler-value'); return response; @@ -542,12 +542,12 @@ describe('Class: Router - Middleware', () => { public scope = 'class-scope'; @app.get('/test') - public async getTest() { + public getTest() { executionOrder.push('handler'); return { message: `${this.scope}: success` }; } - public async handler(event: unknown, _context: Context) { + public handler(event: unknown, _context: Context) { return app.resolve(event, _context, { scope: this }); } } @@ -586,7 +586,7 @@ describe('Class: Router - Middleware', () => { executionOrder ); - app.get('/test', [routeMiddleware], async () => { + app.get('/test', [routeMiddleware], () => { executionOrder.push('handler'); return { success: true }; }); @@ -619,7 +619,7 @@ describe('Class: Router - Middleware', () => { executionOrder ); - app.get('/test', [routeMiddleware1, routeMiddleware2], async () => { + app.get('/test', [routeMiddleware1, routeMiddleware2], () => { executionOrder.push('handler'); return { success: true }; }); @@ -646,7 +646,7 @@ describe('Class: Router - Middleware', () => { app.use(createTrackingMiddleware('global-middleware', executionOrder)); - app.get('/test', async () => { + app.get('/test', () => { executionOrder.push('handler'); return { success: true }; }); @@ -674,7 +674,7 @@ describe('Class: Router - Middleware', () => { new Response('Route middleware response', { status: 403 }) ); - app.get('/test', [routeMiddleware], async () => { + app.get('/test', [routeMiddleware], () => { executionOrder.push('handler'); return { success: true }; }); diff --git a/packages/event-handler/tests/unit/rest/converters.test.ts b/packages/event-handler/tests/unit/rest/converters.test.ts index e33c6136e6..e6f5a9a893 100644 --- a/packages/event-handler/tests/unit/rest/converters.test.ts +++ b/packages/event-handler/tests/unit/rest/converters.test.ts @@ -1,4 +1,3 @@ -import type { APIGatewayProxyEvent } from 'aws-lambda'; import { describe, expect, it } from 'vitest'; import { handlerResultToProxyResult, @@ -6,36 +5,11 @@ import { proxyEventToWebRequest, webResponseToProxyResult, } from '../../../src/rest/index.js'; +import { createTestEvent } from './helpers.js'; describe('Converters', () => { describe('proxyEventToWebRequest', () => { - const baseEvent: APIGatewayProxyEvent = { - httpMethod: 'GET', - path: '/test', - resource: '/test', - headers: {}, - multiValueHeaders: {}, - queryStringParameters: null, - multiValueQueryStringParameters: {}, - pathParameters: null, - stageVariables: null, - requestContext: { - accountId: '123456789012', - apiId: 'test-api', - httpMethod: 'GET', - path: '/test', - requestId: 'test-request-id', - resourceId: 'test-resource', - resourcePath: '/test', - stage: 'test', - domainName: 'api.example.com', - identity: { - sourceIp: '127.0.0.1', - }, - } as any, - isBase64Encoded: false, - body: null, - }; + const baseEvent = createTestEvent('/test', 'GET'); it('converts basic GET request', () => { // Prepare & Act @@ -65,25 +39,24 @@ describe('Converters', () => { it('uses X-Forwarded-Proto header for protocol', () => { // Prepare - const event = { - ...baseEvent, - headers: { 'X-Forwarded-Proto': 'https' }, - }; + const event = createTestEvent('/test', 'GET', { + 'X-Forwarded-Proto': 'http', + }); // Act const request = proxyEventToWebRequest(event); // Assess expect(request).toBeInstanceOf(Request); - expect(request.url).toBe('https://api.example.com/test'); + expect(request.url).toBe('http://api.example.com/test'); }); - it('handles null values in multiValueHeaders arrays', () => { + it('handles undefined values in multiValueHeaders arrays', () => { // Prepare const event = { ...baseEvent, multiValueHeaders: { - Accept: null as any, + Accept: undefined, 'Custom-Header': ['value1'], }, }; @@ -97,12 +70,12 @@ describe('Converters', () => { expect(request.headers.get('Custom-Header')).toBe('value1'); }); - it('handles null values in multiValueQueryStringParameters arrays', () => { + it('handles undefined values in multiValueQueryStringParameters arrays', () => { // Prepare const event = { ...baseEvent, multiValueQueryStringParameters: { - filter: null as any, + filter: undefined, sort: ['desc'], }, }; @@ -117,7 +90,7 @@ describe('Converters', () => { expect(url.searchParams.get('sort')).toBe('desc'); }); - it('handles POST request with string body', async () => { + it('handles POST request with string body', () => { // Prepare const event = { ...baseEvent, @@ -136,7 +109,7 @@ describe('Converters', () => { expect(request.headers.get('Content-Type')).toBe('application/json'); }); - it('decodes base64 encoded body', async () => { + it('decodes base64 encoded body', () => { // Prepare const originalText = 'Hello World'; const base64Text = Buffer.from(originalText).toString('base64'); @@ -321,13 +294,13 @@ describe('Converters', () => { expect(url.searchParams.getAll('multi')).toEqual(['value1', 'value2']); }); - it('skips null queryStringParameter values', () => { + it('skips undefined queryStringParameter values', () => { // Prepare const event = { ...baseEvent, queryStringParameters: { valid: 'value', - null: null as any, + null: undefined, }, }; @@ -341,13 +314,13 @@ describe('Converters', () => { expect(url.searchParams.has('null')).toBe(false); }); - it('skips null header values', () => { + it('skips undefined header values', () => { // Prepare const event = { ...baseEvent, headers: { 'Valid-Header': 'value', - 'Null-Header': null as any, + 'Undefined-Header': undefined, }, }; @@ -357,26 +330,7 @@ describe('Converters', () => { // Assess expect(request).toBeInstanceOf(Request); expect(request.headers.get('Valid-Header')).toBe('value'); - expect(request.headers.get('Null-Header')).toBe(null); - }); - - it('handles null/undefined collections', () => { - // Prepare - const event = { - ...baseEvent, - headers: null as any, - multiValueHeaders: null as any, - queryStringParameters: null as any, - multiValueQueryStringParameters: null as any, - }; - - // Act - const request = proxyEventToWebRequest(event); - - // Assess - expect(request).toBeInstanceOf(Request); - expect(request.method).toBe('GET'); - expect(request.url).toBe('https://api.example.com/test'); + expect(request.headers.get('Undefined-Header')).toBe(null); }); }); @@ -568,7 +522,7 @@ describe('Converters', () => { expect(result.headers.get('content-type')).toBe('text/plain'); }); - it('converts APIGatewayProxyResult with multiValueHeaders', async () => { + it('converts APIGatewayProxyResult with multiValueHeaders', () => { // Prepare const proxyResult = { statusCode: 200, @@ -590,7 +544,7 @@ describe('Converters', () => { ); }); - it('converts plain object to JSON Response with default headers', async () => { + it('converts plain object to JSON Response with default headers', () => { // Prepare const obj = { message: 'success' }; @@ -604,7 +558,7 @@ describe('Converters', () => { expect(result.headers.get('Content-Type')).toBe('application/json'); }); - it('uses provided headers for plain object', async () => { + it('uses provided headers for plain object', () => { // Prepare const obj = { message: 'success' }; const headers = new Headers({ 'x-custom': 'value' }); @@ -617,7 +571,7 @@ describe('Converters', () => { expect(result.headers.get('x-custom')).toBe('value'); }); - it('handles APIGatewayProxyResult with undefined headers', async () => { + it('handles APIGatewayProxyResult with undefined headers', () => { // Prepare const proxyResult = { statusCode: 200, @@ -634,7 +588,7 @@ describe('Converters', () => { expect(result.status).toBe(200); }); - it('handles APIGatewayProxyResult with undefined multiValueHeaders', async () => { + it('handles APIGatewayProxyResult with undefined multiValueHeaders', () => { // Prepare const proxyResult = { statusCode: 200, @@ -651,7 +605,7 @@ describe('Converters', () => { expect(result.headers.get('content-type')).toBe('text/plain'); }); - it('handles APIGatewayProxyResult with undefined values in multiValueHeaders', async () => { + it('handles APIGatewayProxyResult with undefined values in multiValueHeaders', () => { // Prepare const proxyResult = { statusCode: 200, diff --git a/packages/event-handler/tests/unit/rest/helpers.ts b/packages/event-handler/tests/unit/rest/helpers.ts index 4f04e0e3c1..aeb4e51c2d 100644 --- a/packages/event-handler/tests/unit/rest/helpers.ts +++ b/packages/event-handler/tests/unit/rest/helpers.ts @@ -19,7 +19,7 @@ export const createTestEvent = ( requestContext: { httpMethod, path, - domainName: 'localhost', + domainName: 'api.example.com', } as APIGatewayProxyEvent['requestContext'], resource: '', }); @@ -40,7 +40,7 @@ export const createThrowingMiddleware = ( executionOrder: string[], errorMessage: string ): Middleware => { - return async () => { + return () => { executionOrder.push(name); throw new Error(errorMessage); }; @@ -51,7 +51,7 @@ export const createReturningMiddleware = ( executionOrder: string[], response: HandlerResponse ): Middleware => { - return async () => { + return () => { executionOrder.push(name); return response; }; @@ -61,7 +61,7 @@ export const createNoNextMiddleware = ( name: string, executionOrder: string[] ): Middleware => { - return async () => { + return () => { executionOrder.push(name); // Intentionally doesn't call next() }; diff --git a/packages/event-handler/tests/unit/rest/middleware/compress.test.ts b/packages/event-handler/tests/unit/rest/middleware/compress.test.ts index 0aa8a1e289..653bb62afd 100644 --- a/packages/event-handler/tests/unit/rest/middleware/compress.test.ts +++ b/packages/event-handler/tests/unit/rest/middleware/compress.test.ts @@ -22,7 +22,7 @@ describe('Compress Middleware', () => { it('compresses response when conditions are met', async () => { // Prepare - app.get('/test', async () => { + app.get('/test', () => { return body; }); @@ -49,7 +49,7 @@ describe('Compress Middleware', () => { 'content-length': '1', }), ], - async () => { + () => { return { test: 'x' }; } ); @@ -65,7 +65,7 @@ describe('Compress Middleware', () => { it('skips compression for HEAD requests', async () => { // Prepare const headEvent = createTestEvent('/test', 'HEAD'); - app.head('/test', async () => { + app.head('/test', () => { return body; }); @@ -93,7 +93,7 @@ describe('Compress Middleware', () => { 'content-length': '2000', }), ], - async () => { + () => { return body; } ); @@ -118,7 +118,7 @@ describe('Compress Middleware', () => { 'cache-control': 'no-transform', }), ], - async () => { + () => { return body; } ); @@ -144,7 +144,7 @@ describe('Compress Middleware', () => { 'content-length': '2000', }), ], - async () => { + () => { return body; } ); @@ -162,7 +162,7 @@ describe('Compress Middleware', () => { const noCompressionEvent = createTestEvent('/test', 'GET', { 'Accept-Encoding': 'identity', }); - app.get('/test', async () => { + app.get('/test', () => { return body; }); diff --git a/packages/event-handler/tests/unit/rest/utils.test.ts b/packages/event-handler/tests/unit/rest/utils.test.ts index 5082eb6608..2c8db5db78 100644 --- a/packages/event-handler/tests/unit/rest/utils.test.ts +++ b/packages/event-handler/tests/unit/rest/utils.test.ts @@ -469,7 +469,7 @@ describe('Path Utilities', () => { const composed = composeMiddleware(middleware); await composed({ reqCtx: mockOptions, - next: async () => { + next: () => { executionOrder.push('handler'); }, }); @@ -488,7 +488,7 @@ describe('Path Utilities', () => { async ({ next }) => { await next(); }, - async () => { + () => { return { shortCircuit: true }; }, ]; @@ -496,7 +496,7 @@ describe('Path Utilities', () => { const composed = composeMiddleware(middleware); const result = await composed({ reqCtx: mockOptions, - next: async () => { + next: () => { return { handler: true }; }, }); @@ -514,7 +514,7 @@ describe('Path Utilities', () => { const composed = composeMiddleware(middleware); const result = await composed({ reqCtx: mockOptions, - next: async () => { + next: () => { return { handler: true }; }, }); @@ -541,7 +541,7 @@ describe('Path Utilities', () => { const composed = composeMiddleware([]); const result = await composed({ reqCtx: mockOptions, - next: async () => { + next: () => { return { handler: true }; }, }); @@ -559,7 +559,7 @@ describe('Path Utilities', () => { const composed = composeMiddleware(middleware); const result = await composed({ reqCtx: mockOptions, - next: async () => { + next: () => { return undefined; }, });