@@ -261,9 +261,14 @@ describe('DataConnectApiClient CRUD helpers', () => {
261
261
} ,
262
262
notes : undefined ,
263
263
releaseYear : undefined ,
264
- extras : [ 1 , undefined , 'hello' , undefined , { a : 1 , b : undefined } ]
264
+ extras : [ 1 , 'hello' , { a : 1 , b : undefined } ]
265
265
} ;
266
266
267
+ const dataWithSparseArray = {
268
+ genre : 'Action' ,
269
+ extras : [ 1 , undefined , 'hello' , undefined , { a : 1 , b : undefined } ]
270
+ }
271
+
267
272
const tableNames = [ 'movie' , 'Movie' , 'MOVIE' , 'mOvIE' , 'toybox' , 'toyBox' , 'toyBOX' , 'ToyBox' , 'TOYBOX' ] ;
268
273
const formatedTableNames = [ 'movie' , 'movie' , 'mOVIE' , 'mOvIE' , 'toybox' , 'toyBox' , 'toyBOX' , 'toyBox' , 'tOYBOX' ] ;
269
274
@@ -343,7 +348,7 @@ describe('DataConnectApiClient CRUD helpers', () => {
343
348
title: "Die Hard",
344
349
ratings: null,
345
350
director: {},
346
- extras: [1, null, "hello", null , { a: 1 }]
351
+ extras: [1, "hello", { a: 1 }]
347
352
})
348
353
}` ;
349
354
await apiClient . insert ( tableName , dataWithUndefined ) ;
@@ -369,6 +374,16 @@ describe('DataConnectApiClient CRUD helpers', () => {
369
374
await expect ( apiClientQueryError . insert ( tableName , { data : 1 } ) )
370
375
. to . be . rejectedWith ( FirebaseDataConnectError , `${ serverErrorString } . ${ additionalErrorMessageForBulkImport } ` ) ;
371
376
} ) ;
377
+
378
+ [
379
+ { a : [ null ] } , { a : [ undefined ] } , { a : [ 1 , null , 2 ] } , { a : [ 1 , undefined , 2 ] } ,
380
+ { a : [ 'a' , null , 'b' , undefined , 'd' ] } , dataWithSparseArray
381
+ ] . forEach ( ( data ) => {
382
+ it ( 'should throw FirebaseDataConnectError for arrays with null or undefined elements' , async ( ) => {
383
+ await expect ( apiClient . insert ( tableName , data ) )
384
+ . to . be . rejectedWith ( FirebaseDataConnectError , / A r r a y e l e m e n t s c a n n o t c o n t a i n ` n u l l ` o r ` u n d e f i n e d ` v a l u e s ./ ) ;
385
+ } ) ;
386
+ } ) ;
372
387
} ) ;
373
388
374
389
// --- INSERT MANY TESTS ---
@@ -417,14 +432,14 @@ describe('DataConnectApiClient CRUD helpers', () => {
417
432
title: "Die Hard",
418
433
ratings: null,
419
434
director: {},
420
- extras: [1, null, "hello", null , { a: 1 }]
435
+ extras: [1, "hello", { a: 1 }]
421
436
},
422
437
{
423
438
genre: "Action",
424
439
title: "Die Hard",
425
440
ratings: null,
426
441
director: {},
427
- extras: [1, null, "hello", null , { a: 1 }]
442
+ extras: [1, "hello", { a: 1 }]
428
443
}])
429
444
}` ;
430
445
await apiClient . insertMany ( tableName , dataArray ) ;
@@ -455,6 +470,16 @@ describe('DataConnectApiClient CRUD helpers', () => {
455
470
await expect ( apiClientQueryError . insertMany ( tableName , [ { data : 1 } ] ) )
456
471
. to . be . rejectedWith ( FirebaseDataConnectError , `${ serverErrorString } . ${ additionalErrorMessageForBulkImport } ` ) ;
457
472
} ) ;
473
+
474
+ [
475
+ [ null ] , [ undefined ] , [ 1 , null , 2 ] , [ 1 , undefined , 2 ] ,
476
+ [ 'a' , null , 'b' , undefined , 'd' ] , [ dataWithSparseArray ]
477
+ ] . forEach ( ( data ) => {
478
+ it ( 'should throw FirebaseDataConnectError for arrays with null or undefined elements' , async ( ) => {
479
+ await expect ( apiClient . insertMany ( tableName , data ) )
480
+ . to . be . rejectedWith ( FirebaseDataConnectError , / A r r a y e l e m e n t s c a n n o t c o n t a i n ` n u l l ` o r ` u n d e f i n e d ` v a l u e s ./ ) ;
481
+ } ) ;
482
+ } ) ;
458
483
} ) ;
459
484
460
485
// --- UPSERT TESTS ---
@@ -476,10 +501,10 @@ describe('DataConnectApiClient CRUD helpers', () => {
476
501
} ) ;
477
502
478
503
it ( 'should call executeGraphql with the correct mutation for complex data' , async ( ) => {
479
- const complexData = { id : 'key2' , active : false , items : [ 1 , null ] , detail : { status : 'done/\\' } } ;
504
+ const complexData = { id : 'key2' , active : false , items : [ 1 , 2 ] , detail : { status : 'done/\\' } } ;
480
505
const expectedMutation = `
481
506
mutation { ${ formatedTableName } _upsert(data:
482
- { id: "key2", active: false, items: [1, null ], detail: { status: "done/\\\\" } }) }` ;
507
+ { id: "key2", active: false, items: [1, 2 ], detail: { status: "done/\\\\" } }) }` ;
483
508
await apiClient . upsert ( tableName , complexData ) ;
484
509
expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( normalizeGraphQLString ( expectedMutation ) ) ;
485
510
} ) ;
@@ -492,7 +517,7 @@ describe('DataConnectApiClient CRUD helpers', () => {
492
517
title: "Die Hard",
493
518
ratings: null,
494
519
director: {},
495
- extras: [1, null, "hello", null , { a: 1 }]
520
+ extras: [1, "hello", { a: 1 }]
496
521
})
497
522
}` ;
498
523
await apiClient . upsert ( tableName , dataWithUndefined ) ;
@@ -518,6 +543,16 @@ describe('DataConnectApiClient CRUD helpers', () => {
518
543
await expect ( apiClientQueryError . upsert ( tableName , { data : 1 } ) )
519
544
. to . be . rejectedWith ( FirebaseDataConnectError , `${ serverErrorString } . ${ additionalErrorMessageForBulkImport } ` ) ;
520
545
} ) ;
546
+
547
+ [
548
+ { a : [ null ] } , { a : [ undefined ] } , { a : [ 1 , null , 2 ] } , { a : [ 1 , undefined , 2 ] } ,
549
+ { a : [ 'a' , null , 'b' , undefined , 'd' ] } , dataWithSparseArray
550
+ ] . forEach ( ( data ) => {
551
+ it ( 'should throw FirebaseDataConnectError for arrays with null or undefined elements' , async ( ) => {
552
+ await expect ( apiClient . upsert ( tableName , data ) )
553
+ . to . be . rejectedWith ( FirebaseDataConnectError , / A r r a y e l e m e n t s c a n n o t c o n t a i n ` n u l l ` o r ` u n d e f i n e d ` v a l u e s ./ ) ;
554
+ } ) ;
555
+ } ) ;
521
556
} ) ;
522
557
523
558
// --- UPSERT MANY TESTS ---
@@ -542,11 +577,11 @@ describe('DataConnectApiClient CRUD helpers', () => {
542
577
it ( 'should call executeGraphql with the correct mutation for complex data array' , async ( ) => {
543
578
const complexDataArray = [
544
579
{ id : 'x' , active : true , info : { nested : 'n1/\\"x' } } ,
545
- { id : 'y' , scores : [ null , 2 ] }
580
+ { id : 'y' , scores : [ 1 , 2 ] }
546
581
] ;
547
582
const expectedMutation = `
548
583
mutation { ${ formatedTableName } _upsertMany(data:
549
- [{ id: "x", active: true, info: { nested: "n1/\\\\\\"x" } }, { id: "y", scores: [null , 2] }]) }` ;
584
+ [{ id: "x", active: true, info: { nested: "n1/\\\\\\"x" } }, { id: "y", scores: [1 , 2] }]) }` ;
550
585
await apiClient . upsertMany ( tableName , complexDataArray ) ;
551
586
expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( normalizeGraphQLString ( expectedMutation ) ) ;
552
587
} ) ;
@@ -563,14 +598,14 @@ describe('DataConnectApiClient CRUD helpers', () => {
563
598
title: "Die Hard",
564
599
ratings: null,
565
600
director: {},
566
- extras: [1, null, "hello", null , { a: 1 }]
601
+ extras: [1, "hello", { a: 1 }]
567
602
},
568
603
{
569
604
genre: "Action",
570
605
title: "Die Hard",
571
606
ratings: null,
572
607
director: {},
573
- extras: [1, null, "hello", null , { a: 1 }]
608
+ extras: [1, "hello", { a: 1 }]
574
609
}])
575
610
}` ;
576
611
await apiClient . upsertMany ( tableName , dataArray ) ;
@@ -601,5 +636,15 @@ describe('DataConnectApiClient CRUD helpers', () => {
601
636
await expect ( apiClientQueryError . upsertMany ( tableName , [ { data : 1 } ] ) )
602
637
. to . be . rejectedWith ( FirebaseDataConnectError , `${ serverErrorString } . ${ additionalErrorMessageForBulkImport } ` ) ;
603
638
} ) ;
639
+
640
+ [
641
+ [ null ] , [ undefined ] , [ 1 , null , 2 ] , [ 1 , undefined , 2 ] ,
642
+ [ 'a' , null , 'b' , undefined , 'd' ] , [ dataWithSparseArray ]
643
+ ] . forEach ( ( data ) => {
644
+ it ( 'should throw FirebaseDataConnectError for arrays with null or undefined elements' , async ( ) => {
645
+ await expect ( apiClient . upsertMany ( tableName , data ) )
646
+ . to . be . rejectedWith ( FirebaseDataConnectError , / A r r a y e l e m e n t s c a n n o t c o n t a i n ` n u l l ` o r ` u n d e f i n e d ` v a l u e s ./ ) ;
647
+ } ) ;
648
+ } ) ;
604
649
} ) ;
605
650
} ) ;
0 commit comments