testrail-modern-client
Version:
A modern TypeScript client for TestRail API
141 lines (140 loc) • 5.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResultService = void 0;
const base_1 = require("./base");
/**
* Service for managing TestRail test results.
* @since TestRail 6.7
*/
class ResultService extends base_1.BaseService {
/**
* Returns a list of test results for a test.
* @param testId - The ID of the test
* @param offset - The offset of the first record to return (used for pagination)
* @param limit - The maximum number of records to return (used for pagination, max 250)
* @param filters - Optional filters to apply
* @returns A list of test results
* @throws {Error} 400 - Invalid or unknown test
* @throws {Error} 403 - No access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async list(testId, offset = 0, limit = 250, filters) {
const response = await this.client.get(`/get_results/${testId}`, {
params: {
offset,
limit,
...filters,
},
});
return response.data.results;
}
/**
* Returns a list of test results for a test case in a specific test run.
* @param runId - The ID of the test run
* @param caseId - The ID of the test case
* @param offset - The offset of the first record to return (used for pagination)
* @param limit - The maximum number of records to return (used for pagination, max 250)
* @param filters - Optional filters to apply
* @returns A list of test results
* @throws {Error} 400 - Invalid or unknown test run or case
* @throws {Error} 403 - No access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async listForCase(runId, caseId, offset = 0, limit = 250, filters) {
const response = await this.client.get(`/get_results_for_case/${runId}/${caseId}`, {
params: {
offset,
limit,
...filters,
},
});
return response.data.results;
}
/**
* Returns a list of test results for a test run.
* @param runId - The ID of the test run
* @param offset - The offset of the first record to return (used for pagination)
* @param limit - The maximum number of records to return (used for pagination, max 250)
* @param filters - Optional filters to apply
* @returns A list of test results
* @throws {Error} 400 - Invalid or unknown test run
* @throws {Error} 403 - No access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async listForRun(runId, offset = 0, limit = 250, filters) {
const response = await this.client.get(`/get_results_for_run/${runId}`, {
params: {
offset,
limit,
...filters,
},
});
return response.data.results;
}
/**
* Returns an existing test result.
* @param resultId - The ID of the test result
* @returns The test result
* @throws {Error} 400 - Invalid or unknown test result
* @throws {Error} 403 - No access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async get(resultId) {
const response = await this.client.get(`/get_result/${resultId}`);
return response.data;
}
/**
* Adds a new test result, comment or assigns a test.
* @param testId - The ID of the test
* @param result - The test result data to add
* @returns The created test result
* @throws {Error} 400 - Invalid or unknown test
* @throws {Error} 403 - No permissions to add test results or no access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async add(testId, result) {
const response = await this.client.post(`/add_result/${testId}`, result);
return response.data;
}
/**
* Adds a new test result, comment or assigns a test (for a test run and case combination).
* @param runId - The ID of the test run
* @param caseId - The ID of the test case
* @param result - The test result data to add
* @returns The created test result
* @throws {Error} 400 - Invalid or unknown test run or case
* @throws {Error} 403 - No permissions to add test results or no access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async addForCase(runId, caseId, result) {
const response = await this.client.post(`/add_result_for_case/${runId}/${caseId}`, result);
return response.data;
}
/**
* Adds multiple test results for cases in a test run.
* @param runId - The ID of the test run
* @param results - The test results data to add
* @returns The created test results
* @throws {Error} 400 - Invalid or unknown test run/cases
* @throws {Error} 403 - No permissions to add test results or no access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async addForCases(runId, results) {
const response = await this.client.post(`/add_results_for_cases/${runId}`, results);
return response.data;
}
/**
* Adds multiple test results for tests in a test run.
* @param runId - The ID of the test run
* @param results - The test results data to add
* @returns The created test results
* @throws {Error} 400 - Invalid or unknown test run/tests
* @throws {Error} 403 - No permissions to add test results or no access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async addForTests(runId, results) {
const response = await this.client.post(`/add_results/${runId}`, results);
return response.data;
}
}
exports.ResultService = ResultService;