UNPKG

@bitblit/epsilon

Version:

Tiny adapter to simplify building API gateway Lambda APIS

73 lines 3.73 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 inter_api_util_1 = require("./inter-api-util"); const jest_1 = require("@bitblit/ratchet/jest"); const globals_1 = require("@jest/globals"); describe('#interApiUtil', function () { let mockSns; let mockSqs; let mockBgMgr; const evt = { Records: [ { EventSource: 'aws:sns', EventVersion: '1.0', EventSubscriptionArn: 'arn:aws:sns:us-east-1:012345678901:GenericApiEventTopicDev:6efec6a5-1f02-4fc5-b0f7-fa7c013cf8bb', Sns: { Type: 'Notification', MessageId: '205de1e8-7ba6-52f5-b706-b815f442c512', TopicArn: 'arn:aws:sns:us-east-1:012345678901:GenericApiEventTopicDev', Subject: null, Message: '{"type":"EPSILON_INTER_API_EVENT","interApiEvent":{"source":"OriginalApi","type":"Sample","data":{"notes":"SOURCE API: OriginalApi","timestampEpochMS":1636011428200}}}', Timestamp: '2021-11-04T07:37:08.241Z', SignatureVersion: '1', Signature: 'LyS2ybM/Epsq5sFqPJd==', SigningCertUrl: 'https://sns.us-east-1.amazonaws.com/SimpleNotificationService-7ff5318490ec183fbaddaa2a969abfda.pem', UnsubscribeUrl: 'https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:012345678901:GenericApiEventTopicDev:6efec6a5-1f02-4fc5-b0f7-fa7c013cf8bb', MessageAttributes: {}, }, }, ], }; beforeEach(() => { mockSns = jest_1.JestRatchet.mock(globals_1.jest.fn); mockSqs = jest_1.JestRatchet.mock(globals_1.jest.fn); mockBgMgr = jest_1.JestRatchet.mock(globals_1.jest.fn); //new AwsSqsSnsBackgroundManager({} as BackgroundAwsConfig, mockSqs, mockSns); }); it('should translate processes', () => __awaiter(this, void 0, void 0, function* () { mockBgMgr.createEntry.mockResolvedValue({ t: 1 }); mockBgMgr.addEntriesToQueue.mockResolvedValue(['a]']); const cfg = { aws: { source: 'test', snsArn: 'test', localMode: true, }, processMappings: [ { typeRegex: '.*', sourceRegex: '.*', disabled: false, backgroundProcessTypes: ['TESTBG'], }, ], }; const output = yield inter_api_util_1.InterApiUtil.processInterApiEvent(evt, cfg, mockBgMgr); expect(output).not.toBeNull(); expect(output.length).toEqual(1); })); it('should verify that an event is an inter-api even', () => __awaiter(this, void 0, void 0, function* () { const res = inter_api_util_1.InterApiUtil.isInterApiSnsEvent(evt); expect(res).toBeTruthy(); }), 500); }); //# sourceMappingURL=inter-api-util.spec.js.map