UNPKG

wa-chat-server

Version:

Watson Assistant powered chat server

85 lines (84 loc) 3.5 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 }); exports.SessionStorageMockFactory = SessionStorageMockFactory; const SessionDoesNotExistError_1 = require("../../exception/SessionDoesNotExistError"); function SessionStorageMockFactory(sessId = '') { class SessionStorageMock { constructor() { this.initCalled = false; this.createCalled = false; this.readCalled = false; this.writeCalled = false; this.testSessionData = {}; } init() { return __awaiter(this, void 0, void 0, function* () { this.initCalled = true; return this; }); } create() { return __awaiter(this, void 0, void 0, function* () { this.createCalled = true; if (sessId) { throw new Error('Unexpected create() call'); } return sessId; }); } // eslint-disable-next-line @typescript-eslint/no-unused-vars read(sessionId) { return __awaiter(this, void 0, void 0, function* () { this.readCalled = true; if (!sessId) { throw new SessionDoesNotExistError_1.SessionDoesNotExistError(); } if (!this.initCalled) { throw new Error('read() called before init()'); } return this.testSessionData; }); } write(sessionId, data) { return __awaiter(this, void 0, void 0, function* () { this.writeCalled = true; if (!this.initCalled) { throw new Error('write() called before init()'); } if (!this.readCalled && !this.createCalled) { throw new Error('write() called before read() or create()'); } if (sessionId !== sessId) { throw new Error(`write() called with incorrect argument '${sessionId}'`); } if (sessId && data !== this.testSessionData) { throw new Error('write() called with incorrect data'); } }); } check() { if (!this.initCalled) { throw new Error('init() not called'); } if (!this.readCalled) { throw new Error('read() not called'); } if (!sessId && !this.createCalled) { throw new Error('create() not called'); } if (!this.write) { throw new Error('write() not called'); } } } return SessionStorageMock.prototype.constructor; }