/
_bamboo.test.ts
82 lines (70 loc) · 2.49 KB
/
_bamboo.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
import { Bamboo } from "../Bamboo"
import { getCISourceForEnv } from "../../get_ci_source"
const correctEnv = {
bamboo_buildPlanName: "My Build Plan",
bamboo_repository_pr_key: "1234",
bamboo_planRepository_repositoryUrl: "ssh://git@bitbucket.mycompany.com:7999/my_project/my_repository.git",
}
const correctDotedRepoEnv = {
bamboo_buildPlanName: "My Build Plan",
bamboo_repository_pr_key: "1234",
bamboo_planRepository_repositoryUrl: "ssh://git@bitbucket.mycompany.com:7999/my_project/my.custom.repository.git",
}
describe("being found when looking for CI", () => {
it("finds Bamboo with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
expect(ci).toBeInstanceOf(Bamboo)
})
})
describe(".isCI", () => {
it("validates when all Bamboo environment vars are set", () => {
const pipelines = new Bamboo(correctEnv)
expect(pipelines.isCI).toBeTruthy()
})
it("does not validate without josh", () => {
const pipelines = new Bamboo({})
expect(pipelines.isCI).toBeFalsy()
})
})
describe(".isPR", () => {
it("validates when all Bamboo environment vars are set", () => {
const pipelines = new Bamboo(correctEnv)
expect(pipelines.isPR).toBeTruthy()
})
it("does not validate outside of Bamboo", () => {
const pipelines = new Bamboo({})
expect(pipelines.isPR).toBeFalsy()
})
Object.keys(correctEnv).forEach((key: string) => {
let env = Object.assign({}, correctEnv)
env[key] = null
it(`does not validate when ${key} is missing`, () => {
const pipelines = new Bamboo(env)
expect(pipelines.isPR).toBeFalsy()
})
it("needs to have a PR number", () => {
let env = Object.assign({}, correctEnv)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete env["bamboo_repository_pr_key"]
const pipelines = new Bamboo(env)
expect(pipelines.isPR).toBeFalsy()
})
})
})
describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const pipelines = new Bamboo({ bamboo_repository_pr_key: "800" })
expect(pipelines.pullRequestID).toEqual("800")
})
})
describe(".repoSlug", () => {
it("derives it from the PR Url", () => {
const pipelines = new Bamboo(correctEnv)
expect(pipelines.repoSlug).toEqual("projects/my_project/repos/my_repository")
})
it("derives it from the PR doted Url", () => {
const pipelines = new Bamboo(correctDotedRepoEnv)
expect(pipelines.repoSlug).toEqual("projects/my_project/repos/my.custom.repository")
})
})