-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsingle-query.test.ts
55 lines (51 loc) · 1.39 KB
/
single-query.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
import { Configuration, generateRandomQuery } from '../src'
import * as fs from 'fs'
import { buildSchema, validate, print } from 'graphql'
const schemaDefGitHub = fs
.readFileSync('./test/fixtures/github.graphql')
.toString()
const schemaGitHub = buildSchema(schemaDefGitHub)
test(`Generate single random query`, () => {
const config: Configuration = {
breadthProbability: (nesting) => {
if (nesting === 0) {
return 0.5
} else {
return 1 / Math.pow(2, nesting)
}
},
depthProbability: (nesting) => {
if (nesting === 0) {
return 0.5
} else {
return 1 / Math.pow(2, nesting)
}
},
maxDepth: 10,
ignoreOptionalArguments: true,
argumentsToConsider: ['first'],
providerMap: {
'*__*__*': (existingVars, argType) => {
if (argType.name === 'String') {
return 'test'
} else if (argType.name === 'Int') {
return 1
} else if (argType.name === 'Float') {
return 1.0
} else if (argType.name === 'Boolean') {
return true
}
}
},
considerInterfaces: false,
considerUnions: true,
pickNestedQueryField: true,
seed: 0.9366856322996101
}
const { queryDocument, variableValues } = generateRandomQuery(
schemaGitHub,
config
)
const errors = validate(schemaGitHub, queryDocument)
expect(errors).toEqual([])
})