-
-
Notifications
You must be signed in to change notification settings - Fork 364
/
_github.test.ts
112 lines (90 loc) · 3.32 KB
/
_github.test.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { resolve } from "path"
import { readFileSync } from "fs"
const fixtures = resolve(__dirname, "fixtures")
/** Returns JSON from the fixtured dir */
// eslint-disable-next-line jest/no-export
export const requestWithFixturedJSON =
async (path: string): Promise<() => Promise<any>> =>
() =>
Promise.resolve(JSON.parse(readFileSync(`${fixtures}/${path}`, {}).toString()))
class mockGitHubAPI {
async getPullRequestInfo() {
const fixtures = await requestWithFixturedJSON("github_pr.json")
return await fixtures()
}
async getIssue() {
const fixtures = await requestWithFixturedJSON("github_issue.json")
return await fixtures()
}
async getPullRequestCommits() {
const fixtures = await requestWithFixturedJSON("github_commits.json")
return await fixtures()
}
async getPullRequestInlineComments() {
const fixtures = await requestWithFixturedJSON("github_inline_comments.json")
return await fixtures()
}
async getReviews() {
const fixtures = await requestWithFixturedJSON("reviews.json")
return await fixtures()
}
async getReviewerRequests() {
const fixtures = await requestWithFixturedJSON("requested_reviewers.json")
return await fixtures()
}
getExternalAPI() {
return {}
}
APIMetadataForPR() {
return {}
}
}
// Mock GitHubAPI class
jest.mock("../github/GitHubAPI", () => {
return { GitHubAPI: mockGitHubAPI }
})
import { GitHub, GitHubType } from "../GitHub"
import { GitHubAPI } from "../github/GitHubAPI"
import { RepoMetaData } from "../../dsl/RepoMetaData"
describe("getPlatformReviewDSLRepresentation", () => {
let github: GitHubType
beforeEach(() => {
github = GitHub(new GitHubAPI({} as RepoMetaData))
})
it("should return the correct review title from getReviewInfo", async () => {
const info = await github.getReviewInfo()
expect(info.title).toEqual("Adds support for showing the metadata and trending Artists to a Gene VC")
})
it("should get the commits of the pull request", async () => {
const expected = "https://api.github.com/repos/artsy/emission/git/commits/13da2c844def1f4262ee440bd86fb2a3b021718b"
const { commits } = await github.getPlatformReviewDSLRepresentation()
expect(commits[0].commit.url).toEqual(expected)
})
it("should get the reviews", async () => {
const { reviews } = await github.getPlatformReviewDSLRepresentation()
expect(reviews[0].id).toEqual(2332973)
})
it("should get the reviewer requests", async () => {
const { requested_reviewers } = await github.getPlatformReviewDSLRepresentation()
expect(requested_reviewers[0].id).toEqual(12397828)
})
it("should get the pull request information", async () => {
const { pr } = await github.getPlatformReviewDSLRepresentation()
expect(pr.number).toEqual(327)
})
it("should get the inline comments for this PR", async () => {
const comments = await github.getInlineComments("danger-id")
expect(comments[0].id).toEqual(81345954)
expect(comments[0].body).toEqual("needed to update the schema for description\n")
expect(comments.length).toEqual(6)
})
it("should set thisPR correct", async () => {
const dsl = await github.getPlatformReviewDSLRepresentation()
expect(dsl.thisPR).toEqual({
pull_number: 327,
number: 327,
owner: "artsy",
repo: "emission",
})
})
})