import _ from 'lodash' import axios from 'axios' /** * */ class ReportClient { /** * Creates a new client for interacting with the Bespoken Test API * Must pass the API key which can be found in the Bespoken Dashboard under account settings * @param {string} apiKey * @param {string} [baseURL] */ constructor (apiKey, baseURL) { this.apiKey = apiKey this.baseURL = baseURL || 'https://test-api.bespoken.io' if (window.location.href.includes('localhost')) { this.baseURL = 'http://localhost:3000' } } /** * Classifies the specified run * @param {string} jobID * @returns {Promise<any[]>} */ async jobSummaryResults (jobID) { const runURL = `${this.baseURL}/report/job/${jobID}/summary` const response = await axios.get(runURL) return response.data } /** * Classifies the specified run * @param {string} runID * @returns {Promise<any[]>} */ async loadTestSummaryResults (runID) { const runURL = `${this.baseURL}/report/load-test/${runID}/summary` const response = await axios.get(runURL) return response.data } /** * Classifies the specified run * @param {string} runID * @returns {Promise<any[]>} */ async loadTestByMinute (runID) { const runURL = `${this.baseURL}/report/load-test/${runID}/results-by-minute` const response = await axios.get(runURL) return response.data } /** * Classifies the specified run * @param {string} runID * @returns {Promise<any[]>} */ async runThroughputByMinutes (runID) { const runURL = `${this.baseURL}/report/run/${runID}/throughputByMinute` const response = await axios.get(runURL) return response.data } /** * Classifies the specified run * @param {string} runID * @returns {Promise<any[]>} */ async runSummaryResults (runID) { const runURL = `${this.baseURL}/report/run/${runID}/summaryResults` const response = await axios.get(runURL) return response.data } /** * Classifies the specified run * @param {string} runID * @returns {Promise<any[]>} */ async runRawResults (runID) { const runURL = `${this.baseURL}/report/load-test/${runID}/raw-results` const response = await axios.get(runURL) return response.data } } export default ReportClient