import { APIGatewayProxyEvent } from "aws-lambda" ; import { chance } from "_/helpers" ; template TParameters template TEvent interface APIGatewayProxyEventOptions < TParameters extends { } , TEvent extends { } > { path : string ; pathParameters : TParameters ; method : "GET" | "POST" ; headers : { [ name ] : string ; } ; body : TEvent | string ; } param number return export function mockAPIGatewayProxyEventPathParameters ( count = chance . integer ( { min : 0 , max : 2 } ) ) { return [ ... Array ( count ) ] . reduce ( params => { return { ... params , [ chance . string ( ) ] : chance . string ( ) } ; } , { } ) ; } template TParameters template TEvent param options return export function mockAPIGatewayProxyEventOptions < TParameters extends { } , TEvent extends { } > ( override ? ) { return { path : "/" , pathParameters : mockAPIGatewayProxyEventPathParameters ( ) , method : "POST" , body : "" , ... override , headers : { "Host" : chance . url ( ) , "Referer" : chance . url ( ) , "User-Agent" : chance . string ( ) , ... ( override ? override . headers : { } ) } } ; } template TParameters template TEvent param options return export function mockAPIGatewayProxyEvent < TEvent extends { } > ( override ? ) ; export function mockAPIGatewayProxyEvent < TParameters extends { } , TEvent extends { } > ( override ? ) ; export function mockAPIGatewayProxyEvent < TParameters extends { } , TEvent extends { } > ( override ? ) { const options = mockAPIGatewayProxyEventOptions < TParameters , TEvent > ( override ) ; const body = typeof options . body !== "string" ? JSON . stringify ( options . body ) : options . body ; return { resource : "/" , path : options . path , httpMethod : options . method , headers : options . headers , queryStringParameters : null , pathParameters : options . pathParameters , requestContext : { accountId : chance . string ( ) , apiId : chance . string ( ) , authorizer : { } , connectedAt : chance . integer ( ) , protocol : chance . string ( ) , httpMethod : "POST" , requestId : chance . guid ( ) , requestTimeEpoch : chance . timestamp ( ) * 1000 + chance . millisecond ( ) , resourceId : chance . string ( ) , resourcePath : "/" , identity : { clientCert : null , accountId : null , apiKey : chance . string ( ) , apiKeyId : chance . string ( ) , accessKey : null , caller : null , cognitoAuthenticationProvider : null , cognitoAuthenticationType : null , cognitoIdentityId : null , cognitoIdentityPoolId : null , principalOrgId : null , sourceIp : chance . ip ( ) , user : null , userAgent : chance . string ( ) , userArn : null } , path : options . path , stage : chance . string ( ) } , multiValueHeaders : { } , multiValueQueryStringParameters : null , stageVariables : null , body , isBase64Encoded : chance . bool ( ) } ; }