UNPKG

@bitblit/epsilon

Version:

Tiny adapter to simplify building API gateway Lambda APIS

85 lines 4.97 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 client_sqs_1 = require("@aws-sdk/client-sqs"); const aws_sqs_sns_background_manager_1 = require("./aws-sqs-sns-background-manager"); const echo_processor_1 = require("../../built-in/background/echo-processor"); const no_op_processor_1 = require("../../built-in/background/no-op-processor"); const client_sns_1 = require("@aws-sdk/client-sns"); const aws_sdk_client_mock_1 = require("aws-sdk-client-mock"); const model_validator_1 = require("@bitblit/ratchet/model-validator"); const common_1 = require("@bitblit/ratchet/common"); let mockSqs; let mockSns; describe('#createEntry', function () { mockSns = (0, aws_sdk_client_mock_1.mockClient)(client_sns_1.SNSClient); mockSqs = (0, aws_sdk_client_mock_1.mockClient)(client_sqs_1.SQSClient); let backgroundMgr; const fakeAccountNumber = '123456789012'; let backgroundConfig; let backgroundAwsConfig; const fakeModelValidator = new model_validator_1.ModelValidator({ BackgroundBuiltInSampleInputValidatedProcessor: {} }); const echoProcessor = new echo_processor_1.EchoProcessor(); const noOpProcessor = new no_op_processor_1.NoOpProcessor(); beforeEach(() => { mockSqs.reset(); mockSns.reset(); backgroundConfig = { processors: [echoProcessor, noOpProcessor], httpSubmissionPath: '/background/', implyTypeFromPathSuffix: true, httpMetaEndpoint: '/background-meta', }; backgroundAwsConfig = { queueUrl: 'https://fake-sqs.fake-availability-zone.test.com/' + fakeAccountNumber + '/fakeQueue.fifo', notificationArn: 'arn:aws:sns:fake-availability-zone:' + fakeAccountNumber + ':fakeSnsTopicName', }; backgroundMgr = new aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager(backgroundAwsConfig, mockSqs, mockSns); }); it('Should return queue attributes', () => __awaiter(this, void 0, void 0, function* () { mockSqs.on(client_sqs_1.GetQueueAttributesCommand).resolves({ Attributes: { ApproximateNumberOfMessages: 1, }, }); const queueAttr = yield backgroundMgr.fetchCurrentQueueAttributes(); const msgCount = yield backgroundMgr.fetchApproximateNumberOfQueueEntries(); common_1.Logger.info('Got : %j', queueAttr); common_1.Logger.info('Msg: %d', msgCount); expect(queueAttr).toBeTruthy(); expect(msgCount).toEqual(1); })); it('Should round-trip guids with prefix no slash', () => __awaiter(this, void 0, void 0, function* () { const prefix = 'test'; const guid = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.generateBackgroundGuid(); expect(guid).toBeTruthy(); const path = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.backgroundGuidToPath(prefix, guid); const outGuid = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.pathToBackgroundGuid(prefix, path); expect(outGuid).toEqual(guid); })); it('Should round-trip guids with prefix with slash', () => __awaiter(this, void 0, void 0, function* () { const prefix = 'test/'; const guid = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.generateBackgroundGuid(); expect(guid).toBeTruthy(); const path = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.backgroundGuidToPath(prefix, guid); const outGuid = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.pathToBackgroundGuid(prefix, path); expect(outGuid).toEqual(guid); })); it('Should round-trip guids with no prefix', () => __awaiter(this, void 0, void 0, function* () { const prefix = null; const guid = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.generateBackgroundGuid(); expect(guid).toBeTruthy(); const path = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.backgroundGuidToPath(prefix, guid); const outGuid = aws_sqs_sns_background_manager_1.AwsSqsSnsBackgroundManager.pathToBackgroundGuid(prefix, path); expect(outGuid).toEqual(guid); })); }); //# sourceMappingURL=background-manager.spec.js.map