Comparing version 0.1.0 to 0.1.2
{ | ||
"name": "funclify", | ||
"version": "0.1.0", | ||
"version": "0.1.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.ts", |
import { Api } from './index'; | ||
import { HandlerEvent, HandlerResponse } from '@netlify/functions'; | ||
export class ApiTestHarness { | ||
private api: Api; | ||
constructor(api: Api) { | ||
export interface TestRequest<TBody = unknown> { | ||
method: string; | ||
url: string; | ||
headers: Record<string, string>; | ||
body: TBody; | ||
params?: Record<string, string>; | ||
} | ||
export class ApiTestHarness<TApi extends Api<any>> { | ||
private api: TApi; | ||
constructor(api: TApi) { | ||
this.api = api; | ||
} | ||
async handleRequest(request: Request) { | ||
this.api.baseHandler( | ||
async handleRequest(request: TestRequest): Promise<HandlerResponse> { | ||
return this.api.baseHandler( | ||
{ | ||
@@ -16,3 +25,4 @@ httpMethod: request.method, | ||
body: request.body, | ||
} as any, | ||
queryStringParameters: request.params ?? {}, | ||
} as HandlerEvent, | ||
{} as any | ||
@@ -19,0 +29,0 @@ ); |
39829
1005