UNPKG

testrail-integration

Version:
449 lines 17.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestRailClient = void 0; const routed_1 = require("../routed"); class TestRailClient { constructor(options) { this.uri = "/index.php?/api/v2"; this.caseIdsMap = new Map(); this.base = options.url.includes("https") ? `${options.url}${this.uri}` : `https://${options.url}${this.uri}`; this.username = options.username; this.password = options.password; } async addResultsForCases(runId, results) { const url = `${this.base}/add_results_for_cases/${runId}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify({ "results": results })); return JSON.parse(response.body); } async addResultForCase(runId, caseId, content) { const url = `${this.base}/add_result_for_case/${runId}/${caseId}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } async getCase(caseId) { const url = `${this.base}/get_case/${caseId}`; const response = await routed_1.route(url, this.headers()); return response; } async getCases(projectId, caseFilters) { const queryParams = this.queryCaseFilters(caseFilters); const url = `${this.base}/get_cases/${projectId}${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } async addCase(sectionId, content) { const url = `${this.base}/add_case/${sectionId}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } async updateCase(caseId, content) { const url = `${this.base}/update_case/${caseId}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } async deleteCase(caseId) { const url = `${this.base}/delete_case/${caseId}`; await routed_1.route(url, this.headers(), "POST"); } async deleteCases(projectId, suiteId, soft = 1, caseIds) { const url = `${this.base}/delete_case/${projectId}&suite_id=${suiteId}&soft=${soft}`; await routed_1.route(url, this.headers(), "POST", JSON.stringify({ "case_ids": caseIds })); } async getRun(runId) { const url = `${this.base}/get_run/${runId}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } async getRuns(projectId) { const url = `${this.base}/get_runs/${projectId}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } async addRun(projectId, content) { const url = `${this.base}/add_run/${projectId}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } async updateRun(runId, content) { const url = `${this.base}/update_run/${runId}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } async closeRun(runId) { const url = `${this.base}/close_run/${runId}`; const response = await routed_1.route(url, this.headers(), "POST"); return JSON.parse(response.body); } async deleteRun(runId) { const url = `${this.base}/delete_run/${runId}`; await routed_1.route(url, this.headers(), "POST"); } async addTestResult(runid, caseid, content) { return this.addResultForCase(runid, caseid, content); } async updateTestCase(caseid, content) { return this.updateCase(caseid, content); } headers() { const auth = Buffer.from(this.username + ':' + this.password).toString('base64'); const header = { Authorization: `Basic ${auth}`, "Content-Type": "application/json" }; return header; } queryCaseFilters(filters) { let val = []; if (filters !== undefined || filters === null) { const val = Object.entries(filters).map((key) => { let st = ""; if (key[1] !== "") { st = `&${key[0]}=${key[1]}`; } else { st = `&${key[0]}`; } return st; }); return val.toString().replace(/,&/g, '&'); } return val.toString(); } async getRunId(projectId, runName) { const response = await this.getRuns(projectId); const testRun = response.find((tr) => runName === tr.name); if (testRun) { return testRun.id; } return 0; } // ----- Case Fields ----- async getCaseFields() { const url = `${this.base}/get_case_fields`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } // ----- Case Types ----- async getCaseTypes() { const url = `${this.base}/get_case_types`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; // ----- Configurations ----- async getConfigs(project_id) { const url = `${this.base}/get_configs/${project_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async addConfigGroup(project_id, content) { const url = `${this.base}/add_config_group/${project_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async addConfig(config_group_id, content) { const url = `${this.base}/add_config/${config_group_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async updateConfigGroup(config_group_id, content) { const url = `${this.base}/update_config_group/${config_group_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async updateConfig(config_id, content) { const url = `${this.base}/update_config/${config_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async deleteConfigGroup(config_group_id) { const url = `${this.base}/delete_config_group/${config_group_id}`; await routed_1.route(url, this.headers(), "POST"); } ; async deleteConfig(config_id) { const url = `${this.base}/delete_config/${config_id}`; await routed_1.route(url, this.headers(), "POST"); } ; // ----- Milestones ----- async getMilestone(milestone_id) { const url = `${this.base}/get_milestone/${milestone_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getMilestones(project_id, filters) { const queryParams = this.queryCaseFilters(filters); const url = `${this.base}/get_milestones/${project_id}${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async addMilestone(project_id, content) { const url = `${this.base}/add_milestone/${project_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async updateMilestone(milestone_id, content) { const url = `${this.base}/update_milestone/${milestone_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async deleteMilestone(milestone_id) { const url = `${this.base}/delete_milestone/${milestone_id}`; await routed_1.route(url, this.headers(), "POST"); } ; // ----- Plans ----- async getPlan(plan_id) { const url = `${this.base}/get_plan/${plan_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getPlans(project_id, filters) { const queryParams = this.queryCaseFilters(filters); const url = `${this.base}/get_plans/${project_id}${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async addPlan(project_id, content) { const url = `${this.base}/add_plan/${project_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async addPlanEntry(plan_id, content) { const url = `${this.base}/add_plan_entry/${plan_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async updatePlan(plan_id, content) { const url = `${this.base}/update_plan/${plan_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async updatePlanEntry(plan_id, entry_id, content) { const url = `${this.base}/update_plan_entry/${plan_id}/${entry_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async closePlan(plan_id) { const url = `${this.base}/close_plan/${plan_id}`; await routed_1.route(url, this.headers(), "POST"); } ; async deletePlan(plan_id) { const url = `${this.base}/delete_plan/${plan_id}`; await routed_1.route(url, this.headers(), "POST"); } ; async deletePlanEntry(plan_id, entry_id) { const url = `${this.base}/delete_plan_entry/${plan_id}/${entry_id}`; await routed_1.route(url, this.headers(), "POST"); } ; // ----- Priorities ----- async getPriorities() { const url = `${this.base}/get_priorities`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; // ----- Projects ----- async getProject(project_id) { const url = `${this.base}/get_project/${project_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getProjects(filters) { const queryParams = this.queryCaseFilters(filters); const url = `${this.base}/get_projects${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async addProject(content) { const url = `${this.base}/add_project`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async updateProject(project_id, content) { const url = `${this.base}/update_project/${project_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async deleteProject(project_id) { const url = `${this.base}/delete_project/${project_id}`; await routed_1.route(url, this.headers(), "POST"); } ; // ----- Results ----- async getResults(test_id, filters) { const queryParams = this.queryCaseFilters(filters); const url = `${this.base}/get_results/${test_id}${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getResultsForCase(run_id, case_id, filters) { const queryParams = this.queryCaseFilters(filters); const url = `${this.base}/get_results_for_case/${run_id}/${case_id}${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getResultsForRun(run_id, filters) { const queryParams = this.queryCaseFilters(filters); const url = `${this.base}/get_results_for_run/${run_id}${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async addResult(test_id, content) { const url = `${this.base}/add_result/${test_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async addResults(run_id, content) { const url = `${this.base}/add_results/${run_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; // ----- Result Fields ----- async getResultFields() { const url = `${this.base}/get_result_fields`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; // ----- Sections ----- async getSection(section_id) { const url = `${this.base}/get_section/${section_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getSections(project_id, filters) { const queryParams = this.queryCaseFilters(filters); const url = `${this.base}/get_sections/${project_id}${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async addSection(project_id, content) { const url = `${this.base}/add_section/${project_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async updateSection(section_id, content) { const url = `${this.base}/update_section/${section_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async deleteSection(section_id) { const url = `${this.base}/delete_section/${section_id}`; const response = await routed_1.route(url, this.headers(), "POST"); return JSON.parse(response.body); } ; // ----- Statuses ----- async getStatuses() { const url = `${this.base}/get_statuses`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; // ----- Suites ----- async getSuite(suite_id) { const url = `${this.base}/get_suite/${suite_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getSuites(project_id) { const url = `${this.base}/get_suites/${project_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async addSuite(project_id, content) { const url = `${this.base}/add_suite/${project_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async updateSuite(suite_id, content) { const url = `${this.base}/update_suite/${suite_id}`; const response = await routed_1.route(url, this.headers(), "POST", JSON.stringify(content)); return JSON.parse(response.body); } ; async deleteSuite(suite_id) { const url = `${this.base}/delete_suite/${suite_id}`; const response = await routed_1.route(url, this.headers(), "POST"); return JSON.parse(response.body); } ; // ----- Templates ----- async getTemplates(project_id) { const url = `${this.base}/get_templates/${project_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; // ----- Tests ----- async getTest(test_id) { const url = `${this.base}/get_test/${test_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getTests(run_id, filters) { const queryParams = this.queryCaseFilters(filters); const url = `${this.base}/get_tests/${run_id}${queryParams}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; // ----- Users ----- async getUser(user_id) { const url = `${this.base}/get_user/${user_id}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getUserByEmail(email) { const url = `${this.base}/get_user_by_email&email=${email}`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; async getUsers() { const url = `${this.base}/get_users`; const response = await routed_1.route(url, this.headers()); return JSON.parse(response.body); } ; } exports.TestRailClient = TestRailClient; //# sourceMappingURL=testrail.js.map