Skip to content

Commit a974258

Browse files
committed
add test cases
1 parent 9787510 commit a974258

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

src/__tests__/QueryComplexity-test.ts

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,91 @@ describe('QueryComplexity analysis', () => {
4141
expect(complexity).to.equal(1);
4242
});
4343

44+
it('should respect @include(if: false)', () => {
45+
const ast = parse(`
46+
query {
47+
variableScalar(count: 10) @include(if: false)
48+
}
49+
`);
50+
51+
const complexity = getComplexity({
52+
estimators: [
53+
simpleEstimator({defaultComplexity: 1})
54+
],
55+
schema,
56+
query: ast
57+
});
58+
expect(complexity).to.equal(0);
59+
});
60+
61+
it('should respect @include(if: true)', () => {
62+
const ast = parse(`
63+
query {
64+
variableScalar(count: 10) @include(if: true)
65+
}
66+
`);
67+
68+
const complexity = getComplexity({
69+
estimators: [
70+
simpleEstimator({defaultComplexity: 1})
71+
],
72+
schema,
73+
query: ast
74+
});
75+
expect(complexity).to.equal(1);
76+
});
77+
78+
it('should respect @skip(if: true)', () => {
79+
const ast = parse(`
80+
query {
81+
variableScalar(count: 10) @skip(if: true)
82+
}
83+
`);
84+
85+
const complexity = getComplexity({
86+
estimators: [
87+
simpleEstimator({defaultComplexity: 1})
88+
],
89+
schema,
90+
query: ast
91+
});
92+
expect(complexity).to.equal(0);
93+
});
94+
95+
it('should respect @skip(if: false)', () => {
96+
const ast = parse(`
97+
query {
98+
variableScalar(count: 10) @skip(if: false)
99+
}
100+
`);
101+
102+
const complexity = getComplexity({
103+
estimators: [
104+
simpleEstimator({defaultComplexity: 1})
105+
],
106+
schema,
107+
query: ast
108+
});
109+
expect(complexity).to.equal(1);
110+
});
111+
112+
it('should respect @skip(if: false) @include(if: true)', () => {
113+
const ast = parse(`
114+
query {
115+
variableScalar(count: 10) @skip(if: false) @include(if: true)
116+
}
117+
`);
118+
119+
const complexity = getComplexity({
120+
estimators: [
121+
simpleEstimator({defaultComplexity: 1})
122+
],
123+
schema,
124+
query: ast
125+
});
126+
expect(complexity).to.equal(1);
127+
});
128+
44129
it('should calculate complexity with variables', () => {
45130
const ast = parse(`
46131
query Q($count: Int) {
@@ -341,7 +426,7 @@ describe('QueryComplexity analysis', () => {
341426
});
342427
expect(Number.isNaN(complexity)).to.equal(true);
343428
});
344-
429+
345430
it('should skip complexity calculation by directiveEstimator when no astNode available on field', () => {
346431
const ast = parse(`
347432
query {

0 commit comments

Comments
 (0)