diff --git a/src/serverless-adapter.ts b/src/serverless-adapter.ts index 8af93dbb..5f58b4ea 100644 --- a/src/serverless-adapter.ts +++ b/src/serverless-adapter.ts @@ -8,7 +8,12 @@ import { ResolverContract, ServerlessHandler, } from './contracts'; -import { DEFAULT_BINARY_ENCODINGS, ILogger, createDefaultLogger } from './core'; +import { + DEFAULT_BINARY_CONTENT_TYPES, + DEFAULT_BINARY_ENCODINGS, + ILogger, + createDefaultLogger, +} from './core'; //#endregion @@ -61,11 +66,11 @@ export class ServerlessAdapter< /** * Settings for whether the response should be treated as binary or not * - * @default `contentEncodings` and `contentTypes` are set with {@link DEFAULT_BINARY_ENCODINGS} and {@link DEFAULT_BINARY_ENCODINGS}, respectively. + * @default `contentEncodings` and `contentTypes` are set with {@link DEFAULT_BINARY_ENCODINGS} and {@link DEFAULT_BINARY_CONTENT_TYPES}, respectively. */ protected binarySettings: BinarySettings = { contentEncodings: DEFAULT_BINARY_ENCODINGS, - contentTypes: DEFAULT_BINARY_ENCODINGS, + contentTypes: DEFAULT_BINARY_CONTENT_TYPES, }; /** diff --git a/test/serverless-adapter.spec.ts b/test/serverless-adapter.spec.ts index f5272040..f7141dbf 100644 --- a/test/serverless-adapter.spec.ts +++ b/test/serverless-adapter.spec.ts @@ -1,16 +1,54 @@ import { BinarySettings, + DEFAULT_BINARY_CONTENT_TYPES, + DEFAULT_BINARY_ENCODINGS, HandlerContract, NO_OP, ServerlessAdapter, createDefaultLogger, } from '../src'; import { ApiGatewayV2Adapter } from '../src/adapters/aws'; +import * as logger from '../src/core/logger'; import { DefaultHandler } from '../src/handlers/default'; import { PromiseResolver } from '../src/resolvers/promise'; import { FrameworkMock } from './mocks/framework.mock'; describe('ServerlessAdapter', () => { + it('should have correct default values', () => { + const defaultLoggerSymbol = Symbol('createDefaultLogger'); + + jest + .spyOn(logger, 'createDefaultLogger') + .mockReturnValue(defaultLoggerSymbol as any); + const oldEnv = process.env; + jest.resetModules(); + process.env = { ...oldEnv, NODE_ENV: 'test' }; + + const adapter = ServerlessAdapter.new(null); + + expect(adapter['binarySettings']).toHaveProperty( + 'contentEncodings', + DEFAULT_BINARY_ENCODINGS, + ); + expect(adapter['binarySettings']).toHaveProperty( + 'contentTypes', + DEFAULT_BINARY_CONTENT_TYPES, + ); + expect(adapter['respondWithErrors']).toEqual(false); + expect(adapter['log']).toEqual(defaultLoggerSymbol); + expect(adapter['adapters']).toHaveLength(0); + expect(adapter['framework']).toBeUndefined(); + expect(adapter['resolver']).toBeUndefined(); + expect(adapter['handler']).toBeUndefined(); + expect(adapter['app']).toEqual(null); + + jest.resetModules(); + process.env = { ...oldEnv, NODE_ENV: 'development' }; + const developmentAdapter = ServerlessAdapter.new(null); + + expect(developmentAdapter['respondWithErrors']).toEqual(true); + }); + it('should can create a pipeline of handlers', () => { const statusCode = 200; const response = { body: true };