1
1
/* @flow */
2
2
3
- import { TypeComposer , InputTypeComposer , GraphQLJSON } from 'graphql-compose' ;
3
+ import { TypeComposer , GraphQLJSON } from 'graphql-compose' ;
4
4
5
5
import {
6
6
GraphQLString ,
@@ -14,10 +14,7 @@ import {
14
14
import {
15
15
convertToSourceTC ,
16
16
propertyToSourceGraphQLType ,
17
- convertToAggregatableITC ,
18
17
inputPropertiesToGraphQLTypes ,
19
- convertToSearchableITC ,
20
- convertToAnalyzedITC ,
21
18
getSubFields ,
22
19
} from '../mappingConverter' ;
23
20
@@ -173,7 +170,7 @@ describe('PropertiesConverter', () => {
173
170
describe ( 'inputPropertiesToGraphQLTypes()' , ( ) => {
174
171
it ( 'should throw error on incorrect prop' , ( ) => {
175
172
expect ( ( ) => {
176
- inputPropertiesToGraphQLTypes ( { } , ( ) => true ) ;
173
+ inputPropertiesToGraphQLTypes ( { } ) ;
177
174
} ) . toThrowError ( 'incorrect Elastic property config' ) ;
178
175
} ) ;
179
176
@@ -182,35 +179,31 @@ describe('PropertiesConverter', () => {
182
179
{
183
180
type : 'text' ,
184
181
} ,
185
- ( ) => true ,
186
182
'lastname'
187
183
) ;
188
184
expect ( fields . _all . lastname ) . toEqual ( GraphQLString ) ;
189
185
expect ( fields . text . lastname ) . toEqual ( GraphQLString ) ;
190
186
} ) ;
191
187
192
188
it ( 'should accept mapping' , ( ) => {
193
- const fields = inputPropertiesToGraphQLTypes ( mapping , ( ) => true ) ;
189
+ const fields = inputPropertiesToGraphQLTypes ( mapping ) ;
194
190
expect ( Object . keys ( fields . _all ) . length ) . toBeGreaterThan ( 2 ) ;
195
191
} ) ;
196
192
197
193
it ( 'should convert nested fields' , ( ) => {
198
- const fields = inputPropertiesToGraphQLTypes (
199
- {
200
- properties : {
201
- name : {
202
- type : 'text' ,
203
- fields : {
204
- keyword : {
205
- type : 'keyword' ,
206
- ignore_above : 256 ,
207
- } ,
194
+ const fields = inputPropertiesToGraphQLTypes ( {
195
+ properties : {
196
+ name : {
197
+ type : 'text' ,
198
+ fields : {
199
+ keyword : {
200
+ type : 'keyword' ,
201
+ ignore_above : 256 ,
208
202
} ,
209
203
} ,
210
204
} ,
211
205
} ,
212
- ( ) => true
213
- ) ;
206
+ } ) ;
214
207
expect ( Object . keys ( fields . _all ) . length ) . toEqual ( 2 ) ;
215
208
expect ( Object . keys ( fields . _all ) ) . toEqual (
216
209
expect . arrayContaining ( [ 'name' , 'name__keyword' ] )
@@ -223,53 +216,18 @@ describe('PropertiesConverter', () => {
223
216
) ;
224
217
} ) ;
225
218
226
- it ( 'should use filterFn' , ( ) => {
227
- const fields = inputPropertiesToGraphQLTypes (
228
- {
229
- properties : {
230
- name : {
231
- type : 'text' ,
232
- fields : {
233
- keyword : {
234
- type : 'keyword' ,
235
- ignore_above : 256 ,
236
- } ,
237
- } ,
238
- } ,
239
- } ,
240
- } ,
241
- prop => prop . type !== 'text'
242
- ) ;
243
- expect ( Object . keys ( fields . _all ) . length ) . toEqual ( 1 ) ;
244
- expect ( Object . keys ( fields . _all ) ) . toEqual (
245
- expect . arrayContaining ( [ 'name__keyword' ] )
246
- ) ;
247
- expect ( Object . keys ( fields . keyword ) . length ) . toEqual ( 1 ) ;
248
- expect ( Object . keys ( fields . keyword ) ) . toEqual (
249
- expect . arrayContaining ( [ 'name__keyword' ] )
250
- ) ;
251
- } ) ;
252
-
253
219
it ( 'should not return index:false fields' , ( ) => {
254
- const itc = convertToSearchableITC ( mapping , 'SearchInput' ) ;
255
- expect ( itc . getFieldNames ( ) ) . not . toEqual (
256
- expect . arrayContaining ( [ 'noIndex' ] )
257
- ) ;
258
-
259
- const fields = inputPropertiesToGraphQLTypes (
260
- {
261
- properties : {
262
- name : {
263
- type : 'text' ,
264
- index : false ,
265
- } ,
266
- date : {
267
- type : 'date' ,
268
- } ,
220
+ const fields = inputPropertiesToGraphQLTypes ( {
221
+ properties : {
222
+ name : {
223
+ type : 'text' ,
224
+ index : false ,
225
+ } ,
226
+ date : {
227
+ type : 'date' ,
269
228
} ,
270
229
} ,
271
- prop => prop . type !== 'text'
272
- ) ;
230
+ } ) ;
273
231
expect ( Object . keys ( fields . _all ) . length ) . toEqual ( 1 ) ;
274
232
expect ( Object . keys ( fields . _all ) ) . toEqual (
275
233
expect . arrayContaining ( [ 'date' ] )
@@ -281,116 +239,6 @@ describe('PropertiesConverter', () => {
281
239
} ) ;
282
240
} ) ;
283
241
284
- describe ( 'convertToAggregatableITC()' , ( ) => {
285
- it ( 'should throw error on empty mapping' , ( ) => {
286
- // $FlowFixMe
287
- expect ( ( ) => convertToAggregatableITC ( ) ) . toThrowError (
288
- 'incorrect mapping'
289
- ) ;
290
- } ) ;
291
-
292
- it ( 'should throw error on empty typeName' , ( ) => {
293
- expect ( ( ) => {
294
- // $FlowFixMe
295
- convertToAggregatableITC ( mapping ) ;
296
- } ) . toThrowError ( 'empty name' ) ;
297
- } ) ;
298
-
299
- it ( 'should return InputTypeComposer' , ( ) => {
300
- const itc = convertToAggregatableITC ( mapping , 'AggsInput' ) ;
301
- expect ( itc ) . toBeInstanceOf ( InputTypeComposer ) ;
302
- expect ( itc . getTypeName ( ) ) . toBe ( 'AggsInput' ) ;
303
- expect ( itc . getFieldNames ( ) . length ) . toBeGreaterThan ( 1 ) ;
304
- } ) ;
305
-
306
- it ( 'should return array of aggregatable fields' , ( ) => {
307
- const itc = convertToAggregatableITC ( mapping , 'AggsInput' ) ;
308
- expect ( itc . getFieldNames ( ) ) . toEqual (
309
- expect . arrayContaining ( [
310
- 'name__keyword' ,
311
- 'birthday' ,
312
- 'avatarUrl__thumb__keyword' ,
313
- ] )
314
- ) ;
315
- } ) ;
316
-
317
- it ( 'should not return text fields' , ( ) => {
318
- const itc = convertToAggregatableITC ( mapping , 'AggsInput' ) ;
319
- expect ( itc . getFieldNames ( ) ) . not . toEqual (
320
- expect . arrayContaining ( [ 'lastname' ] )
321
- ) ;
322
- } ) ;
323
- } ) ;
324
-
325
- describe ( 'convertToSearchableITC()' , ( ) => {
326
- it ( 'should throw error on empty mapping' , ( ) => {
327
- // $FlowFixMe
328
- expect ( ( ) => convertToSearchableITC ( ) ) . toThrowError ( 'incorrect mapping' ) ;
329
- } ) ;
330
-
331
- it ( 'should throw error on empty typeName' , ( ) => {
332
- expect ( ( ) => {
333
- // $FlowFixMe
334
- convertToSearchableITC ( mapping ) ;
335
- } ) . toThrowError ( 'empty name' ) ;
336
- } ) ;
337
-
338
- it ( 'should return InputTypeComposer' , ( ) => {
339
- const itc = convertToSearchableITC ( mapping , 'SearchInput' ) ;
340
- expect ( itc ) . toBeInstanceOf ( InputTypeComposer ) ;
341
- expect ( itc . getTypeName ( ) ) . toBe ( 'SearchInput' ) ;
342
- expect ( itc . getFieldNames ( ) . length ) . toBeGreaterThan ( 1 ) ;
343
- } ) ;
344
-
345
- it ( 'should return array of searchable fields' , ( ) => {
346
- const itc = convertToSearchableITC ( mapping , 'SearchInput' ) ;
347
- expect ( itc . getFieldNames ( ) ) . toEqual (
348
- expect . arrayContaining ( [
349
- 'name__keyword' ,
350
- 'name' ,
351
- 'avatarUrl__big' ,
352
- 'avatarUrl__thumb__keyword' ,
353
- 'avatarUrl__thumb' ,
354
- 'lastname' ,
355
- 'birthday' ,
356
- ] )
357
- ) ;
358
- } ) ;
359
- } ) ;
360
-
361
- describe ( 'convertToAnalyzedITC()' , ( ) => {
362
- it ( 'should throw error on empty mapping' , ( ) => {
363
- // $FlowFixMe
364
- expect ( ( ) => convertToAnalyzedITC ( ) ) . toThrowError ( 'incorrect mapping' ) ;
365
- } ) ;
366
-
367
- it ( 'should throw error on empty typeName' , ( ) => {
368
- expect ( ( ) => {
369
- // $FlowFixMe
370
- convertToAnalyzedITC ( mapping ) ;
371
- } ) . toThrowError ( 'empty name' ) ;
372
- } ) ;
373
-
374
- it ( 'should return InputTypeComposer' , ( ) => {
375
- const itc = convertToAnalyzedITC ( mapping , 'AnalyzedInput' ) ;
376
- expect ( itc ) . toBeInstanceOf ( InputTypeComposer ) ;
377
- expect ( itc . getTypeName ( ) ) . toBe ( 'AnalyzedInput' ) ;
378
- expect ( itc . getFieldNames ( ) . length ) . toBeGreaterThan ( 1 ) ;
379
- } ) ;
380
-
381
- it ( 'should return array of searchable fields' , ( ) => {
382
- const itc = convertToAnalyzedITC ( mapping , 'AnalyzedInput' ) ;
383
- expect ( itc . getFieldNames ( ) ) . toEqual (
384
- expect . arrayContaining ( [
385
- 'name' ,
386
- 'avatarUrl__big' ,
387
- 'avatarUrl__thumb' ,
388
- 'lastname' ,
389
- ] )
390
- ) ;
391
- } ) ;
392
- } ) ;
393
-
394
242
describe ( 'getSubFields()' , ( ) => {
395
243
it ( 'should return array of sub fields' , ( ) => {
396
244
expect (
0 commit comments