-
Notifications
You must be signed in to change notification settings - Fork 18
/
smoke.test.js
82 lines (69 loc) · 2.08 KB
/
smoke.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import axios from "axios";
import fixtures from "../..";
import { readFileSync } from "fs";
test("Accepts fixtures object as argument", async () => {
fixtures.mock(
JSON.parse(
readFileSync(
"./scenarios/api.github.com/get-repository/normalized-fixture.json"
)
)
);
const result = await axios({
method: "get",
url: "https://api.github.com/repos/octokit-fixture-org/hello-world",
headers: {
Accept: "application/vnd.github.v3+json",
Authorization: "token 0000000000000000000000000000000000000001",
},
});
expect(result.data.name).toBe("hello-world");
});
test("Missing Accept header", async () => {
fixtures.mock("api.github.com/get-repository");
try {
await axios({
method: "get",
url: "https://api.github.com/repos/octokit-fixture-org/hello-world",
});
throw new Error("request should fail");
} catch (error) {
expect(error.message).toMatch("No match for request");
}
});
test("Matches corret fixture based on authorization header", async () => {
fixtures.mock("api.github.com/get-root");
const result = await axios({
method: "get",
url: "https://api.github.com",
headers: {
Accept: "application/vnd.github.v3+json",
Authorization: "token 0000000000000000000000000000000000000001",
},
});
expect(result.headers["x-ratelimit-remaining"]).toBe("4999");
});
test("unmatched request error", async () => {
const mock = fixtures.mock("api.github.com/get-repository");
try {
await axios({
method: "get",
url: "https://api.github.com/unknown",
headers: {
Accept: "application/vnd.github.v3+json",
},
}).catch(mock.explain);
throw new Error("request should fail");
} catch (error) {
expect(error.message).toMatch('+ url: "https://api.github.com/unknown');
}
});
test("explain non-request error", async () => {
const mock = fixtures.mock("api.github.com/get-repository");
try {
mock.explain(new Error("foo"));
throw new Error("should throw error");
} catch (error) {
expect(error.message).toBe("foo");
}
});