testrail-modern-client
Version:
A modern TypeScript client for TestRail API
96 lines (95 loc) • 4.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SectionService = void 0;
const base_1 = require("./base");
/**
* Service for managing TestRail sections.
*/
class SectionService extends base_1.BaseService {
/**
* Returns a list of sections for a project and test suite.
* @param projectId - The ID of the project
* @param suiteId - The ID of the test suite (optional if the project is operating in single suite mode)
* @param offset - Where to start counting the sections from (the offset)
* @param limit - The number of sections the response should return (max 250)
* @returns A list of sections
* @throws {Error} 400 - Invalid or unknown project or test suite
* @throws {Error} 403 - No access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async list(projectId, suiteId, offset = 0, limit = 250) {
const response = await this.client.get(`/get_sections/${projectId}`, {
params: {
suite_id: suiteId,
offset,
limit,
},
});
return response.data.sections;
}
/**
* Returns an existing section.
* @param sectionId - The ID of the section
* @returns The section
* @throws {Error} 400 - Invalid or unknown section
* @throws {Error} 403 - No access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async get(sectionId) {
const response = await this.client.get(`/get_section/${sectionId}`);
return response.data;
}
/**
* Creates a new section.
* @param projectId - The ID of the project
* @param section - The section data to add
* @returns The created section
* @throws {Error} 400 - Invalid or unknown project or test suite
* @throws {Error} 403 - No permissions to add sections or no access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async add(projectId, section) {
const response = await this.client.post(`/add_section/${projectId}`, section);
return response.data;
}
/**
* Updates an existing section (partial updates are supported).
* @param sectionId - The ID of the section
* @param section - The section data to update
* @returns The updated section
* @throws {Error} 400 - Invalid or unknown section
* @throws {Error} 403 - No permissions to modify sections or no access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async update(sectionId, section) {
const response = await this.client.post(`/update_section/${sectionId}`, section);
return response.data;
}
/**
* Moves a section to another suite or section.
* @param sectionId - The ID of the section
* @param moveData - The move operation data
* @returns The moved section
* @throws {Error} 400 - Invalid or unknown section_id, parent_id, or after_id
* @throws {Error} 403 - No permissions to add sections or no access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
* @since TestRail 6.5.2
*/
async move(sectionId, moveData) {
const response = await this.client.post(`/move_section/${sectionId}`, moveData);
return response.data;
}
/**
* Deletes an existing section.
* Note: Deleting a section cannot be undone and also deletes all related test cases as well as active tests & results.
* @param sectionId - The ID of the section
* @param soft - If true, only returns data about affected items without actually deleting
* @throws {Error} 400 - Invalid or unknown section
* @throws {Error} 403 - No permissions to delete sections or test cases or no access to the project
* @throws {Error} 429 - Too many requests (TestRail Cloud only)
*/
async delete(sectionId, soft) {
await this.client.post(`/delete_section/${sectionId}`, { soft: soft ? 1 : 0 });
}
}
exports.SectionService = SectionService;