forked from adamlaska/core.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphql.test.ts
More file actions
52 lines (43 loc) · 1.19 KB
/
graphql.test.ts
File metadata and controls
52 lines (43 loc) · 1.19 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
import { getUserAgent } from "universal-user-agent";
import fetchMock from "fetch-mock";
import { Octokit } from "../src";
const userAgent = `octokit-core.js/0.0.0-development ${getUserAgent()}`;
describe("octokit.graphql()", () => {
it("is a function", () => {
const octokit = new Octokit();
expect(octokit.graphql).toBeInstanceOf(Function);
});
it("README usage example", async () => {
const mockResult = {
organization: {
repositories: {
totalCount: 123
}
}
};
const mock = fetchMock
.sandbox()
.postOnce("https://api.github.com/graphql", (url, request) => {
const body = JSON.parse(request.body!.toString());
expect(body.query).toEqual(query);
return {
data: mockResult
};
});
const octokit = new Octokit({
auth: `secret123`,
request: {
fetch: mock
}
});
const query = `query ($login: String!) {
organization(login: $login) {
repositories(privacy: PRIVATE) {
totalCount
}
}
}`;
const result = await octokit.graphql(query, { login: "octokit" });
expect(result).toStrictEqual(mockResult);
});
});