-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-resolver.test.ts
46 lines (43 loc) · 988 Bytes
/
post-resolver.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
import nock from "nock";
import { gql } from "apollo-server";
import { createServer } from "../create-server";
import { print } from "graphql";
describe("PostResolver", () => {
it("returns all posts", async () => {
const postsQuery = gql`
query Posts {
posts {
id
userId
title
body
}
}
`;
nock("https://jsonplaceholder.typicode.com/posts")
.get("/")
.reply(200, [
{
userId: 1,
id: 1,
title: "Post title",
body: "Body\nof the\npost",
},
]);
const server = await createServer();
const response = await server.executeOperation({
query: print(postsQuery),
});
expect(response.errors).toBeUndefined();
expect(response.data).toEqual({
posts: [
{
id: "1",
userId: "1",
title: "Post title",
body: "Body\nof the\npost",
},
],
});
});
});