Parsing body string using middy when calling an AWS lambda handler with Jest?

Viewed 30

Taking a lambda handler written in typescript

const identityUrl: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (event) => {
    const iFRequest = event.body as unknown as IFRequest;
    const fileUrl = iFRequest;
    return formatJSONResponse({
        result: fileUrl,
    });
}

export const main = middyfy(identityFileGetSigner);

And calling it with a Jest test case results in the body being passed to the lambda as an unparsed string.

const defaultEvent: APIGatewayProxyEvent = {
  httpMethod: 'post',
  headers: {Authorization: "dummyToken"},
  body: JSON.stringify(apiParamsBasic),
  isBase64Encoded: false,
  path: '/url,
  multiValueQueryStringParameters: null,
  multiValueHeaders: null,
  pathParameters: null,
  queryStringParameters: null,
  stageVariables: null,
  requestContext: null,
  resource: ''
}

test('Empty list', async () => {
  const result1 = await main(defaultEvent, defaultContext);
}

How to get middy to parse the string?

0 Answers
Related