This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
forked from danger/peril
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_danger_run.test.ts
96 lines (86 loc) · 2.89 KB
/
_danger_run.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
import {
dangerRepresentationforPath,
DangerRun,
dangerRunForRules,
dsl,
dslTypeForEvent,
feedback,
} from "../danger_run"
describe("for ping", () => {
it("returns an action when ping is in the rules", () => {
const rules = { ping: "dangerfile.js" }
expect(dangerRunForRules("ping", null, rules)).toEqual({
action: null,
dangerfilePath: "dangerfile.js",
dslType: dsl.import,
event: "ping",
feedback: feedback.silent,
})
})
it("returns nothing when ping is not in the rules", () => {
const rules = {}
expect(dangerRunForRules("ping", null, rules)).toBeNull()
})
})
describe("for PRs", () => {
it("returns a PR when PR is in the rules", () => {
const rules = { pull_request: "dangerfile.js" }
expect(dangerRunForRules("pull_request", "created", rules)).toEqual({
action: "created",
dangerfilePath: "dangerfile.js",
dslType: dsl.pr,
event: "pull_request",
feedback: feedback.commentable,
})
})
// Same semantics
it("returns a PR run when all sub events are globbed in the rules", () => {
const rules = { "pull_request.*": "dangerfile.js" }
expect(dangerRunForRules("pull_request", "updated", rules)).toEqual({
action: "updated",
dangerfilePath: "dangerfile.js",
dslType: dsl.pr,
event: "pull_request",
feedback: feedback.commentable,
})
})
it("returns null when you only ask for a specific action", () => {
const rules = { "pull_request.created": "dangerfile.js" }
expect(dangerRunForRules("pull_request", "updated", rules)).toBeNull()
})
it("returns a PR run when all sub events are globbed in the rules", () => {
const rules = { "pull_request.deleted": "dangerfile.js" }
expect(dangerRunForRules("pull_request", "deleted", rules)).toEqual({
action: "deleted",
dangerfilePath: "dangerfile.js",
dslType: dsl.pr,
event: "pull_request",
feedback: feedback.commentable,
})
})
})
describe("dangerRepresentationforPath", () => {
it("returns just the path when there is no repo reference", () => {
const path = "dangerfile.ts"
expect(dangerRepresentationforPath(path)).toEqual({
dangerfilePath: "dangerfile.ts",
})
})
it("returns just the path when there is no repo reference", () => {
const path = "orta/[email protected]"
expect(dangerRepresentationforPath(path)).toEqual({
dangerfilePath: "dangerfile.ts",
repoSlug: "orta/eigen",
})
})
})
describe("dslTypeForEvent", () => {
it("recommends importing the integration as the DSL for anything but a PR", () => {
expect(dslTypeForEvent("ping")).toEqual(dsl.import)
expect(dslTypeForEvent("issue")).toEqual(dsl.import)
expect(dslTypeForEvent("user")).toEqual(dsl.import)
})
it("recommends creating the Dangerfile DSL for a pull request", () => {
expect(dslTypeForEvent("pull_request")).toEqual(dsl.pr)
})
})