alagarr
Version:
Alagarr is a request-response helper library that removes the boilerplate from your Node.js serverless functions and helps make your code portable.
32 lines (31 loc) • 1.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const requests_1 = require("../../../test/fixtures/requests");
const normalize_programming_model_1 = __importDefault(require("./normalize-programming-model"));
const testRequest = Object.assign({}, requests_1.get, { httpMethod: 'GET', queryStringParameters: {
foo: 'bar',
} });
describe('Normalize programming model', () => {
test('normalize request http method', () => {
const normalized = normalize_programming_model_1.default({ httpMethod: testRequest.httpMethod });
expect(normalized.method).toEqual(testRequest.httpMethod);
});
test('normalize request query parameters', () => {
const normalized = normalize_programming_model_1.default({
queryStringParameters: testRequest.queryStringParameters,
});
expect(normalized.query).toEqual(testRequest.queryStringParameters);
});
test('normalized request should have a "source" property', () => {
const normalized = normalize_programming_model_1.default(testRequest);
expect(normalized.source).toEqual('api-gateway');
});
test('handle crap request', () => {
const normalized = normalize_programming_model_1.default({});
expect(normalized.query).toEqual({});
expect(normalized.method).toEqual('');
});
});