-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtypescript.test.ts
68 lines (59 loc) · 1.75 KB
/
typescript.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
import { describe, it, expect } from "vitest";
import { Octokit } from "@octokit/core";
import {
type RestEndpointMethodTypes,
restEndpointMethods,
} from "../src/index.ts";
describe("Smoke test", () => {
it("Get parameters type for octokit.rest.issues.updateLabel()", async () => {
const options = {
owner: "octocat",
repo: "hello-world",
name: "bug",
color: "cc0000",
};
return updateLabel(options);
async function updateLabel(
_: RestEndpointMethodTypes["issues"]["updateLabel"]["parameters"],
): Promise<RestEndpointMethodTypes["issues"]["updateLabel"]["response"]> {
return {
headers: {},
data: {
id: 123,
node_id: "123",
color: "cc0000",
default: false,
description: "",
name: "bug",
url: "",
},
status: 200,
url: "",
};
}
});
it("Should accept .endpoint(options) without options.url being set", async () => {
const MyOctokit = Octokit.plugin(restEndpointMethods);
const octokit = new MyOctokit();
const requestOptions = octokit.rest.repos.getContent.endpoint({
owner: "foo",
repo: "bar",
path: "path/to/binary/file",
mediaType: {
format: "raw",
},
});
expect(requestOptions.method).toEqual("GET");
expect(requestOptions.url).toEqual(
"https://api.github.com/repos/foo/bar/contents/path%2Fto%2Fbinary%2Ffile",
);
});
it(".defaults()", async () => {
const MyOctokit = Octokit.plugin(restEndpointMethods);
const octokit = new MyOctokit();
const myRequest = octokit.rest.repos.getContent.defaults({
method: "HEAD",
});
expect(myRequest.endpoint.DEFAULTS.method).toEqual("HEAD");
});
});