-
Notifications
You must be signed in to change notification settings - Fork 2k
/
getIntrospectionQuery-test.js
78 lines (62 loc) · 2.09 KB
/
getIntrospectionQuery-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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { expect } from 'chai';
import { describe, it } from 'mocha';
import type { IntrospectionOptions } from '../getIntrospectionQuery';
import { getIntrospectionQuery } from '../getIntrospectionQuery';
function expectIntrospectionQuery(options?: IntrospectionOptions) {
const query = getIntrospectionQuery(options);
return {
toMatch(pattern: RegExp, times: number = 1): void {
expect(query).to.match(pattern);
const gPattern = new RegExp(pattern, 'g');
expect(query.match(gPattern)).to.have.lengthOf(times);
},
toNotMatch(pattern: RegExp): void {
expect(query).to.not.match(pattern);
},
};
}
describe('getIntrospectionQuery', () => {
it('skip all "description" fields', () => {
expectIntrospectionQuery().toMatch(/\bdescription\b/, 5);
expectIntrospectionQuery({ descriptions: true }).toMatch(
/\bdescription\b/,
5,
);
expectIntrospectionQuery({ descriptions: false }).toNotMatch(
/\bdescription\b/,
);
});
it('include "isRepeatable" field on directives', () => {
expectIntrospectionQuery().toNotMatch(/\bisRepeatable\b/);
expectIntrospectionQuery({ directiveIsRepeatable: true }).toMatch(
/\bisRepeatable\b/,
);
expectIntrospectionQuery({ directiveIsRepeatable: false }).toNotMatch(
/\bisRepeatable\b/,
);
});
it('include "description" field on schema', () => {
expectIntrospectionQuery().toMatch(/\bdescription\b/, 5);
expectIntrospectionQuery({ schemaDescription: false }).toMatch(
/\bdescription\b/,
5,
);
expectIntrospectionQuery({ schemaDescription: true }).toMatch(
/\bdescription\b/,
6,
);
expectIntrospectionQuery({
descriptions: false,
schemaDescription: true,
}).toNotMatch(/\bdescription\b/);
});
it('include "specifiedByUrl" field', () => {
expectIntrospectionQuery().toNotMatch(/\bspecifiedByUrl\b/);
expectIntrospectionQuery({ specifiedByUrl: true }).toMatch(
/\bspecifiedByUrl\b/,
);
expectIntrospectionQuery({ specifiedByUrl: false }).toNotMatch(
/\bspecifiedByUrl\b/,
);
});
});