Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
77 lines (69 loc) · 1.86 KB
/
Copy pathtest.js
File metadata and controls
77 lines (69 loc) · 1.86 KB
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 { createHmac } from "node:crypto";
import { suite } from "uvu";
import * as assert from "uvu/assert";
import nock from "nock";
import {
createCloudFunction,
Probot,
ProbotOctokit,
} from "@probot/adapter-google-cloud-functions";
import app from "./app.js";
nock.disableNetConnect();
const test = suite("app");
test("comments on a signed issues.opened webhook", async () => {
const secret = "test-webhook-secret";
const probot = new Probot({
// simple authentication as alternative to appId/privateKey
githubToken: "test",
secret,
// disable logs
logLevel: "warn",
// disable request throttling and retries
Octokit: ProbotOctokit.defaults({
throttle: { enabled: false },
retry: { enabled: false },
}),
});
const handler = createCloudFunction(app, { probot });
const mock = nock("https://api.github.com")
.post(
"/repos/probot/example-google-cloud-function/issues/1/comments",
(requestBody) => {
assert.equal(requestBody, { body: "Hello, World!" });
return true;
}
)
.reply(201, {});
const rawBody = Buffer.from(JSON.stringify({
action: "opened",
repository: {
owner: {
login: "probot",
},
name: "example-google-cloud-function",
},
issue: {
number: 1,
},
}));
const signature = createHmac("sha256", secret).update(rawBody).digest("hex");
const headers = new Map([
["x-github-delivery", "1"],
["x-github-event", "issues"],
["x-hub-signature-256", `sha256=${signature}`],
]);
let response;
await handler(
{ rawBody, get: (name) => headers.get(name) },
{
status: (status) => ({
send: (body) => {
response = { status, body };
},
}),
}
);
assert.equal(response, { status: 200, body: { ok: true } });
assert.equal(mock.activeMocks(), []);
});
test.run();