import * as Hapi from 'hapi'; import {Handler, IServer} from "./app"; import asHapi from "./transpositions/to-hapi"; class BaseServer { private host: string; private port: number; constructor({ host, port }: { host: string, port: number }) { this.host = host; this.port = port; } public test(): void { // nope... } } export class MockServer extends BaseServer implements IServer { private routes: Handler[] = []; public started: boolean = false; constructor({ host, port }: { host: string, port: number }) { super({ host, port }); this.routes = []; } public async addRoutes(routes: Handler[]) { this.routes.push(...routes); } public run() { this.started = true; return Promise.resolve(); } } class HttpServer implements IServer { private client: Hapi.Server; public constructor(client: Hapi.Server) { this.client = client; } public async addRoutes(routes: Handler[]) { for (const route of routes) { const handler = asHapi(route.assetPath, route.fields || ['*']); this.client.route({ method: route.method, path: route.path as string, handler, }); } } public run() { return this.client.start(); } } export default HttpServer;