Skip to content

Commit 4a7f99f

Browse files
committed
WIP
1 parent 81a8fee commit 4a7f99f

File tree

4 files changed

+161
-13
lines changed

4 files changed

+161
-13
lines changed

package-lock.json

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Octokit } from "@octokit/core";
22
import { Deprecation } from "deprecation";
33

44
import ENDPOINTS from "./generated/endpoints";
5+
export { RestEndpointMethodTypes } from "./generated/method-types";
56
import { VERSION } from "./version";
67
import { Api } from "./types";
78
import { endpointsToMethods } from "./endpoints-to-methods";

test/rest-endpoint-methods.test.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,62 @@ describe("REST API endpoint methods", () => {
3232
});
3333

3434
it("Required preview header", async () => {
35-
const mock = fetchMock.sandbox().post(
36-
"path:/repos/octocat/hello-world/dispatches",
35+
const mock = fetchMock.sandbox().getOnce(
36+
"path:/app",
3737
{ ok: true },
3838
{
39-
body: {
40-
event_type: "greeting",
41-
client_payload: { name: "Mona" },
39+
headers: {
40+
accept: "application/vnd.github.machine-man-preview+json",
4241
},
4342
}
4443
);
4544

4645
const MyOctokit = Octokit.plugin(restEndpointMethods);
4746
const octokit = new MyOctokit({
48-
auth: "secret123",
4947
request: {
5048
fetch: mock,
5149
},
5250
});
5351

54-
// See https://developer.github.com/v3/repos/#create
55-
const { data } = await octokit.repos.createDispatchEvent({
56-
owner: "octocat",
57-
repo: "hello-world",
58-
event_type: "greeting",
59-
client_payload: { name: "Mona" },
60-
});
52+
// See https://developer.github.com/v3/repos/#create-a-repository-dispatch-event
53+
const { data } = await octokit.apps.getAuthenticated();
6154

6255
expect(data).toStrictEqual({ ok: true });
6356
});
6457

58+
it("octokit.markdown.renderRaw()", async () => {
59+
const mock = fetchMock.sandbox().postOnce(
60+
"path:/markdown/raw",
61+
{ ok: true },
62+
{
63+
headers: {
64+
"content-type": "text/plain; charset=utf-8",
65+
},
66+
matcher: (url, { body, headers }) => {
67+
expect(body).toEqual("# Hello, world!");
68+
return true;
69+
},
70+
}
71+
);
72+
73+
const MyOctokit = Octokit.plugin(restEndpointMethods);
74+
const octokit = new MyOctokit({
75+
request: {
76+
fetch: mock,
77+
},
78+
});
79+
80+
return octokit.markdown
81+
.renderRaw({
82+
data: "# Hello, world!",
83+
})
84+
.catch((error) => {
85+
console.log(error);
86+
87+
throw error;
88+
});
89+
});
90+
6591
it("octokit.repos.uploadReleaseAsset()", async () => {
6692
const mock = fetchMock.sandbox().postOnce(
6793
"https://uploads.github.com/repos/octocat/hello-world/releases/123/assets",

test/typescript.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { RestEndpointMethodTypes } from "../src";
2+
3+
describe("Smoke test", () => {
4+
it("Get parameters type for octokit.issues.updateLabel()", async () => {
5+
const options = {
6+
owner: "octocat",
7+
repo: "hello-world",
8+
name: "bug",
9+
color: "cc0000",
10+
};
11+
12+
return updateLabel(options);
13+
14+
async function updateLabel(
15+
options: RestEndpointMethodTypes["issues"]["updateLabel"]["parameters"]
16+
): Promise<RestEndpointMethodTypes["issues"]["updateLabel"]["response"]> {
17+
return {
18+
headers: {},
19+
data: {
20+
id: 123,
21+
node_id: "123",
22+
color: "cc0000",
23+
default: false,
24+
description: "",
25+
name: "bug",
26+
url: "",
27+
},
28+
status: 201,
29+
url: "",
30+
};
31+
}
32+
});
33+
});

0 commit comments

Comments
 (0)