Skip to content

Commit

Permalink
fix: no rp results when running tests with run command (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Jan 15, 2024
1 parent 7f0cf35 commit 67f0527
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 233 deletions.
41 changes: 41 additions & 0 deletions helpers/restClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const axios = require('axios').default;

class RestClient {
constructor() {
this.axios = axios.create();
}

async makePostRequest (url, payload = {}, headers = {}) {
try {
return this.axios.post(url, payload, { headers });
} catch (e) {
throw new Error(e.message);
}
}

async makePutRequest (url, payload = {}, headers = {}) {
try {
return this.axios.put(url, payload, { headers });
} catch (e) {
throw new Error(e.message);
}
}

async makeGetRequest(url, headers = {}) {
try {
return this.axios.get(url, { headers });
} catch (e) {
throw new Error(e.message);
}
}

async makeDeleteRequest(url, headers = {}) {
try {
return this.axios.delete(url, { headers });
} catch (e) {
throw new Error(e.message);
}
}
}

module.exports = RestClient;
20 changes: 16 additions & 4 deletions helpers/rpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const {TEST_ITEM_TYPES} = require("../constants/testItemTypes");
const {STATUSES} = require("../constants/statuses");
const fs = require("fs");
const path = require("path");
const RestClient = require("./restClient");
const debug = require('debug')('codeceptjs:reportportal');
const axios = require('axios').default;
const restClient = axios.create();
const restClient = new RestClient();
const { output, event } = codeceptjs;
let rpClient;

Expand Down Expand Up @@ -45,7 +45,7 @@ async function finishLaunch(launchObj, launchStatus) {

async function getRPLink(config, launchId) {
try {
const res = await restClient.get(`${config.endpoint}/${config.projectName}/launch?page.page=1&page.size=50&page.sort=startTime%2Cnumber%2CDESC`, { headers: { Authorization: `Bearer ${config.token}`}});
const res = await restClient.makeGetRequest(`${config.endpoint}/${config.projectName}/launch?page.page=1&page.size=50&page.sort=startTime%2Cnumber%2CDESC`, { Authorization: `Bearer ${config.token}`});
const launch = res.data.content.filter(item => item.uuid === launchId);
return `${config.endpoint.split('api')[0]}ui/#${config.projectName}/launches/all/${launch[0].id}`;
} catch (e) {
Expand Down Expand Up @@ -81,14 +81,25 @@ async function startTestItem(launchId, testTitle, method, parentId = null, paren
}
}

async function finishTestItem(test) {
if (!test) return;

debug(`Finishing '${test.toString()}' Test`);

rpClient.finishTestItem(test.tempId, {
endTime: rpClient.helpers.now(),
status: rpStatus(test.status),
});
}

async function finishStepItem(step) {
if (!step) return;

debug(`Finishing '${step.toString()}' step`);

return rpClient.finishTestItem(step.tempId, {
endTime: rpClient.helpers.now(),
status: rpStatus(step.status),
status: rpStatus(step.status) || STATUSES.PASSED,
});
}

Expand Down Expand Up @@ -169,6 +180,7 @@ module.exports = {
getRPLink,
writePRInfo,
startTestItem,
finishTestItem,
finishStepItem,
logCurrent,
rpStatus,
Expand Down
Loading

0 comments on commit 67f0527

Please sign in to comment.