Skip to content

Commit 90f3dd7

Browse files
committed
test: octokit.graphql()
1 parent e451d3a commit 90f3dd7

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

test/graphql.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,47 @@ import { Octokit } from "../src";
66
const userAgent = `octokit-core.js/0.0.0-development ${getUserAgent()}`;
77

88
describe("octokit.graphql()", () => {
9-
it.todo("is a function");
9+
it("is a function", () => {
10+
const octokit = new Octokit();
11+
expect(octokit.graphql).toBeInstanceOf(Function);
12+
});
13+
14+
it("README usage example", async () => {
15+
const mockResult = {
16+
organization: {
17+
repositories: {
18+
totalCount: 123
19+
}
20+
}
21+
};
22+
const mock = fetchMock
23+
.sandbox()
24+
.postOnce("https://api.github.com/graphql", (url, request) => {
25+
const body = JSON.parse(request.body!.toString());
26+
expect(body.query).toEqual(query);
27+
28+
return {
29+
data: mockResult
30+
};
31+
});
32+
33+
const octokit = new Octokit({
34+
auth: `secret123`,
35+
request: {
36+
fetch: mock
37+
}
38+
});
39+
40+
const query = `query ($login: String!) {
41+
organization(login: $login) {
42+
repositories(privacy: PRIVATE) {
43+
totalCount
44+
}
45+
}
46+
}`;
47+
48+
const result = await octokit.graphql(query, { login: "octokit" });
49+
50+
expect(result).toStrictEqual(mockResult);
51+
});
1052
});

0 commit comments

Comments
 (0)