/
gh.test.mjs
49 lines (42 loc) · 1.25 KB
/
gh.test.mjs
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
import * as github from "@actions/github";
import {
afterAll,
afterEach,
beforeEach,
describe,
expect,
test,
vi,
} from "vitest";
import * as gh from "../src/gh";
test("gh.pullRequestEvent() return undefined by default", () => {
expect(gh.pullRequestPayload()).toBeUndefined();
});
describe("Stub github.context w/ a pull_request payload", () => {
const context = {
eventName: "pull_request",
payload: {
pull_request: { number: 42 },
repository: { name: "test", owner: { login: "anonymous" } },
},
};
afterEach(() => vi.restoreAllMocks());
test("pull_request context is returned by gh.pullRequestEvent()", () => {
vi.spyOn(github, "context", "get").mockReturnValue(context);
expect(gh.pullRequestPayload()).toEqual(context.payload);
});
});
describe("Stub github.context w/ a 'push' payload", () => {
const context = {
eventName: "push",
payload: {
pull_request: { number: 42 },
repository: { name: "test", owner: { login: "anonymous" } },
},
};
afterEach(() => vi.restoreAllMocks());
test("'undefined' is returned by gh.pullRequestEvent()", () => {
vi.spyOn(github, "context", "get").mockReturnValue(context);
expect(gh.pullRequestPayload()).toBeUndefined();
});
});