/
integration.test.ts
89 lines (77 loc) · 2.22 KB
/
integration.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
jest.mock("lib/apis/fetch", () => jest.fn())
import fetch from "lib/apis/fetch"
const mockFetch = fetch as jest.Mock
describe("integration tests", () => {
// These tests ensure that *any* query works against our express app.
const request = require("supertest")
const app = require("../../index").default
const gql = require("lib/gql").default
beforeEach(() => {
mockFetch.mockClear()
mockFetch.mockReset()
})
it("should bail for an unknown GET request", async () => {
const response = await request(app).get("/")
expect(response.statusCode).toBe(400)
})
it("can make a request against the schema", async () => {
// Mock the fetch for the Artist loader
mockFetch.mockResolvedValueOnce(
Promise.resolve({ body: { name: "Mr Bank" } })
)
const response = await request(app)
.post("/")
.set("Accept", "application/json")
.send({
query: gql`
{
artist(id: "banksy") {
name
}
}
`,
})
expect(response.body.data).toEqual({ artist: { name: "Mr Bank" } })
expect(response.statusCode).toBe(200)
})
it("assigns x-xapp-token if present", async () => {
mockFetch.mockResolvedValueOnce(Promise.resolve({ body: {} }))
await request(app)
.post("/")
.set("Accept", "application/json")
.set("x-xapp-token", "xapp-token")
.send({
query: gql`
{
artist(id: "yayoi-kusama") {
name
}
}
`,
})
expect(mockFetch.mock.calls[0][1].headers["X-XAPP-TOKEN"]).toEqual(
"xapp-token"
)
})
it("doesn't include `extensions` by default", async () => {
// Mock the fetch for the Artist loader
mockFetch.mockResolvedValueOnce(
Promise.resolve({ body: { name: "Mr Bank" } })
)
const response = await request(app)
.post("/")
.set("Accept", "application/json")
.send({
query: gql`
{
artist(id: "banksy") {
name
}
}
`,
})
expect(response.body.data).toEqual({ artist: { name: "Mr Bank" } })
expect(response.statusCode).toBe(200)
expect(response.body.extensions).toBeFalsy()
})
})