1- import getQueryTypeComplxity from '../../src/analysis/typeComplexityAnalysis' ;
1+ import getQueryTypeComplexity from '../../src/analysis/typeComplexityAnalysis' ;
22
33/**
44 * Here is the schema that creates the followning 'typeWeightsObject' used for the tests
@@ -164,48 +164,44 @@ const typeWeights: TypeWeightObject = {
164164describe ( 'Test getQueryTypeComplexity function' , ( ) => {
165165 let query = '' ;
166166 describe ( 'Calculates the correct type complexity for queries' , ( ) => {
167- beforeEach ( ( ) => {
168- query = '' ;
169- } ) ;
170-
171167 test ( 'with one feild' , ( ) => {
172168 query = `Query { scalars { num } }` ;
173- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + Scalars 1
169+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + Scalars 1
174170 } ) ;
175171
176172 test ( 'with two or more fields' , ( ) => {
177173 query = `Query { scalars { num } test { name } }` ;
178- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 3 ) ; // Query 1 + scalars 1 + test 1
174+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 3 ) ; // Query 1 + scalars 1 + test 1
179175 } ) ;
180176
181177 test ( 'with one level of nested fields' , ( ) => {
182178 query = `Query { scalars { num, test { name } } }` ;
183- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 3 ) ; // Query 1 + scalars 1 + test 1
179+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 3 ) ; // Query 1 + scalars 1 + test 1
184180 } ) ;
185181
186182 test ( 'with multiple levels of nesting' , ( ) => {
187183 query = `Query { scalars { num, test { name, scalars { id } } } }` ;
188- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 4 ) ; // Query 1 + scalars 1 + test 1 + scalars 1
184+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 4 ) ; // Query 1 + scalars 1 + test 1 + scalars 1
189185 } ) ;
190186
191187 test ( 'with aliases' , ( ) => {
192188 query = `Query { foo: scalar { num } bar: scalar { id }}` ;
193- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 3 ) ; // Query 1 + scalar 1 + scalar 1
189+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 3 ) ; // Query 1 + scalar 1 + scalar 1
194190 } ) ;
195191
196192 test ( 'with all scalar fields' , ( ) => {
197193 query = `Query { scalars { id, num, float, bool, string } }` ;
198- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + scalar 1
194+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + scalar 1
199195 } ) ;
200196
201197 test ( 'with arguments and variables' , ( ) => {
202198 query = `Query { hero(episode: EMPIRE) { id, name } }` ;
203- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + hero/character 1
199+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + hero/character 1
204200 query = `Query { human(id: 1) { id, name, appearsIn } }` ;
205- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 3 ) ; // Query 1 + human/character 1 + appearsIn/episode
201+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 3 ) ; // Query 1 + human/character 1 + appearsIn/episode
206202 // argument passed in as a variable
207203 query = `Query { hero(episode: $ep) { id, name } }` ;
208- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + hero/character 1
204+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + hero/character 1
209205 } ) ;
210206
211207 test ( 'with fragments' , ( ) => {
@@ -224,7 +220,7 @@ describe('Test getQueryTypeComplexity function', () => {
224220 appearsIn
225221 }
226222 }` ;
227- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 5 ) ; // Query 1 + 2*(character 1 + appearsIn/episode 1)
223+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 5 ) ; // Query 1 + 2*(character 1 + appearsIn/episode 1)
228224 } ) ;
229225
230226 test ( 'with inline fragments' , ( ) => {
@@ -240,14 +236,11 @@ describe('Test getQueryTypeComplexity function', () => {
240236 }
241237 }
242238 }` ;
243- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + hero/character 1)
239+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 2 ) ; // Query 1 + hero/character 1)
244240 } ) ;
245241
246242 /**
247- * TODO: handle lists of unknown size
248- *
249- * Figure out the implementation before tests
250- *
243+ * FIXME: handle lists of unknown size. change the expected result Once we figure out the implementation.
251244 */
252245 xtest ( 'with lists of unknown size' , ( ) => {
253246 query = `
@@ -259,12 +252,12 @@ describe('Test getQueryTypeComplexity function', () => {
259252 }
260253 }
261254 }` ;
262- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( false ) ; // ?
255+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( false ) ; // ?
263256 } ) ;
264257
265258 test ( 'with lists detrmined by arguments' , ( ) => {
266259 query = `Query {reviews(episode: EMPIRE, first: 3) { stars, commentary } }` ;
267- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( false ) ; // 1 Query + 3 reviews
260+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( false ) ; // 1 Query + 3 reviews
268261 } ) ;
269262
270263 test ( 'with nested lists' , ( ) => {
@@ -280,7 +273,7 @@ describe('Test getQueryTypeComplexity function', () => {
280273 }
281274 }
282275 }` ;
283- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 17 ) ; // 1 Query + 1 human/character + (5 friends/character X 3 friends/characters)
276+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 17 ) ; // 1 Query + 1 human/character + (5 friends/character X 3 friends/characters)
284277 } ) ;
285278
286279 test ( 'accounting for __typename feild' , ( ) => {
@@ -298,19 +291,19 @@ describe('Test getQueryTypeComplexity function', () => {
298291 }
299292 }
300293 }` ;
301- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 5 ) ; // 1 Query + 4 search results
294+ expect ( getQueryTypeComplexity ( query , typeWeights ) ) . toBe ( 5 ) ; // 1 Query + 4 search results
302295 } ) ;
303296
304297 // todo: directives @skip , @include and custom directives
305298
306299 // todo: expand on error handling
307300 test ( 'Throws an error if for a bad query' , ( ) => {
308301 query = `Query { hello { hi } }` ; // type doesn't exist
309- expect ( ( ) => getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
302+ expect ( ( ) => getQueryTypeComplexity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
310303 query = `Query { hero(episode: EMPIRE){ starship } }` ; // field doesn't exist
311- expect ( ( ) => getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
304+ expect ( ( ) => getQueryTypeComplexity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
312305 query = `Query { hero(episode: EMPIRE) { id, name }` ; // missing a closing bracket
313- expect ( ( ) => getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
306+ expect ( ( ) => getQueryTypeComplexity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
314307 } ) ;
315308 } ) ;
316309
0 commit comments