1
1
import fs from 'fs-extra' ;
2
+ import pino from 'pino' ;
2
3
3
- import { Schema } from '../src' ;
4
+ import { Schema , SchemaLoader } from '../src' ;
4
5
import {
5
6
batchIterator ,
6
7
GraphQLBackend ,
@@ -15,7 +16,8 @@ import {
15
16
UpsertBuffer ,
16
17
} from '../src/graphql/client/graphql-client' ;
17
18
import { Operation , UpdateRecord } from '../src/graphql/client/types' ;
18
- import pino from 'pino' ;
19
+
20
+ /*eslint max-len: ["error", { "code": 120 }]*/
19
21
20
22
describe ( 'graphql-client' , ( ) => {
21
23
test ( 'basic batch mutation' , ( ) => {
@@ -207,10 +209,12 @@ describe('graphql-client write batch upsert', () => {
207
209
}
208
210
}` ) ;
209
211
const record1 = JSON . parse (
210
- '{"name":"foo","uid":"foo","repository":{"name":"metis","uid":"metis","organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
212
+ '{"name":"foo","uid":"foo","repository":{"name":"metis","uid":"metis",' +
213
+ '"organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
211
214
) ;
212
215
const record2 = JSON . parse (
213
- '{"name":"main","uid":"main","repository":{"name":"hermes","uid":"hermes","organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
216
+ '{"name":"main","uid":"main","repository":{"name":"hermes","uid":"hermes",' +
217
+ '"organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
214
218
) ;
215
219
let queries = 0 ;
216
220
const backend : GraphQLBackend = {
@@ -226,9 +230,8 @@ describe('graphql-client write batch upsert', () => {
226
230
return Promise . resolve ( res2 ) ;
227
231
} else if ( query . startsWith ( 'mutation { insert_vcs_Branch' ) ) {
228
232
return Promise . resolve ( res3 ) ;
229
- } else {
230
- throw new Error ( 'unexpected query ' + query ) ;
231
233
}
234
+ throw new Error ( 'unexpected query ' + query ) ;
232
235
} ,
233
236
} ;
234
237
const client = new GraphQLClient (
@@ -306,7 +309,8 @@ describe('graphql-client write batch upsert', () => {
306
309
const records = [
307
310
JSON . parse ( '{"name":"foo","uid":"foo"}' ) ,
308
311
JSON . parse (
309
- '{"name":"main","uid":"main","repository":{"name":"hermes","uid":"hermes","organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
312
+ '{"name":"main","uid":"main","repository":{"name":"hermes","uid":"hermes",' +
313
+ '"organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
310
314
) ,
311
315
] ;
312
316
let queries = 0 ;
@@ -360,9 +364,8 @@ describe('graphql-client write batch upsert', () => {
360
364
queries ++ ;
361
365
if ( query . startsWith ( 'mutation { insert_vcs_Organization' ) ) {
362
366
return Promise . resolve ( res1 ) ;
363
- } else {
364
- throw new Error ( 'unexpected query ' + query ) ;
365
367
}
368
+ throw new Error ( 'unexpected query ' + query ) ;
366
369
} ,
367
370
} ;
368
371
const client = new GraphQLClient (
@@ -441,7 +444,9 @@ describe('graphql-client write batch upsert', () => {
441
444
}` ) ;
442
445
const responses = [ res1 , res2 , res3 , res4 ] ;
443
446
const record1 = JSON . parse (
444
- '{"userTool":{"user":{"uid":"dbruno21","source":"GitHub"},"organization":{"uid":"princode-ar","source":"GitHub"},"tool":{"category":"GitHubCopilot","detail":""}},"usedAt":"2021-10-14T00:53:33-06:00"}'
447
+ '{"userTool":{"user":{"uid":"dbruno21","source":"GitHub"},' +
448
+ '"organization":{"uid":"princode-ar","source":"GitHub"},' +
449
+ '"tool":{"category":"GitHubCopilot","detail":""}},"usedAt":"2021-10-14T00:53:33-06:00"}'
445
450
) ;
446
451
let queries = 0 ;
447
452
const backend : GraphQLBackend = {
@@ -465,7 +470,7 @@ describe('graphql-client write batch upsert', () => {
465
470
await client . flush ( ) ;
466
471
expect ( queries ) . toEqual ( 4 ) ;
467
472
} ) ;
468
- test ( 'mergeByPrimaryKey' , async ( ) => {
473
+ test ( 'mergeByPrimaryKey' , ( ) => {
469
474
const users = [
470
475
{
471
476
uid : 'tovbinm' ,
@@ -517,7 +522,7 @@ describe('graphql-client write batch upsert', () => {
517
522
const primaryKeys = [ 'uid' , 'source' ] ;
518
523
expect ( mergeByPrimaryKey ( users , primaryKeys ) ) . toMatchSnapshot ( ) ;
519
524
} ) ;
520
- test ( 'mergeByPrimaryKey - object value' , async ( ) => {
525
+ test ( 'mergeByPrimaryKey - object value' , ( ) => {
521
526
const objs = [
522
527
{
523
528
uid : 'tovbinm' ,
@@ -726,14 +731,16 @@ describe('graphql-client write batch upsert', () => {
726
731
model : 'vcs_PullRequest' ,
727
732
origin : 'my-origin' ,
728
733
data : JSON . parse (
729
- '{"number":2,"uid":"2","repository":{"name":"repo1","uid":"repo1","organization":{"uid":"playg","source":"Bitbucket"}}}'
734
+ '{"number":2,"uid":"2","repository":{"name":"repo1","uid":"repo1",' +
735
+ '"organization":{"uid":"playg","source":"Bitbucket"}}}'
730
736
) ,
731
737
} ,
732
738
{
733
739
model : 'vcs_Commit' ,
734
740
origin : 'my-origin' ,
735
741
data : JSON . parse (
736
- '{"sha":"b500332b58c74fc15302c8961e54facf66c16c44","uid":"b500332b58c74fc15302c8961e54facf66c16c44","repository":{"name":"repo1","uid":"repo1","organization":{"uid":"playg","source":"Bitbucket"}}}'
742
+ '{"sha":"b500332b58c74fc15302c8961e54facf66c16c44","uid":"b500332b58c74fc15302c8961e54facf66c16c44",' +
743
+ '"repository":{"name":"repo1","uid":"repo1","organization":{"uid":"playg","source":"Bitbucket"}}}'
737
744
) ,
738
745
} ,
739
746
] ;
@@ -992,7 +999,7 @@ describe('graphql-client write batch upsert', () => {
992
999
} ) ;
993
1000
994
1001
describe ( 'graphql-client write batch updates' , ( ) => {
995
- const schemaLoader = {
1002
+ const schemaLoader : SchemaLoader = {
996
1003
async loadSchema ( ) : Promise < Schema > {
997
1004
return await fs . readJson ( 'test/resources/hasura-ce-schema.json' , {
998
1005
encoding : 'utf-8' ,
@@ -1049,7 +1056,7 @@ describe('graphql-client write batch updates', () => {
1049
1056
} ) ;
1050
1057
1051
1058
describe ( 'upsert buffer' , ( ) => {
1052
- test ( 'basic' , async ( ) => {
1059
+ test ( 'basic' , ( ) => {
1053
1060
const buf = new UpsertBuffer ( ) ;
1054
1061
buf . add ( { model : 'm1' , object : { } , foreignKeys : { } } ) ;
1055
1062
expect ( buf . size ( ) ) . toEqual ( 1 ) ;
@@ -1067,11 +1074,11 @@ describe('upsert buffer', () => {
1067
1074
} ) ;
1068
1075
1069
1076
describe ( 'graphql-client utilities' , ( ) => {
1070
- test ( 'serialize' , async ( ) => {
1077
+ test ( 'serialize' , ( ) => {
1071
1078
expect ( serialize ( { z : 1 , a : 'bar' } ) ) . toEqual ( 'a:bar|z:1' ) ;
1072
1079
expect ( serialize ( { } ) ) . toEqual ( '' ) ;
1073
1080
} ) ;
1074
- test ( 'strictPick' , async ( ) => {
1081
+ test ( 'strictPick' , ( ) => {
1075
1082
expect ( strictPick ( { z : 0 , a : 'bar' } , [ 'z' , 'b' ] ) ) . toEqual ( { z : 0 , b : 'null' } ) ;
1076
1083
expect ( strictPick ( { z : 1 , a : 'bar' } , [ 'z' , 'b' ] ) ) . toEqual ( { z : 1 , b : 'null' } ) ;
1077
1084
expect ( strictPick ( { z : 1 , a : 'bar' } , [ 'b' ] ) ) . toEqual ( { b : 'null' } ) ;
@@ -1251,18 +1258,18 @@ describe('groupByKeys', () => {
1251
1258
} ) ;
1252
1259
1253
1260
describe ( 'toPostgresArrayLiteral' , ( ) => {
1254
- test ( 'strings' , async ( ) => {
1255
- expect ( toPostgresArrayLiteral ( [ 'a' , 'b' , 'c' ] ) ) . toEqual ( ` {"a","b","c"}` ) ;
1256
- expect ( toPostgresArrayLiteral ( [ 'a' , '' , 'c' ] ) ) . toEqual ( ` {"a","","c"}` ) ;
1257
- expect ( toPostgresArrayLiteral ( [ 'a' , null , 'c' ] ) ) . toEqual ( ` {"a",NULL,"c"}` ) ;
1261
+ test ( 'strings' , ( ) => {
1262
+ expect ( toPostgresArrayLiteral ( [ 'a' , 'b' , 'c' ] ) ) . toEqual ( ' {"a","b","c"}' ) ;
1263
+ expect ( toPostgresArrayLiteral ( [ 'a' , '' , 'c' ] ) ) . toEqual ( ' {"a","","c"}' ) ;
1264
+ expect ( toPostgresArrayLiteral ( [ 'a' , null , 'c' ] ) ) . toEqual ( ' {"a",NULL,"c"}' ) ;
1258
1265
expect ( toPostgresArrayLiteral ( [ 'a' , undefined , 'c' ] ) ) . toEqual (
1259
- ` {"a",NULL,"c"}`
1266
+ ' {"a",NULL,"c"}'
1260
1267
) ;
1261
1268
} ) ;
1262
- test ( 'numbers' , async ( ) => {
1263
- expect ( toPostgresArrayLiteral ( [ 1 , 2 , 3 ] ) ) . toEqual ( ` {1,2,3}` ) ;
1264
- expect ( toPostgresArrayLiteral ( [ 1 , null , 3 ] ) ) . toEqual ( ` {1,NULL,3}` ) ;
1265
- expect ( toPostgresArrayLiteral ( [ 1 , undefined , 3 ] ) ) . toEqual ( ` {1,NULL,3}` ) ;
1266
- expect ( toPostgresArrayLiteral ( [ 1 , 0 , 3 ] ) ) . toEqual ( ` {1,0,3}` ) ;
1269
+ test ( 'numbers' , ( ) => {
1270
+ expect ( toPostgresArrayLiteral ( [ 1 , 2 , 3 ] ) ) . toEqual ( ' {1,2,3}' ) ;
1271
+ expect ( toPostgresArrayLiteral ( [ 1 , null , 3 ] ) ) . toEqual ( ' {1,NULL,3}' ) ;
1272
+ expect ( toPostgresArrayLiteral ( [ 1 , undefined , 3 ] ) ) . toEqual ( ' {1,NULL,3}' ) ;
1273
+ expect ( toPostgresArrayLiteral ( [ 1 , 0 , 3 ] ) ) . toEqual ( ' {1,0,3}' ) ;
1267
1274
} ) ;
1268
1275
} ) ;
0 commit comments