/
_buddyWorks.test.ts
84 lines (72 loc) · 2.5 KB
/
_buddyWorks.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
import { BuddyWorks } from "../BuddyWorks"
import { getCISourceForEnv } from "../../get_ci_source"
const correctEnv = {
BUDDY_PIPELINE_ID: "170873",
BUDDY_EXECUTION_PULL_REQUEST_NO: "1799",
BUDDY_REPO_SLUG: "danger/dangerjs",
BUDDY_EXECUTION_URL:
"https://app.buddy.works/danger/dangerjs/pipelines/pipeline/170873/execution/5d6d49dbaab2cb6fdf975c71",
}
describe("being found when looking for CI", () => {
it("finds Buddy.works with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
expect(ci).toBeInstanceOf(BuddyWorks)
})
})
describe(".isCI", () => {
test("validates when all Buddy.works environment vars are set", () => {
const buddyWorks = new BuddyWorks(correctEnv)
expect(buddyWorks.isCI).toBeTruthy()
})
test("does not validate without pipeline ID", () => {
const buddyWorks = new BuddyWorks({})
expect(buddyWorks.isCI).toBeFalsy()
})
})
describe(".isPR", () => {
test("validates when all Buddy.works environment vars are set", () => {
const buddyWorks = new BuddyWorks(correctEnv)
expect(buddyWorks.isPR).toBeTruthy()
})
test("does not validate without pipeline ID", () => {
const buddyWorks = new BuddyWorks({})
expect(buddyWorks.isPR).toBeFalsy()
})
const envs = ["BUDDY_EXECUTION_PULL_REQUEST_NO", "BUDDY_REPO_SLUG"]
envs.forEach((key: string) => {
const env = Object.assign({}, correctEnv)
env[key] = null
test(`does not validate when ${key} is missing`, () => {
const buddyWorks = new BuddyWorks(env)
expect(buddyWorks.isPR).toBeFalsy()
})
})
it("needs to have a PR number", () => {
const env = Object.assign({}, correctEnv)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete env.BUDDY_EXECUTION_PULL_REQUEST_NO
const buddyWorks = new BuddyWorks(env)
expect(buddyWorks.isPR).toBeFalsy()
})
})
describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const buddyWorks = new BuddyWorks(correctEnv)
expect(buddyWorks.pullRequestID).toEqual("1799")
})
})
describe(".repoSlug", () => {
it("pulls it out of the env", () => {
const buddyWorks = new BuddyWorks(correctEnv)
expect(buddyWorks.repoSlug).toEqual("danger/dangerjs")
})
})
describe(".ciRunURL", () => {
it("pulls it out of the env", () => {
const buddyWorks = new BuddyWorks(correctEnv)
expect(buddyWorks.ciRunURL).toEqual(
"https://app.buddy.works/danger/dangerjs/pipelines/pipeline/170873/execution/5d6d49dbaab2cb6fdf975c71"
)
})
})