From 9664f6bbf5317ac7e72f6ccb20fdff7fe5c258b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Sun, 17 Jul 2022 12:52:05 -0300 Subject: [PATCH] test(azure): added test when useContextLogWhenInternalLogger is false --- test/handlers/azure.handler.spec.ts | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/handlers/azure.handler.spec.ts b/test/handlers/azure.handler.spec.ts index b534a43c..f3c0cd9d 100644 --- a/test/handlers/azure.handler.spec.ts +++ b/test/handlers/azure.handler.spec.ts @@ -98,4 +98,39 @@ describe(AzureHandler.name, () => { undefined, ); }); + + it('should prefer default log method when send false to useContextLogWhenInternalLogger option', () => { + const event = createHttpTriggerEvent('GET', '/'); + const context = createHttpTriggerContext('GET', '/'); + + const defaultServerlessHandler = jest.fn(() => Promise.resolve(response)); + const defaultGetHandler = jest + .spyOn(DefaultHandler.prototype, 'getHandler') + .mockImplementation(() => defaultServerlessHandler); + + const log = createDefaultLogger(); + + const getHandlerArguments = [ + app, + mockFramework, + adapters, + resolver, + binarySettings, + respondWithErrors, + log, + ] as const; + + const azureHandler = new AzureHandler({ + useContextLogWhenInternalLogger: false, + }).getHandler(...getHandlerArguments); + + expect(azureHandler(context, event)).resolves.toBe(response); + + expect(defaultGetHandler).toHaveBeenCalledWith(...getHandlerArguments); + expect(defaultServerlessHandler).toHaveBeenCalledWith( + event, + context, + undefined, + ); + }); });