Skip to content

Commit ea77c5c

Browse files
fahrradfluchtaduh95
authored andcommitted
test(ncu-ci): checkCommitsAfterReviewOrLabel
1 parent 941a4aa commit ea77c5c

File tree

7 files changed

+154
-1
lines changed

7 files changed

+154
-1
lines changed

test/fixtures/data.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,12 @@ for (const subdir of readdirSync(path('./jenkins'))) {
134134
readJSON(`./jenkins/${subdir}/${item}`);
135135
}
136136
};
137+
138+
export const labeledEvents = {};
139+
140+
for (const item of readdirSync(path('./labeled_events'))) {
141+
if (!item.endsWith('.json')) {
142+
continue;
143+
}
144+
labeledEvents[basename(item, '.json')] = readJSON(`./labeled_events/${item}`);
145+
}

test/fixtures/first_timer_pr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
}
2323
]
2424
},
25+
"timelineItems": { "updatedAt": "2017-10-24T11:13:43Z" },
2526
"title": "test: awesome changes",
2627
"baseRefName": "main",
2728
"headRefName": "awesome-changes"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"actor": { "login": "nodejs-github-bot" },
4+
"label": { "name": "doc" },
5+
"createdAt": "2024-05-13T15:57:10Z"
6+
},
7+
{
8+
"actor": { "login": "nodejs-github-bot" },
9+
"label": { "name": "test_runner" },
10+
"createdAt": "2024-05-13T15:57:10Z"
11+
}
12+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"actor": { "login": "nodejs-github-bot" },
4+
"label": { "name": "doc" },
5+
"createdAt": "2024-05-13T15:57:10Z"
6+
},
7+
{
8+
"actor": { "login": "foo" },
9+
"label": { "name": "request-ci" },
10+
"createdAt": "1999-10-24T11:13:43Z"
11+
}
12+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"actor": { "login": "nodejs-github-bot" },
4+
"label": { "name": "doc" },
5+
"createdAt": "2024-05-13T15:57:10Z"
6+
},
7+
{
8+
"actor": { "login": "foo" },
9+
"label": { "name": "request-ci" },
10+
"createdAt": "2024-05-13T15:57:10Z"
11+
}
12+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"actor": { "login": "nodejs-github-bot" },
4+
"label": { "name": "doc" },
5+
"createdAt": "2024-05-13T15:57:10Z"
6+
},
7+
{
8+
"actor": { "login": "random-person" },
9+
"label": { "name": "request-ci" },
10+
"createdAt": "2024-05-13T15:57:10Z"
11+
}
12+
]

test/unit/pr_checker.test.js

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import {
4141
conflictingPR,
4242
closedPR,
4343
mergedPR,
44-
pullRequests
44+
pullRequests,
45+
labeledEvents
4546
} from '../fixtures/data.js';
4647

4748
jobCache.disable();
@@ -2048,6 +2049,100 @@ describe('PRChecker', () => {
20482049
});
20492050
});
20502051

2052+
describe('checkCommitsAfterReviewOrLabel', () => {
2053+
it('should return true if PR passes post review checks', async() => {
2054+
const cli = new TestCLI();
2055+
const checker = new PRChecker(cli, {
2056+
pr: semverMajorPR,
2057+
reviewers: allGreenReviewers,
2058+
comments: commentsWithLGTM,
2059+
reviews: approvingReviews,
2060+
commits: simpleCommits,
2061+
collaborators,
2062+
authorIsNew: () => true,
2063+
getThread: PRData.prototype.getThread
2064+
}, {}, argv);
2065+
2066+
const status = await checker.checkCommitsAfterReviewOrLabel();
2067+
assert.strictEqual(status, true);
2068+
});
2069+
2070+
describe('without approvals', () => {
2071+
const data = {
2072+
pr: firstTimerPR,
2073+
reviewers: noReviewers,
2074+
comments: [],
2075+
reviews: [],
2076+
commits: [],
2077+
collaborators: [],
2078+
labeledEvents: [],
2079+
authorIsNew: () => true,
2080+
getThread: PRData.prototype.getThread,
2081+
getLabeledEvents: async() => {
2082+
data.labeledEvents = [];
2083+
},
2084+
getCollaborators: async() => {
2085+
data.collaborators = collaborators;
2086+
}
2087+
};
2088+
2089+
it('should return false if PR has no labels', async() => {
2090+
const cli = new TestCLI();
2091+
data.getLabeledEvents = async() => {
2092+
data.labeledEvents = [];
2093+
};
2094+
const checker = new PRChecker(cli, data, {}, argv);
2095+
2096+
const status = await checker.checkCommitsAfterReviewOrLabel();
2097+
assert.strictEqual(status, false);
2098+
});
2099+
2100+
it('should return false if PR has no request-ci label', async() => {
2101+
const cli = new TestCLI();
2102+
data.getLabeledEvents = async() => {
2103+
data.labeledEvents = labeledEvents['no-request-ci'];
2104+
};
2105+
const checker = new PRChecker(cli, data, {}, argv);
2106+
2107+
const status = await checker.checkCommitsAfterReviewOrLabel();
2108+
assert.strictEqual(status, false);
2109+
});
2110+
2111+
it('should return false if PR has request-ci from non-collaborator', async() => {
2112+
const cli = new TestCLI();
2113+
data.getLabeledEvents = async() => {
2114+
data.labeledEvents = labeledEvents['recent-request-ci-non-collaborator'];
2115+
};
2116+
const checker = new PRChecker(cli, data, {}, argv);
2117+
2118+
const status = await checker.checkCommitsAfterReviewOrLabel();
2119+
assert.strictEqual(status, false);
2120+
});
2121+
2122+
it('should return false if PR has outdated request-ci from a collaborator', async() => {
2123+
const cli = new TestCLI();
2124+
data.getLabeledEvents = async() => {
2125+
data.labeledEvents = labeledEvents['old-request-ci-collaborator'];
2126+
};
2127+
const checker = new PRChecker(cli, data, {}, argv);
2128+
2129+
const status = await checker.checkCommitsAfterReviewOrLabel();
2130+
assert.strictEqual(status, false);
2131+
});
2132+
2133+
it('should return true if PR has recent request-ci from a collaborator', async() => {
2134+
const cli = new TestCLI();
2135+
data.getLabeledEvents = async() => {
2136+
data.labeledEvents = labeledEvents['recent-request-ci-collaborator'];
2137+
};
2138+
const checker = new PRChecker(cli, data, {}, argv);
2139+
2140+
const status = await checker.checkCommitsAfterReviewOrLabel();
2141+
assert.strictEqual(status, true);
2142+
});
2143+
});
2144+
});
2145+
20512146
describe('checkCommitsAfterReview', () => {
20522147
const cli = new TestCLI();
20532148

0 commit comments

Comments
 (0)