UNPKG

@testmonitor/ts-reporter-client

Version:

A convenient TypeScript wrapper for the TestMonitor reporter API endpoints. It can be used in both TypeScript and JavaScript.

87 lines (86 loc) 3.29 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.Client = void 0; const HttpClient_1 = require("./services/http/HttpClient"); const ApiResponse_1 = require("./services/http/ApiResponse"); class Client { /** * * @param config */ constructor(config) { this.createReportPath = config.createReportPath; this.submitTestResultsPath = config.submitTestResultsPath; this.uploadAttachmentPath = config.uploadAttachmentPath; this.client = new HttpClient_1.HttpClient({ basePath: this.generateBasePath(config.domain), accessToken: config.accessToken, }); } /** * * @param request * @returns */ createReport(request) { return __awaiter(this, void 0, void 0, function* () { return ApiResponse_1.ApiResponse.from(yield this.client.request({ method: 'POST', path: this.createReportPath, body: Object.assign(Object.assign(Object.assign({ integration_id: request.integrationId, name: request.name }, (request.milestoneId != null && { milestoneId: request.milestoneId })), (request.milestoneId == null && request.milestone != null && { milestone: request.milestone })), (request.testEnvironmentId != null && { test_environment_id: request.testEnvironmentId })), })); }); } /** * * @param request * @returns */ submitTestResults(request) { return __awaiter(this, void 0, void 0, function* () { return ApiResponse_1.ApiResponse.from(yield this.client.request({ method: 'POST', path: this.submitTestResultsPath, body: { report_id: request.reportId, data: request.data, }, })); }); } /** * * @param request */ uploadAttachment(request) { return __awaiter(this, void 0, void 0, function* () { const formData = new FormData(); formData.append('id', request.id); formData.append('report_id', request.reportId.toString()); formData.append('attachment', request.attachment); yield this.client.request({ method: 'POST', path: this.uploadAttachmentPath, body: formData, }); }); } /** * * @param domain * @returns string */ generateBasePath(domain) { return `https://${domain}`; } } exports.Client = Client;