UNPKG

@studyportals/sp-r2d2

Version:

A framework that contains various components used when developing projects that will be deployed via AWS λ.

111 lines 5.49 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; 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 chai_1 = require("chai"); const mocha_1 = require("@testdeck/mocha"); const Moq = require("typemoq"); const application_1 = require("../../../../application"); const event_translation_error_class_1 = require("../../../../environment/core/errors/event-translation-error.class"); const sns_event_translator_class_1 = require("../../../../environment/execution-environments/sns/event-translation/sns-event-translator.class"); let SnsEventTranslatorTest = class SnsEventTranslatorTest { get snsMessageMock() { return this._snsMessageMock; } get snsMessage() { return this.snsMessageMock.object; } get snsEventRecordMock() { return this._snsEventRecordMock; } get snsEventRecord() { return this.snsEventRecordMock.object; } get snsEventMock() { return this._snsEventMock; } get snsEvent() { return this.snsEventMock.object; } get testInstanceMock() { return this._testInstanceMock; } get testInstance() { return this.testInstanceMock.object; } before() { this._snsEventMock = Moq.Mock.ofType(); this._snsEventRecordMock = Moq.Mock.ofType(); this._snsMessageMock = Moq.Mock.ofType(); this.snsEventRecordMock.setup((_) => _.Sns).returns(() => this.snsMessage); this._testInstanceMock = Moq.Mock.ofType(sns_event_translator_class_1.SnsEventTranslator); this.testInstanceMock.callBase = true; } translate_NoRecords_BaseRequestWithNoData() { return __awaiter(this, void 0, void 0, function* () { this.snsEventMock.setup((_) => _.Records).returns(() => []); const result = yield this.testInstance.translate(this.snsEvent); chai_1.assert.instanceOf(result, application_1.BaseRequest); chai_1.assert.deepEqual(result.data, {}); }); } translate_OneRecordWithData_BaseRequestWithData() { return __awaiter(this, void 0, void 0, function* () { const providedValue = { SomeProperty: 'SomeValue' }; this.snsMessageMock.setup((_) => _.Message).returns(() => JSON.stringify(providedValue)); this.snsEventMock.setup((_) => _.Records).returns(() => [this.snsEventRecord]); const result = yield this.testInstance.translate(this.snsEvent); chai_1.assert.instanceOf(result, application_1.BaseRequest); chai_1.assert.deepEqual(result.data, providedValue); }); } translate_OneRecordWithoutData_BaseRequestWithNoData() { return __awaiter(this, void 0, void 0, function* () { this.snsMessageMock.setup((_) => _.Message).returns(() => ''); this.snsEventMock.setup((_) => _.Records).returns(() => [this.snsEventRecord]); const result = yield this.testInstance.translate(this.snsEvent); chai_1.assert.instanceOf(result, application_1.BaseRequest); chai_1.assert.deepEqual(result.data, {}); }); } translate_MultipleRecords_EventTranslationError() { return __awaiter(this, void 0, void 0, function* () { this.snsMessageMock.setup((_) => _.Message).returns(() => ''); this.snsEventMock.setup((_) => _.Records).returns(() => [this.snsEventRecord, this.snsEventRecord]); let receivedError; try { yield this.testInstance.translate(this.snsEvent); } catch (e) { receivedError = e; } chai_1.assert.instanceOf(receivedError, event_translation_error_class_1.EventTranslationError); }); } }; __decorate([ mocha_1.test ], SnsEventTranslatorTest.prototype, "translate_NoRecords_BaseRequestWithNoData", null); __decorate([ mocha_1.test ], SnsEventTranslatorTest.prototype, "translate_OneRecordWithoutData_BaseRequestWithNoData", null); __decorate([ mocha_1.test ], SnsEventTranslatorTest.prototype, "translate_MultipleRecords_EventTranslationError", null); SnsEventTranslatorTest = __decorate([ (0, mocha_1.suite)() ], SnsEventTranslatorTest); //# sourceMappingURL=sns-event-translator.test.js.map