-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayground.js
86 lines (79 loc) · 2.02 KB
/
playground.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
83
84
85
86
import {
addMockFunctionsToSchema,
makeExecutableSchema,
MockList
} from 'graphql-tools'
import { graphql } from 'graphql'
import faker from 'faker'
// Must use typeDefs not actual schema.
import typeDefs from '../api/schema/typeDefs'
// Create mocks for server.
const mocks = {
Todo: () => ({
completed: faker.random.boolean(),
id: faker.random.uuid(),
text: faker.lorem.text(),
createdAt: faker.date.past(),
updatedAt: faker.date.future()
}),
User: () => ({
id: faker.random.uuid(),
username: faker.internet.userName(),
email: faker.internet.email(),
createdAt: faker.date.past(),
updatedAt: faker.date.future(),
todos: () => new MockList(5)
})
}
const schema = makeExecutableSchema({ typeDefs })
addMockFunctionsToSchema({
schema,
mocks
})
describe('Queries', () => {
beforeEach(async () => {
const query1 = `
mutation register {
register(username: "turd_ferguson", email: "[email protected]", password: "123") {
id
username
email
}
}
`
const query2 = `
mutation register {
register(username: "Dr Acula", email: "[email protected]", password: "abc") {
id
username
email
}
}
`
const z = await Promise.all([
graphql(schema, query1),
graphql(schema, query2)
])
console.log(z[0].data.register)
return z
})
test.only('should find users', async () => {
const query = `
query findAllUsers {
findAllUsers {
id
username
}
}
`
const { data: { findAllUsers } } = await graphql(schema, query)
console.log(findAllUsers)
expect.assertions(3)
expect(findAllUsers).toHaveLength(2)
expect(findAllUsers[0]).toHaveProperty('id')
expect(findAllUsers[0]).toHaveProperty('username')
})
test('should find User by Id', async () => {})
test('should find Todos belonging to User', async () => {})
test('should find current logged in User', async () => {})
})