-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
57 lines (52 loc) · 1.34 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
const axios = require('axios')
axios.defaults.baseURL = 'http://localhost:8000'
test('basic', async () => {
expect((await axios.post('/graphql', { query: '{ helloPublic }' })).data).toEqual({
data: {
helloPublic: 'Hello public',
},
})
})
test('variable', async () => {
expect(
(await axios.post('/graphql', {
query: 'query($num: Int!) { helloVariable(someNumber: $num) }',
variables: { num: 3 },
})).data
).toEqual({
data: {
helloVariable: 'Your number was 3',
},
})
})
test('private', async () => {
expect(
(await axios.post('/graphql', { query: '{ helloPrivate }' }, { headers: { user: 'whatever' } }))
.data
).toEqual({
data: {
helloPrivate: 'Hello private',
},
})
expect(
(await axios.post('/graphql', { query: '{ helloPrivate }' })).data.errors[0].extensions.code
).toBe('UNAUTHENTICATED')
})
test('bad input', async () => {
expect(
(await axios.post('/graphql', {
query: 'query ($num: Int!) { helloBadInput(lessThanFive: $num) }',
variables: { num: 3 },
})).data
).toEqual({
data: {
helloBadInput: true,
},
})
expect(
(await axios.post('/graphql', {
query: 'query ($num: Int!) { helloBadInput(lessThanFive: $num) }',
variables: { num: 10 },
})).data.errors[0].extensions.code
).toBe('BAD_USER_INPUT')
})