-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
61 lines (50 loc) · 1.42 KB
/
index.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
// see https://hackernoon.com/extensive-graphql-testing-57e8760f1c25
import {
makeExecutableSchema,
addMockFunctionsToSchema,
mockServer
} from 'graphql-tools';
import { graphql } from 'graphql';
import booksSchema from './index';
const titleTestCase = {
id: 'Query Title',
query: `
query {
books {
title
}
}
`,
variables: {},
context: {},
expected: { data: { books: [{ title: 'Title'} , { title: 'Title' }] } }
};
const cases = [titleTestCase];
describe('Schema', () => {
const typeDefs = booksSchema;
const mockSchema = makeExecutableSchema({ typeDefs });
addMockFunctionsToSchema({
schema: mockSchema,
mocks: {
Boolean: () => false,
ID: () => '1',
Int: () => 1,
Float: () => 1.1,
String: () => 'Title',
}
});
test('Has valid type definitions', async () => {
expect(async () => {
const MockServer = mockServer(typeDefs);
await MockServer.query(`{ __schema { types { name } } }`);
}).not.toThrow();
});
cases.forEach(obj => {
const { id, query, variables, context: ctx, expected } = obj;
test(`Testing Query: ${id}`, async () => {
return await expect(
graphql(mockSchema, query, null, { ctx }, variables)
).resolves.toEqual(expected);
});
});
});