UNPKG

@bitblit/epsilon

Version:

Tiny adapter to simplify building API gateway Lambda APIS

67 lines 3.65 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("@bitblit/ratchet/common"); const sample_server_components_1 = require("../../sample/sample-server-components"); const run_handler_as_filter_1 = require("./run-handler-as-filter"); const router_util_1 = require("../../http/route/router-util"); describe('#routerUtilApplyOpenApiDoc', function () { it('should find the most specific route and the least specific', () => __awaiter(this, void 0, void 0, function* () { const inst = yield sample_server_components_1.SampleServerComponents.createSampleEpsilonGlobalHandler('jest-most specific route'); expect(inst.epsilon.modelValidator).toBeTruthy(); // TODO: move this to its own test const evtFixed = { httpMethod: 'get', path: '/v0/multi/fixed', requestContext: { stage: 'v0', }, queryStringParameters: {}, }; const evtVar = { httpMethod: 'get', path: '/v0/multi/xyz', requestContext: { stage: 'v0', }, queryStringParameters: {}, }; const findFixedRP = yield inst.epsilon.webHandler.findBestMatchingRoute(evtFixed); const findVariableRP = yield inst.epsilon.webHandler.findBestMatchingRoute(evtVar); const findFixed = yield run_handler_as_filter_1.RunHandlerAsFilter.findHandler(findFixedRP, evtFixed, {}, false); const findVariable = yield run_handler_as_filter_1.RunHandlerAsFilter.findHandler(findVariableRP, evtVar, {}, false); expect(findFixed).toBeTruthy(); expect(findFixed['flag']).toEqual('fixed'); expect(findVariable).toBeTruthy(); expect(findVariable['flag']).toEqual('variable'); common_1.Logger.info('done'); })); it('should reformat a path to match the other library', function () { const inString = '/meta/item/{itemId}'; const outString = router_util_1.RouterUtil.openApiPathToRouteParserPath(inString); expect(outString).toEqual('/meta/item/:itemId'); }); it('should redact authorization values from events for logging', function () { const inputEvent = { authorization: { raw: 'secret-access-token-here', }, headers: { authorization: 'Bearer secret-access-token-here', }, }; // @ts-expect-error private method const logEventObj = JSON.parse(run_handler_as_filter_1.RunHandlerAsFilter.eventToStringForLog(inputEvent)); expect(logEventObj.authorization.raw).toEqual(run_handler_as_filter_1.RunHandlerAsFilter.redact(inputEvent.authorization.raw)); expect(logEventObj.headers.authorization).toEqual(run_handler_as_filter_1.RunHandlerAsFilter.redact(logEventObj.headers.authorization)); }); }); //# sourceMappingURL=run-handler-as-filter.spec.js.map