-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
62 lines (51 loc) · 1.56 KB
/
test.js
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
import test from "ava";
import fetchMock from "fetch-mock";
import { request } from "@octokit-next/request";
import { Octokit } from "@octokit-next/core";
test("octokit.request is a function", (t) => {
const octokit = new Octokit();
t.deepEqual(typeof octokit.request, "function");
});
test("myOctokit.request is a function", (t) => {
const MyOctokit = Octokit.withDefaults({}).withPlugins([() => {}]);
const myOctokit = new MyOctokit();
t.deepEqual(typeof myOctokit.request, "function");
});
test("octokit.request('GET /')", async (t) => {
const mock = fetchMock.sandbox().get("https://api.github.com", { ok: true });
const octokit = new Octokit({
request: {
fetch: mock,
},
});
const response = await octokit.request("GET /");
t.deepEqual(response.status, 200);
t.deepEqual(response.data, { ok: true });
});
test("octokit.request('GET /unknown')", async (t) => {
const mock = fetchMock
.sandbox()
.get("https://api.github.com/unknown", { status: 404 });
const octokit = new Octokit({
request: {
fetch: mock,
},
});
try {
await octokit.request("GET /unknown");
throw new Error("GET /unknown should fail");
} catch (error) {
if (!error.response) throw error;
t.deepEqual(error.response.status, 404);
}
});
test("request('GET /')", async (t) => {
const mock = fetchMock.sandbox().get("https://api.github.com/", { ok: true });
const response = await request("GET /", {
request: {
fetch: mock,
},
});
t.deepEqual(response.status, 200);
t.deepEqual(response.data, { ok: true });
});