Skip to content

Commit

Permalink
fix(serverless-adapter): passing wrong constant to binary settings co…
Browse files Browse the repository at this point in the history
…ntent types property

fix #12
  • Loading branch information
H4ad committed May 20, 2022
1 parent b9daa97 commit 1d121eb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/serverless-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
};

/**
Expand Down
38 changes: 38 additions & 0 deletions test/serverless-adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand Down

0 comments on commit 1d121eb

Please sign in to comment.