UNPKG

@studyportals/sp-r2d2

Version:

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

125 lines 6.22 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 mocha_1 = require("@testdeck/mocha"); const Moq = require("typemoq"); const chai_1 = require("chai"); const environment_1 = require("../../../environment"); let PingEventHandlerDecoratorTest = class PingEventHandlerDecoratorTest { constructor() { this.event = 'SomeEvent'; } get eventHandler() { return this.eventHandlerMock.object; } get responseSender() { return this.responseSenderMock.object; } get testInstance() { return this.testInstanceMock.object; } before() { this.eventHandlerMock = Moq.Mock.ofType(); this.responseSenderMock = Moq.Mock.ofType(); this.testInstanceMock = Moq.Mock.ofType(environment_1.PingEventHandlerDecorator); this.testInstanceMock.callBase = true; this.testInstanceMock.setup((_) => _['decoratedEventHandler']).returns(() => this.eventHandler); } handle_PingEvent_PongSent() { return __awaiter(this, void 0, void 0, function* () { let awaited = false; this.testInstanceMock.setup((_) => _.isPingEvent(Moq.It.isAny())).returns(() => __awaiter(this, void 0, void 0, function* () { return true; })); this.responseSenderMock .setup((_) => _.sendPong(Moq.It.isAny())) .returns(() => new Promise((_) => setImmediate(() => { awaited = true; _(); }))); yield this.testInstance.handle(this.event, this.responseSender); this.responseSenderMock.verify((_) => _.sendPong(this.event), Moq.Times.once()); chai_1.assert.isTrue(awaited); }); } handle_NotPingEvent_PongNotSent() { return __awaiter(this, void 0, void 0, function* () { this.testInstanceMock.setup((_) => _.isPingEvent(Moq.It.isAny())).returns(() => __awaiter(this, void 0, void 0, function* () { return false; })); yield this.testInstance.handle(this.event, this.responseSender); this.responseSenderMock.verify((_) => _.sendPong(Moq.It.isAny()), Moq.Times.never()); }); } handle_NotPingEvent_HandlingPassedToDecoratedHandler() { return __awaiter(this, void 0, void 0, function* () { let awaited = false; this.testInstanceMock.setup((_) => _.isPingEvent(Moq.It.isAny())).returns(() => __awaiter(this, void 0, void 0, function* () { return false; })); this.eventHandlerMock .setup((_) => _.handle(Moq.It.isAny(), Moq.It.isAny())) .returns(() => new Promise((_) => setImmediate(() => { awaited = true; _(); }))); yield this.testInstance.handle(this.event, this.responseSender); this.eventHandlerMock.verify((_) => _.handle(this.event, this.responseSender), Moq.Times.once()); chai_1.assert.isTrue(awaited); }); } handle_PingEvent_HandlingNotPassedToDecoratedHandler() { return __awaiter(this, void 0, void 0, function* () { this.testInstanceMock.setup((_) => _.isPingEvent(Moq.It.isAny())).returns(() => __awaiter(this, void 0, void 0, function* () { return true; })); yield this.testInstance.handle(this.event, this.responseSender); this.eventHandlerMock.verify((_) => _.handle(Moq.It.isAny(), Moq.It.isAny()), Moq.Times.never()); }); } isPingEvent_PingEvent_True() { return __awaiter(this, void 0, void 0, function* () { chai_1.assert.isTrue(yield this.testInstance.isPingEvent(this.createPingEvent())); }); } isPingEvent_NotPingEvent_False() { return __awaiter(this, void 0, void 0, function* () { const pingEvent = this.createPingEvent(); delete pingEvent['___PING___']; chai_1.assert.isFalse(yield this.testInstance.isPingEvent(pingEvent)); }); } createPingEvent() { return { ___PING___: 1, }; } }; __decorate([ mocha_1.test ], PingEventHandlerDecoratorTest.prototype, "handle_PingEvent_PongSent", null); __decorate([ mocha_1.test ], PingEventHandlerDecoratorTest.prototype, "handle_NotPingEvent_PongNotSent", null); __decorate([ mocha_1.test ], PingEventHandlerDecoratorTest.prototype, "handle_NotPingEvent_HandlingPassedToDecoratedHandler", null); __decorate([ mocha_1.test ], PingEventHandlerDecoratorTest.prototype, "handle_PingEvent_HandlingNotPassedToDecoratedHandler", null); __decorate([ mocha_1.test ], PingEventHandlerDecoratorTest.prototype, "isPingEvent_PingEvent_True", null); __decorate([ mocha_1.test ], PingEventHandlerDecoratorTest.prototype, "isPingEvent_NotPingEvent_False", null); PingEventHandlerDecoratorTest = __decorate([ (0, mocha_1.suite)() ], PingEventHandlerDecoratorTest); //# sourceMappingURL=ping-event-handler-decorator.test.js.map