Skip to content

Commit

Permalink
Allow to create comments for collections with x level of folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rbenhaddou committed Nov 1, 2023
1 parent 070b2a5 commit ec8f5ae
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 23 deletions.
39 changes: 18 additions & 21 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,30 @@ const buildFailureComment = (commentParam, failures) => {
};


Check failure on line 88 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

More than 1 blank line not allowed
const evaluateCollection = (items) => {
if (items[0].subItems === undefined) { // in the case that there is only one folder
const requestsFailed = items.filter((request) => request.test_status === 'FAIL');
const requestsPassCount = items.filter((request) => request.test_status === 'PASS').length;
const requestsSkippedCount = items.filter((request) => request.test_status === 'SKIP').length;
return { requestsFailed, requestsSkippedCount, requestsPassCount };
} if (isLeafLevel(items[0].subItems)) { // in the case that there are multiple folders
let requestsSkippedCount = 0; let
requestsPassCount = 0;
const requestsFailed = [];

items.forEach((leaf) => {
leaf.subItems.filter((request) => request.test_status === 'FAIL')
.forEach((request) => requestsFailed.push(request));
requestsPassCount += leaf.subItems.filter((request) => request.test_status === 'PASS').length;
requestsSkippedCount += leaf.subItems.filter((request) => request.test_status === 'SKIP').length;
});
const evaluateCollection = (result, items) => {

Check failure on line 89 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

Block must not be padded by blank lines

if (isLeafLevel(items)) { // folder with requests
result.requestsFailed.push(...items.filter((request) => request.test_status === 'FAIL'))

Check failure on line 92 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

Missing semicolon
result.requestsPassCount += items.filter((request) => request.test_status === 'PASS').length;

Check failure on line 93 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

Assignment to property of function parameter 'result'
result.requestsSkippedCount += items.filter((request) => request.test_status === 'SKIP').length;

Check failure on line 94 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

Assignment to property of function parameter 'result'

Check failure on line 94 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

Block must not be padded by blank lines

return { requestsFailed, requestsSkippedCount, requestsPassCount };
} else if (isParentLevel(items)) { // folder of folders
items.forEach((folder) => {
evaluateCollection(result, folder.subItems)

Check failure on line 98 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

Missing semicolon
})

Check failure on line 99 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

Missing semicolon
}
return result;
}

Check failure on line 102 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

Missing semicolon

return items.forEach((item) => evaluateCollection(item));
};

Check failure on line 104 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Build and Test

More than 1 blank line not allowed
const buildPullRequestComment = (report, options, issueNumber, checkRunId) => {
const { items } = report;
const { requestsFailed, requestsSkippedCount, requestsPassCount } = evaluateCollection(items);
const initialValue = {
requestsFailed : [],
requestsSkippedCount : 0,
requestsPassCount : 0
};
const { requestsFailed, requestsSkippedCount, requestsPassCount } = evaluateCollection(initialValue, items);
const totalRequests = requestsFailed.length + requestsSkippedCount + requestsPassCount;

const comment = `Please find the complete report [here](${buildCheckPageUrl(options, issueNumber, checkRunId)})
Expand Down
89 changes: 87 additions & 2 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,93 @@ describe("Utils : buildPullRequestComment", () => {
];

const report = {assertions, items}
const issueNumber = 3;
const checkRunId = "1121312312";
const issueNumber = 3;
const checkRunId = "1121312312";
const result = buildPullRequestComment(report, githubService.options, issueNumber, checkRunId);


expect(result).to.equal(expectedResult);
})

it("Given a collection with depth = 2 that has a passing and failing test return the correct comment", () => {
const expectedResult = 'You have some failing tests \n Please find the complete report [here](https://github.com/organization/repo/pull/3/checks?check_run_id=1121312312) \n ✅ 2 / 4 **Requests Passed** \n ❌ 2 / 4 **Requests Failed**\n ⏩ 0 / 4 **Requests Skipped** \n **The following tests are failing:** \n\n [+] Show one place\n - Status code is 200 , AssertionError , expected response to have status code 200 but got 404 \n\n [+] Show one place\n - Status code is 200 , AssertionError , expected response to have status code 200 but got 404 \n'
const assertions = {
failed_count: 2,
skipped_count: 0,
};
const items = [
{
name: "depthOneFolderOne",
subItems: [
{
name: "depthOneFolderOne-A",
subItems: [
{
request_name: 'Get all ice hockey sport places within 99km around McGill University in Montréal, Canada',
url: 'https://sportplaces.api.decathlon.com/api/v1/places?origin=-73.582,45.511&radius=99&sports=175',
method: 'GET',
status: 'OK',
code: 200,
test_status: 'PASS',
failed: [],
skipped: []
}
]
},
{
name: "depthOneFolderOne-B",
subItems: [
{
request_name: 'Show one place',
url: 'https://sportplaces.api.decathlon.com/api/v1/places/8b1e3027-e438-42c2-92ab-5ebd23f68d54',
method: 'GET',
status: 'Not Found',
body: `{ "error": "Not found" }`,
code: 404,
test_status: 'FAIL',
failed: ["Status code is 200 , AssertionError , expected response to have status code 200 but got 404"],
skipped: []
}]
}]
},
{
name: "depthOneFolderTwo",
subItems: [
{
name: "depthOneFolderTwo-A",
subItems: [
{
request_name: 'Show one place',
url: 'https://sportplaces.api.decathlon.com/api/v1/places/8b1e3027-e438-42c2-92ab-5ebd23f68d54',
method: 'GET',
status: 'Not Found',
body: `{ "error": "Not found" }`,
code: 404,
test_status: 'FAIL',
failed: ["Status code is 200 , AssertionError , expected response to have status code 200 but got 404"],
skipped: []
}]
},
{
name: "depthOneFolderTwo-B",
subItems: [
{
request_name: 'Get all ice hockey sport places within 99km around McGill University in Montréal, Canada',
url: 'https://sportplaces.api.decathlon.com/api/v1/places?origin=-73.582,45.511&radius=99&sports=175',
method: 'GET',
status: 'OK',
code: 200,
test_status: 'PASS',
failed: [],
skipped: []
}]
}]
}
];

const report = {assertions, items}
const issueNumber = 3;
const checkRunId = "1121312312";
const result = buildPullRequestComment(report, githubService.options, issueNumber, checkRunId);


Expand Down

0 comments on commit ec8f5ae

Please sign in to comment.