/
_github_utils.test.ts
52 lines (45 loc) · 1.77 KB
/
_github_utils.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
import utils from "../GitHubUtils"
import { readFileSync } from "fs"
import { resolve } from "path"
const fixtures = resolve(__dirname, "..", "..", "_tests", "fixtures")
const fixturedData = (path: string) => JSON.parse(readFileSync(`${fixtures}/${path}`, {}).toString())
const pr = fixturedData("github_pr.json")
const apiFake = {
repos: {
getContent: jest.fn(),
},
} as any
describe("fileLinks", () => {
it("Should convert a few paths into links", () => {
const sut = utils(pr, apiFake)
const links = sut.fileLinks(["a/b/c", "d/e/f"])
const url = "https://github.com/orta/emission/blob/genevc/a/b/c"
expect(links).toEqual(
`<a href="${url}">c</a> and <a href="https://github.com/orta/emission/blob/genevc/d/e/f">f</a>`
)
})
it("Should convert a few paths into links showing full links", () => {
const sut = utils(pr, apiFake)
const links = sut.fileLinks(["a/b/c", "d/e/f"], false)
const url = "https://github.com/orta/emission/blob/genevc"
expect(links).toEqual(`<a href="${url}/a/b/c">a/b/c</a> and <a href="${url}/d/e/f">d/e/f</a>`)
})
it("Should convert a few paths into links showing full link on a custom fork/branch", () => {
const sut = utils(pr, apiFake)
const links = sut.fileLinks(["a/b/c", "d/e/f"], false, "orta/emission", "new")
const url = "https://github.com/orta/emission"
expect(links).toEqual(`<a href="${url}/blob/new/a/b/c">a/b/c</a> and <a href="${url}/blob/new/d/e/f">d/e/f</a>`)
})
})
describe("getContent", () => {
it("should call the API's getContent", () => {
const sut = utils(pr, apiFake)
sut.fileContents("/a/b/c.ts")
expect(apiFake.repos.getContent).toHaveBeenCalledWith({
owner: "orta",
path: "/a/b/c.ts",
ref: "genevc",
repo: "emission",
})
})
})