33// import fs from 'fs';
44import dox from 'dox' ;
55import path from 'path' ;
6- import {
6+ import { GraphQLJSON , TypeComposer , graphql } from 'graphql-compose' ;
7+ import ElasticApiParser from '../ElasticApiParser' ;
8+
9+ const {
710 GraphQLString,
811 GraphQLFloat,
912 GraphQLBoolean,
1013 GraphQLObjectType,
1114 GraphQLEnumType,
1215 GraphQLNonNull,
13- } from 'graphql' ;
14- import { GraphQLJSON , TypeComposer } from 'graphql-compose' ;
15-
16- import ElasticApiParser from '../ElasticApiParser' ;
16+ } = graphql ;
1717
1818const apiPartialPath = path . resolve ( __dirname , '../__mocks__/apiPartial.js' ) ;
1919
@@ -29,9 +29,7 @@ describe('ElasticApiParser', () => {
2929 describe ( 'static methods' , ( ) => {
3030 describe ( 'loadApiFile()' , ( ) => {
3131 it ( 'should load file with data' , ( ) => {
32- expect ( ElasticApiParser . loadApiFile ( apiPartialPath ) ) . toContain (
33- 'api.search = ca({'
34- ) ;
32+ expect ( ElasticApiParser . loadApiFile ( apiPartialPath ) ) . toContain ( 'api.search = ca({' ) ;
3533 } ) ;
3634
3735 it ( 'should replace invalid markup' , ( ) => {
@@ -126,9 +124,7 @@ describe('ElasticApiParser', () => {
126124
127125 describe ( 'cleanupDescription()' , ( ) => {
128126 it ( 'should remove `- ` from start and trim' , ( ) => {
129- expect ( ElasticApiParser . cleanupDescription ( '- Some param ' ) ) . toEqual (
130- 'Some param'
131- ) ;
127+ expect ( ElasticApiParser . cleanupDescription ( '- Some param ' ) ) . toEqual ( 'Some param' ) ;
132128 } ) ;
133129 } ) ;
134130
@@ -148,11 +144,9 @@ describe('ElasticApiParser', () => {
148144 } ) ;
149145
150146 it ( "should api['delete'] convert to api.delete" , ( ) => {
151- expect (
152- ElasticApiParser . cleanUpSource (
153- `api.indices.prototype['delete'] = ca({`
154- )
155- ) . toEqual ( `api.indices.prototype.delete = ca({` ) ;
147+ expect ( ElasticApiParser . cleanUpSource ( `api.indices.prototype['delete'] = ca({` ) ) . toEqual (
148+ `api.indices.prototype.delete = ca({`
149+ ) ;
156150 } ) ;
157151 } ) ;
158152
@@ -172,9 +166,7 @@ describe('ElasticApiParser', () => {
172166 `
173167 ) ;
174168 const doxAST = dox . parseComments ( source , { raw : true } ) ;
175- expect (
176- ElasticApiParser . parseParamsDescription ( doxAST [ 0 ] )
177- ) . toMatchObject ( {
169+ expect ( ElasticApiParser . parseParamsDescription ( doxAST [ 0 ] ) ) . toMatchObject ( {
178170 analyzeWildcard : 'Specify whether wildcard and prefix queries should be analyzed (default: false)' ,
179171 analyzer : 'The analyzer to use for the query string' ,
180172 from : 'Starting offset (default: 0)' ,
@@ -258,15 +250,14 @@ describe('ElasticApiParser', () => {
258250
259251 describe ( 'getMethodName()' , ( ) => {
260252 it ( 'should return string' , ( ) => {
261- expect ( ElasticApiParser . getMethodName ( 'api.updateByQuery' ) ) . toEqual (
262- 'updateByQuery'
263- ) ;
253+ expect ( ElasticApiParser . getMethodName ( 'api.updateByQuery' ) ) . toEqual ( 'updateByQuery' ) ;
264254 } ) ;
265255
266256 it ( 'should return array of string' , ( ) => {
267- expect (
268- ElasticApiParser . getMethodName ( 'api.cat.prototype.allocation' )
269- ) . toEqual ( [ 'cat' , 'allocation' ] ) ;
257+ expect ( ElasticApiParser . getMethodName ( 'api.cat.prototype.allocation' ) ) . toEqual ( [
258+ 'cat' ,
259+ 'allocation' ,
260+ ] ) ;
270261 } ) ;
271262 } ) ;
272263
@@ -283,54 +274,35 @@ describe('ElasticApiParser', () => {
283274
284275 it ( 'should return ElasticParsedSourceT' , ( ) => {
285276 expect (
286- ElasticApiParser . parseSource (
287- ElasticApiParser . loadApiFile ( apiPartialPath )
288- )
277+ ElasticApiParser . parseSource ( ElasticApiParser . loadApiFile ( apiPartialPath ) )
289278 ) . toMatchSnapshot ( ) ;
290279 } ) ;
291280 } ) ;
292281 } ) ;
293282
294283 describe ( 'paramTypeToGraphQL()' , ( ) => {
295284 it ( 'should convert scalar types' , ( ) => {
296- expect ( parser . paramTypeToGraphQL ( { type : 'string' } , 'f1' ) ) . toEqual (
297- GraphQLString
298- ) ;
299- expect ( parser . paramTypeToGraphQL ( { type : 'boolean' } , 'f1' ) ) . toEqual (
300- GraphQLBoolean
301- ) ;
302- expect ( parser . paramTypeToGraphQL ( { type : 'number' } , 'f1' ) ) . toEqual (
303- GraphQLFloat
304- ) ;
305- expect ( parser . paramTypeToGraphQL ( { type : 'time' } , 'f1' ) ) . toEqual (
306- GraphQLString
307- ) ;
285+ expect ( parser . paramTypeToGraphQL ( { type : 'string' } , 'f1' ) ) . toEqual ( GraphQLString ) ;
286+ expect ( parser . paramTypeToGraphQL ( { type : 'boolean' } , 'f1' ) ) . toEqual ( GraphQLBoolean ) ;
287+ expect ( parser . paramTypeToGraphQL ( { type : 'number' } , 'f1' ) ) . toEqual ( GraphQLFloat ) ;
288+ expect ( parser . paramTypeToGraphQL ( { type : 'time' } , 'f1' ) ) . toEqual ( GraphQLString ) ;
308289 } ) ;
309290
310291 it ( 'should `list` convert to GraphQLJSON' , ( ) => {
311- expect ( parser . paramTypeToGraphQL ( { type : 'list' } , 'f1' ) ) . toEqual (
312- GraphQLJSON
313- ) ;
292+ expect ( parser . paramTypeToGraphQL ( { type : 'list' } , 'f1' ) ) . toEqual ( GraphQLJSON ) ;
314293 } ) ;
315294
316295 it ( 'should `enum` convert to GraphQLString (if empty options)' , ( ) => {
317- expect ( parser . paramTypeToGraphQL ( { type : 'enum' } , 'f1' ) ) . toEqual (
318- GraphQLString
319- ) ;
296+ expect ( parser . paramTypeToGraphQL ( { type : 'enum' } , 'f1' ) ) . toEqual ( GraphQLString ) ;
320297 } ) ;
321298
322299 it ( 'should `enum` convert to GraphQLEnumType' , ( ) => {
323- const type = parser . paramTypeToGraphQL (
324- { type : 'enum' , options : [ 'AND' , 'OR' ] } ,
325- 'f1'
326- ) ;
300+ const type = parser . paramTypeToGraphQL ( { type : 'enum' , options : [ 'AND' , 'OR' ] } , 'f1' ) ;
327301 expect ( type ) . toBeInstanceOf ( GraphQLEnumType ) ;
328302 } ) ;
329303
330304 it ( 'should as fallback type return GraphQLJSON' , ( ) => {
331- expect ( parser . paramTypeToGraphQL ( { type : 'crazy' } , 'f1' ) ) . toEqual (
332- GraphQLJSON
333- ) ;
305+ expect ( parser . paramTypeToGraphQL ( { type : 'crazy' } , 'f1' ) ) . toEqual ( GraphQLJSON ) ;
334306 } ) ;
335307 } ) ;
336308
@@ -405,9 +377,7 @@ describe('ElasticApiParser', () => {
405377
406378 describe ( 'paramToGraphQLArgConfig()' , ( ) => {
407379 it ( 'should return object with type property' , ( ) => {
408- expect (
409- parser . paramToGraphQLArgConfig ( { type : 'string' } , 'f1' )
410- ) . toMatchObject ( {
380+ expect ( parser . paramToGraphQLArgConfig ( { type : 'string' } , 'f1' ) ) . toMatchObject ( {
411381 type : GraphQLString ,
412382 } ) ;
413383 } ) ;
@@ -422,9 +392,7 @@ describe('ElasticApiParser', () => {
422392 } ) ;
423393
424394 it ( 'should set defaultValue="json" for `format` argument' , ( ) => {
425- expect (
426- parser . paramToGraphQLArgConfig ( { type : 'string' } , 'format' )
427- ) . toMatchObject ( {
395+ expect ( parser . paramToGraphQLArgConfig ( { type : 'string' } , 'format' ) ) . toMatchObject ( {
428396 type : GraphQLString ,
429397 defaultValue : 'json' ,
430398 } ) ;
@@ -558,9 +526,7 @@ describe('ElasticApiParser', () => {
558526 elasticApiFilePath : apiPartialPath ,
559527 } ) ;
560528 expect ( partialApiParser . generateFieldConfig ( 'search' ) ) . toMatchSnapshot ( ) ;
561- expect (
562- partialApiParser . generateFieldConfig ( 'cat.allocation' )
563- ) . toMatchSnapshot ( ) ;
529+ expect ( partialApiParser . generateFieldConfig ( 'cat.allocation' ) ) . toMatchSnapshot ( ) ;
564530 } ) ;
565531 } ) ;
566532
0 commit comments