UNPKG

systelab-components-wdio-test

Version:
33 lines (32 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApplicationRemoteClient = void 0; const http_status_js_1 = require("../server/http-status.js"); class ApplicationRemoteClient { static async start(host, browserType, options) { const response = await this.executeEndpoint(host, 'start', { browserType, options }); const body = await response.json(); return body.id; } static async stop(application) { await this.executeEndpoint(application.host, `${application.remoteId}/stop`); } static async executeEndpoint(remoteHost, route, body = {}) { const host = remoteHost.name; const port = remoteHost.port; const apiPrefix = remoteHost.apiPrefix; const baseURL = `http://${host}:${port}/${apiPrefix}/applications`; const endpointURL = `${baseURL}/${route}`; const response = await fetch(endpointURL, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body), }); if (response.status === http_status_js_1.HttpStatus.INTERNAL_SERVER_ERROR || response.status == http_status_js_1.HttpStatus.NOT_FOUND) { const errorMessage = response.body.error; throw new Error('Error: ' + errorMessage); } return response; } } exports.ApplicationRemoteClient = ApplicationRemoteClient;