UNPKG

testrail-modern-client

Version:
45 lines (44 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestService = void 0; const base_1 = require("./base"); /** * Service for interacting with TestRail tests (individual instances of test cases). */ class TestService extends base_1.BaseService { /** * Returns a list of tests for a test run. * @param runId - The ID of the test run * @param filters - Optional filters for the request * @param offset - Optional pagination offset * @param limit - Optional pagination limit (max 250) * @returns List of tests * @throws {Error} - If the test run is invalid or unknown (400) * @throws {Error} - If there is no access to the project (403) * @throws {Error} - If too many requests are made (429) - TestRail Cloud only */ async list(runId, filters) { const response = await this.client.get(`/get_tests/${runId}`, { params: filters }); if (response.data && typeof response.data === 'object' && 'tests' in response.data) { return response.data.tests; } console.warn(`Unexpected response format from TestRail API: ${JSON.stringify(response.data)}`); return []; } /** * Returns an existing test. * @param testId - The ID of the test * @param withData - Optional parameter to get data * @returns The requested test * @throws {Error} - If the test is invalid or unknown (400) * @throws {Error} - If there is no access to the project (403) * @throws {Error} - If too many requests are made (429) - TestRail Cloud only */ async get(testId, withData) { const response = await this.client.get(`/get_test/${testId}`, { params: withData ? { with_data: withData } : undefined, }); return response.data; } } exports.TestService = TestService;