-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathgithub-branch-get.test.ts
78 lines (61 loc) · 1.81 KB
/
github-branch-get.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
import { getLogger } from "config/logger";
import { GithubBranchGet } from "routes/github/branch/github-branch-get";
import { mocked } from "jest-mock";
import { Subscription } from "models/subscription";
jest.mock("models/subscription");
describe("GitHub Branches Get", () => {
let req, res;
const gitHubInstallationId = 15;
beforeEach(async () => {
await Subscription.create({
gitHubInstallationId,
jiraHost
});
req = {
log: getLogger("request"),
params: {
owner: "ARC",
repo: "repo-1",
ref: "branch-01"
}
};
res = {
sendStatus: jest.fn(),
send: jest.fn(),
status: jest.fn(),
json: jest.fn(),
locals: {
jiraHost,
githubToken: "abc-token",
gitHubAppConfig: {}
}
};
});
it("Should successfully fetch branch", async () => {
githubNock
.post(`/app/installations/${gitHubInstallationId}/access_tokens`)
.reply(200);
githubNock
.get("/repos/ARC/repo-1/git/refs/heads/branch-01")
.reply(200, {});
mocked(Subscription.findForRepoNameAndOwner).mockResolvedValue({ gitHubInstallationId, id: 1 } as Subscription);
await GithubBranchGet(req, res);
expect(res.sendStatus).toHaveBeenCalledWith(200);
});
it("Should return 404 when no branch found", async () => {
githubNock
.post(`/app/installations/${gitHubInstallationId}/access_tokens`)
.reply(200);
githubNock
.get("/repos/ARC/repo-1/git/refs/heads/branch-01")
.reply(404, {});
mocked(Subscription.findForRepoNameAndOwner).mockResolvedValue({ gitHubInstallationId, id: 1 } as Subscription);
await GithubBranchGet(req, res);
expect(res.sendStatus).toHaveBeenCalledWith(404);
});
it("Should 401 without gitHubAppConfig attributes", async () => {
delete res.locals.gitHubAppConfig;
await GithubBranchGet(req, res);
expect(res.sendStatus).toHaveBeenCalledWith(401);
});
});