-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathmain.test.mts
More file actions
71 lines (62 loc) · 1.76 KB
/
main.test.mts
File metadata and controls
71 lines (62 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import util from "node:util"
test("create-pull-request", async () => {
const mockPool = githubMockPool()
const token = "fake-token"
const base = "base-branch"
const head = "head-branch"
const prTitle = "Some PR title"
const prBody = "Some PR body.\nWith multiple lines."
const labels = "label1,label2"
const reviewers = "reviewer1,reviewer2"
const prNumber = 12345
mockInput("token", token)
mockInput("repository", GITHUB_REPOSITORY)
mockInput("base", base)
mockInput("head", head)
mockInput("title", prTitle)
mockInput("body", prBody)
mockInput("labels", labels)
mockInput("reviewers", reviewers)
mockPool.intercept({
method: "POST",
path: `/repos/${GITHUB_REPOSITORY}/pulls`,
headers: {
Authorization: `token ${token}`,
},
body: (body) => util.isDeepStrictEqual(JSON.parse(body), {
base,
head,
title: prTitle,
body: prBody
}),
}).defaultReplyHeaders({
"Content-Type": "application/json",
}).reply(200, {
number: prNumber
})
mockPool.intercept({
method: "POST",
path: `/repos/${GITHUB_REPOSITORY}/issues/${prNumber}/labels`,
headers: {
Authorization: `token ${token}`,
},
body: (body) => util.isDeepStrictEqual(JSON.parse(body), {
labels: labels.split(",")
}),
}).defaultReplyHeaders({
"Content-Type": "application/json",
}).reply(200, {})
mockPool.intercept({
method: "POST",
path: `/repos/${GITHUB_REPOSITORY}/pulls/${prNumber}/requested_reviewers`,
headers: {
Authorization: `token ${token}`,
},
body: (body) => util.isDeepStrictEqual(JSON.parse(body), {
reviewers: reviewers.split(",")
}),
}).defaultReplyHeaders({
"Content-Type": "application/json",
}).reply(200, {})
await loadMain()
})