diff --git a/src/libs/lambda.test.ts b/src/libs/lambda.test.ts new file mode 100644 index 0000000..b0a1ea5 --- /dev/null +++ b/src/libs/lambda.test.ts @@ -0,0 +1,22 @@ +import middy from '@middy/core'; +import middyJsonBodyParser from '@middy/http-json-body-parser'; +import { middyfy } from './lambda'; + +jest.mock('@middy/core', () => { + const use = jest.fn().mockImplementation(() => 'middyfied handler'); + return jest.fn().mockImplementation(() => ({ use })); +}); +jest.mock('@middy/http-json-body-parser'); + +const MOCK_MIDDY = middy as jest.MockedFunction; + +describe('middyfy', () => { + it('should wrap handler with middy, apply JSON body parser, and return middy instance', () => { + const handler = jest.fn(); + const middyfiedHandler = middyfy(handler); + expect(middy).toHaveBeenCalledWith(handler); + const mockMiddyInstance = MOCK_MIDDY.mock.results[0].value; + expect(mockMiddyInstance.use).toHaveBeenCalledWith(middyJsonBodyParser()); + expect(middyfiedHandler).toBe('middyfied handler'); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 896f946..b2a9bd5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,8 @@ "removeComments": true, "sourceMap": true, "target": "ES2020", - "outDir": "lib" + "outDir": "lib", + "esModuleInterop": true, }, "include": ["src/**/*.ts", "serverless.ts"], "exclude": [