UNPKG

testrail-modern-client

Version:
142 lines (141 loc) 5.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CaseService = void 0; const base_1 = require("./base"); /** * Service for managing test cases in TestRail */ class CaseService extends base_1.BaseService { /** * Returns a list of test cases for a project or specific test suite * @param projectId - The ID of the project * @param filters - Optional filters to apply * @returns List of test cases * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project */ async list(projectId, filters) { const response = await this.client.get(`/get_cases/${projectId}`, { params: filters, }); return response.data.cases; } /** * Returns an existing test case * @param caseId - The ID of the test case * @returns The test case * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project */ async get(caseId) { const response = await this.client.get(`/get_case/${caseId}`); return response.data; } /** * Creates a new test case * @param sectionId - The ID of the section the test case should be added to * @param testCase - The test case to create * @returns The created test case * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project */ async add(sectionId, testCase) { const response = await this.client.post(`/add_case/${sectionId}`, testCase); return response.data; } /** * Updates an existing test case (partial updates are supported) * @param caseId - The ID of the test case * @param testCase - The test case fields to update * @returns The updated test case * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project */ async update(caseId, testCase) { const response = await this.client.post(`/update_case/${caseId}`, testCase); return response.data; } /** * Updates multiple test cases with the same values * @param suiteId - The ID of the test suite (optional if the project is operating in single suite mode) * @param caseIds - The IDs of the test cases to update * @param updates - The fields to update for all test cases * @returns The updated test cases * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project */ async updateBulk(suiteId, caseIds, updates) { const response = await this.client.post(`/update_cases/${suiteId}`, { case_ids: caseIds, ...updates, }); return response.data; } /** * Copies test cases to another suite/section * @param sectionId - The ID of the section to copy the cases to * @param caseIds - The IDs of the test cases to copy * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project */ async copyToSection(sectionId, caseIds) { await this.client.post(`/copy_cases_to_section/${sectionId}`, { case_ids: caseIds, }); } /** * Moves test cases to another suite/section * @param sectionId - The ID of the section to move the cases to * @param suiteId - The ID of the suite to move the cases to * @param caseIds - The IDs of the test cases to move * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project */ async moveToSection(sectionId, suiteId, caseIds) { await this.client.post(`/move_cases_to_section/${sectionId}`, { suite_id: suiteId, case_ids: caseIds, }); } /** * Deletes an existing test case * @param caseId - The ID of the test case * @param soft - If true, returns information about what would be deleted without actually deleting * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project * @remarks Deleting a test case cannot be undone and also permanently deletes all test results in active test runs */ async delete(caseId, soft = false) { await this.client.post(`/delete_case/${caseId}`, { soft: soft ? 1 : 0 }); } /** * Deletes multiple test cases * @param suiteId - The ID of the test suite (optional if the project is operating in single suite mode) * @param projectId - The ID of the project * @param caseIds - The IDs of the test cases to delete * @param soft - If true, returns information about what would be deleted without actually deleting * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project * @remarks Deleting test cases cannot be undone and also permanently deletes all test results in active test runs */ async deleteBulk(suiteId, projectId, caseIds, soft = false) { await this.client.post(`/delete_cases/${suiteId}`, { project_id: projectId, case_ids: caseIds, soft: soft ? 1 : 0, }); } /** * Returns the edit history for a test case * @param caseId - The ID of the test case * @returns List of history entries * @throws {Error} 400 - Invalid or unknown test case * @throws {Error} 403 - No access to the project * @since TestRail 6.5.4 */ async getHistory(caseId) { const response = await this.client.get(`/get_history_for_case/${caseId}`); return response.data; } } exports.CaseService = CaseService;