-
Notifications
You must be signed in to change notification settings - Fork 430
/
Copy pathindex.test.ts
74 lines (62 loc) · 1.97 KB
/
index.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
// You can import your modules
// import index from '../src/index'
import nock from "nock";
// Requiring our app implementation
import myProbotApp from "../src";
import { Probot, ProbotOctokit } from "probot";
// Requiring our fixtures
import payload from "./fixtures/issues.opened.json";
const issueCreatedBody = { body: "Thanks for opening this issue!" };
const fs = require("fs");
const path = require("path");
const privateKey = fs.readFileSync(
path.join(__dirname, "fixtures/mock-cert.pem"),
"utf-8"
);
describe("My Probot app", () => {
let probot: any;
beforeEach(() => {
nock.disableNetConnect();
probot = new Probot({
appId: 123,
privateKey,
// disable request throttling and retries for testing
Octokit: ProbotOctokit.defaults({
retry: { enabled: false },
throttle: { enabled: false },
}),
});
// Load our app into probot
probot.load(myProbotApp);
});
test("creates a comment when an issue is opened", async () => {
const mock = nock("https://api.github.com")
// Test that we correctly return a test token
.post("/app/installations/2/access_tokens")
.reply(200, {
token: "test",
permissions: {
issues: "write",
},
})
// Test that a comment is posted
.post("/repos/hiimbex/testing-things/issues/1/comments", (body: any) => {
expect(body).toMatchObject(issueCreatedBody);
return true;
})
.reply(200);
// Receive a webhook event
await probot.receive({ name: "issues", payload });
expect(mock.pendingMocks()).toStrictEqual([]);
});
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});
});
// For more information about testing with Jest see:
// https://facebook.github.io/jest/
// For more information about using TypeScript in your tests, Jest recommends:
// https://github.com/kulshekhar/ts-jest
// For more information about testing with Nock see:
// https://github.com/nock/nock