1616
1717import * as chai from 'chai' ;
1818import * as chaiAsPromised from 'chai-as-promised' ;
19- import { getDataConnect , ConnectorConfig } from '../../src /data-connect/index' ;
19+ import { getDataConnect , ConnectorConfig } from '../../lib /data-connect/index' ;
2020import firebase from '@firebase/app-compat' ;
2121import { apiKey , projectId } from './setup' ;
22- import { OperationOptions } from '../../src /data-connect/data-connect-api' ;
22+ import { OperationOptions } from '../../lib /data-connect/data-connect-api' ;
2323
2424chai . should ( ) ;
2525chai . use ( chaiAsPromised ) ;
@@ -291,12 +291,14 @@ describe('getDataConnect()', () => {
291291 upsertFredUser
292292 ) ;
293293 //{ data: { user_insert: { id: 'fred_id' } } }
294+ expect ( fredResponse . data . user_upsert . id ) . to . not . be . empty ;
294295 expect ( fredResponse . data . user_upsert . id ) . equals ( fredUser . id ) ;
295296
296297 const jeffResponse = await getDataConnect ( connectorConfig ) . executeGraphql < UserUpsertResponse , unknown > (
297298 upsertJeffUser
298299 ) ;
299300 //{ data: { user_insert: { id: 'jeff_id' } } }
301+ expect ( jeffResponse . data . user_upsert . id ) . to . not . be . empty ;
300302 expect ( jeffResponse . data . user_upsert . id ) . equals ( jeffUser . id ) ;
301303
302304 const upsertEmailResponse = await getDataConnect ( connectorConfig ) . executeGraphql < EmailUpsertResponse , unknown > (
@@ -318,14 +320,19 @@ describe('getDataConnect()', () => {
318320 it ( 'executeGraphql() successfully executes a GraphQL query' , async ( ) => {
319321 const resp = await getDataConnect ( connectorConfig )
320322 . executeGraphql < ListUsersResponse , unknown > ( queryListUsers ) ;
321- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
323+ expect ( resp . data . users ) . to . not . be . empty ;
324+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
325+ resp . data . users . forEach ( ( user ) => {
326+ expect ( initialState . users ) . to . deep . include ( user ) ;
327+ } ) ;
322328 } ) ;
323329
324330 it ( 'executeGraphql() use the operationName when multiple queries are provided' , async ( ) => {
325331 const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListEmailsResponse , unknown > (
326332 multipleQueries ,
327333 { operationName : 'ListEmails' }
328334 ) ;
335+ expect ( resp . data . emails ) . to . not . be . empty ;
329336 expect ( resp . data . emails ) . to . deep . equal ( initialState . emails ) ;
330337 } ) ;
331338
@@ -347,7 +354,11 @@ describe('getDataConnect()', () => {
347354 it ( 'executeGraphqlRead() successfully executes a read-only GraphQL' , async ( ) => {
348355 const resp = await getDataConnect ( connectorConfig )
349356 . executeGraphqlRead < ListUsersResponse , unknown > ( queryListUsers ) ;
350- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
357+ expect ( resp . data . users ) . to . not . be . empty ;
358+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
359+ resp . data . users . forEach ( ( user ) => {
360+ expect ( initialState . users ) . to . deep . include ( user ) ;
361+ } ) ;
351362 } ) ;
352363
353364 it ( 'executeGraphqlRead() should throw for a GraphQL mutation' , async ( ) => {
@@ -362,6 +373,7 @@ describe('getDataConnect()', () => {
362373 const resp =
363374 await getDataConnect ( connectorConfig ) . executeGraphqlRead < ListUsersResponse , unknown > (
364375 queryListUsersImpersonation , optsAuthorizedFredClaims ) ;
376+ expect ( resp . data . users ) . to . not . be . empty ;
365377 expect ( resp . data . users . length ) . equals ( 1 ) ;
366378 expect ( resp . data . users [ 0 ] ) . to . deep . equal ( fredUser ) ;
367379 } ) ;
@@ -377,6 +389,7 @@ describe('getDataConnect()', () => {
377389 it ( 'executeGraphql() successfully executes an impersonated query with authenticated claims' , async ( ) => {
378390 const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListUsersResponse , unknown > (
379391 queryListUsersImpersonation , optsAuthorizedFredClaims ) ;
392+ expect ( resp . data . users ) . to . not . be . empty ;
380393 expect ( resp . data . users . length ) . equals ( 1 ) ;
381394 expect ( resp . data . users [ 0 ] ) . to . deep . equal ( fredUser ) ;
382395 } ) ;
@@ -403,6 +416,7 @@ describe('getDataConnect()', () => {
403416 expect ( updateResp . data . user_update . id ) . equals ( fredUser . id ) ;
404417 const queryResp = await getDataConnect ( connectorConfig ) . executeGraphql < GetUserResponse , GetUserVariables > (
405418 queryGetUserById , { variables : { id : { id : fredUser . id } } } ) ;
419+ expect ( queryResp . data . user ) . to . not . be . empty ;
406420 expect ( queryResp . data . user ) . to . deep . equal ( fredrickUser ) ;
407421 } ) ;
408422
@@ -424,20 +438,32 @@ describe('getDataConnect()', () => {
424438 it ( 'executeGraphql() successfully executes an impersonated query with authenticated claims' , async ( ) => {
425439 const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListUsersResponse , unknown > (
426440 queryListUsers , optsAuthorizedFredClaims ) ;
427- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
441+ expect ( resp . data . users ) . to . not . be . empty ;
442+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
443+ resp . data . users . forEach ( ( user ) => {
444+ expect ( initialState . users ) . to . deep . include ( user ) ;
445+ } ) ;
428446 } ) ;
429447
430448 it ( 'executeGraphql() successfully executes an impersonated query with unauthenticated claims' , async ( ) => {
431449 const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListUsersResponse , unknown > (
432450 queryListUsers , optsUnauthorizedClaims ) ;
433- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
451+ expect ( resp . data . users ) . to . not . be . empty ;
452+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
453+ resp . data . users . forEach ( ( user ) => {
454+ expect ( initialState . users ) . to . deep . include ( user ) ;
455+ } ) ;
434456 } ) ;
435457
436458 it ( 'executeGraphql() successfully executes an impersonated query with non-existing authenticated claims' ,
437459 async ( ) => {
438460 const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListUsersResponse , unknown > (
439461 queryListUsers , optsNonExistingClaims ) ;
440- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
462+ expect ( resp . data . users ) . to . not . be . empty ;
463+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
464+ resp . data . users . forEach ( ( user ) => {
465+ expect ( initialState . users ) . to . deep . include ( user ) ;
466+ } ) ;
441467 } ) ;
442468 } ) ;
443469
@@ -461,8 +487,8 @@ describe('getDataConnect()', () => {
461487 } ) ;
462488 } ) ;
463489
464- describe ( 'executeQuery|Mutation API' , ( ) => {
465- describe ( 'executeQuery ()' , ( ) => {
490+ describe ( 'operation ref API' , ( ) => {
491+ describe ( 'queryRef ()' , ( ) => {
466492 it ( "should fail when executing a query which doesn't exist" , async ( ) => {
467493 return getDataConnect ( connectorConfig ) . executeQuery (
468494 'DOES_NOT_EXIST!!!' ,
@@ -476,6 +502,7 @@ describe('getDataConnect()', () => {
476502 'GetUser' ,
477503 { id : { id : fredUser . id } } ,
478504 ) ;
505+ expect ( resp . data . user ) . to . not . be . empty ;
479506 expect ( resp . data . user ) . to . deep . equal ( fredUser ) ;
480507 } ) ;
481508
@@ -486,7 +513,11 @@ describe('getDataConnect()', () => {
486513 undefined ,
487514 optsUnauthorizedClaims
488515 ) ;
489- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
516+ expect ( resp . data . users ) . to . not . be . empty ;
517+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
518+ resp . data . users . forEach ( ( user ) => {
519+ expect ( initialState . users ) . to . deep . include ( user ) ;
520+ } ) ;
490521 } ) ;
491522
492523 it ( 'should fail to execute a query with @auth(level: USER_ANON)' , ( ) => {
@@ -519,14 +550,22 @@ describe('getDataConnect()', () => {
519550 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
520551 'ListUsersPublic' , undefined , optsAuthorizedFredAnonClaims
521552 ) ;
522- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
553+ expect ( resp . data . users ) . to . not . be . empty ;
554+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
555+ resp . data . users . forEach ( ( user ) => {
556+ expect ( initialState . users ) . to . deep . include ( user ) ;
557+ } ) ;
523558 } ) ;
524559
525560 it ( 'should successfully execute a query with @auth(level: USER_ANON)' , async ( ) => {
526561 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
527562 'ListUsersUserAnon' , undefined , optsAuthorizedFredAnonClaims
528563 ) ;
529- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
564+ expect ( resp . data . users ) . to . not . be . empty ;
565+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
566+ resp . data . users . forEach ( ( user ) => {
567+ expect ( initialState . users ) . to . deep . include ( user ) ;
568+ } ) ;
530569 } ) ;
531570
532571 it ( 'should fail to execute a query with @auth(level: USER)' , async ( ) => {
@@ -551,6 +590,7 @@ describe('getDataConnect()', () => {
551590 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
552591 'ListUsersImpersonationAnon' , undefined , optsAuthorizedFredAnonClaims
553592 ) ;
593+ expect ( resp . data . users ) . to . not . be . empty ;
554594 expect ( resp . data . users . length ) . equals ( 1 ) ;
555595 expect ( resp . data . users [ 0 ] ) . to . deep . equal ( fredUser ) ;
556596 } ) ;
@@ -561,21 +601,33 @@ describe('getDataConnect()', () => {
561601 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
562602 'ListUsersPublic' , undefined , optsAuthorizedFredClaims
563603 ) ;
564- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
604+ expect ( resp . data . users ) . to . not . be . empty ;
605+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
606+ resp . data . users . forEach ( ( user ) => {
607+ expect ( initialState . users ) . to . deep . include ( user ) ;
608+ } ) ;
565609 } ) ;
566610
567611 it ( 'should successfully execute a query with @auth(level: USER_ANON)' , async ( ) => {
568612 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
569613 'ListUsersUserAnon' , undefined , optsAuthorizedFredClaims
570614 ) ;
571- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
615+ expect ( resp . data . users ) . to . not . be . empty ;
616+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
617+ resp . data . users . forEach ( ( user ) => {
618+ expect ( initialState . users ) . to . deep . include ( user ) ;
619+ } ) ;
572620 } ) ;
573621
574622 it ( 'should successfully execute a query with @auth(level: USER)' , async ( ) => {
575623 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
576624 'ListUsersUser' , undefined , optsAuthorizedFredClaims
577625 ) ;
578- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
626+ expect ( resp . data . users ) . to . not . be . empty ;
627+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
628+ resp . data . users . forEach ( ( user ) => {
629+ expect ( initialState . users ) . to . deep . include ( user ) ;
630+ } ) ;
579631 } ) ;
580632
581633 it ( 'should fail to execute a query with @auth(level: USER_EMAIL_VERIFIED)' , async ( ) => {
@@ -594,6 +646,7 @@ describe('getDataConnect()', () => {
594646 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
595647 'ListUsersImpersonationAnon' , undefined , optsAuthorizedFredClaims
596648 ) ;
649+ expect ( resp . data . users ) . to . not . be . empty ;
597650 expect ( resp . data . users . length ) . equals ( 1 ) ;
598651 expect ( resp . data . users [ 0 ] ) . to . deep . equal ( fredUser ) ;
599652 } ) ;
@@ -604,28 +657,44 @@ describe('getDataConnect()', () => {
604657 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
605658 'ListUsersPublic' , undefined , optsAuthorizedFredEmailVerifiedClaims
606659 ) ;
607- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
660+ expect ( resp . data . users ) . to . not . be . empty ;
661+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
662+ resp . data . users . forEach ( ( user ) => {
663+ expect ( initialState . users ) . to . deep . include ( user ) ;
664+ } ) ;
608665 } ) ;
609666
610667 it ( 'should successfully execute a query with @auth(level: USER_ANON)' , async ( ) => {
611668 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
612669 'ListUsersUserAnon' , undefined , optsAuthorizedFredEmailVerifiedClaims
613670 ) ;
614- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
671+ expect ( resp . data . users ) . to . not . be . empty ;
672+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
673+ resp . data . users . forEach ( ( user ) => {
674+ expect ( initialState . users ) . to . deep . include ( user ) ;
675+ } ) ;
615676 } ) ;
616677
617678 it ( 'should successfully execute a query with @auth(level: USER)' , async ( ) => {
618679 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
619680 'ListUsersUser' , undefined , optsAuthorizedFredEmailVerifiedClaims
620681 ) ;
621- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
682+ expect ( resp . data . users ) . to . not . be . empty ;
683+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
684+ resp . data . users . forEach ( ( user ) => {
685+ expect ( initialState . users ) . to . deep . include ( user ) ;
686+ } ) ;
622687 } ) ;
623688
624689 it ( 'should successfully execute a query with @auth(level: USER_EMAIL_VERIFIED)' , async ( ) => {
625690 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
626691 'ListUsersUserEmailVerified' , undefined , optsAuthorizedFredEmailVerifiedClaims
627692 ) ;
628- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
693+ expect ( resp . data . users ) . to . not . be . empty ;
694+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
695+ resp . data . users . forEach ( ( user ) => {
696+ expect ( initialState . users ) . to . deep . include ( user ) ;
697+ } ) ;
629698 } ) ;
630699
631700 it ( 'should fail to execute a query with @auth(level: NO_ACCESS)' , async ( ) => {
@@ -638,6 +707,7 @@ describe('getDataConnect()', () => {
638707 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse , undefined > (
639708 'ListUsersImpersonationAnon' , undefined , optsAuthorizedFredEmailVerifiedClaims
640709 ) ;
710+ expect ( resp . data . users ) . to . not . be . empty ;
641711 expect ( resp . data . users . length ) . equals ( 1 ) ;
642712 expect ( resp . data . users [ 0 ] ) . to . deep . equal ( fredUser ) ;
643713 } ) ;
@@ -648,35 +718,55 @@ describe('getDataConnect()', () => {
648718 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse > (
649719 'ListUsersPublic'
650720 ) ;
651- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
721+ expect ( resp . data . users ) . to . not . be . empty ;
722+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
723+ resp . data . users . forEach ( ( user ) => {
724+ expect ( initialState . users ) . to . deep . include ( user ) ;
725+ } ) ;
652726 } ) ;
653727
654728 it ( 'should successfully execute a query with @auth(level: USER_ANON)' , async ( ) => {
655729 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse > (
656730 'ListUsersUserAnon'
657731 ) ;
658- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
732+ expect ( resp . data . users ) . to . not . be . empty ;
733+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
734+ resp . data . users . forEach ( ( user ) => {
735+ expect ( initialState . users ) . to . deep . include ( user ) ;
736+ } ) ;
659737 } ) ;
660738
661739 it ( 'should successfully execute a query with @auth(level: USER)' , async ( ) => {
662740 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse > (
663741 'ListUsersUser'
664742 ) ;
665- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
743+ expect ( resp . data . users ) . to . not . be . empty ;
744+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
745+ resp . data . users . forEach ( ( user ) => {
746+ expect ( initialState . users ) . to . deep . include ( user ) ;
747+ } ) ;
666748 } ) ;
667749
668750 it ( 'should successfully execute a query with @auth(level: USER_EMAIL_VERIFIED)' , async ( ) => {
669751 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse > (
670752 'ListUsersUserEmailVerified'
671753 ) ;
672- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
754+ expect ( resp . data . users ) . to . not . be . empty ;
755+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
756+ resp . data . users . forEach ( ( user ) => {
757+ expect ( initialState . users ) . to . deep . include ( user ) ;
758+ } ) ;
673759 } ) ;
674760
675761 it ( 'should successfully execute a query with @auth(level: NO_ACCESS)' , async ( ) => {
676762 const resp = await getDataConnect ( connectorConfig ) . executeQuery < ListUsersResponse > (
677763 'ListUsersNoAccess'
678764 ) ;
679- expect ( resp . data . users ) . to . deep . equal ( initialState . users ) ;
765+ expect ( resp . data . users ) . to . not . be . empty ;
766+ expect ( resp . data . users . length ) . to . equal ( initialState . users . length ) ;
767+ resp . data . users . forEach ( ( user ) => {
768+ expect ( initialState . users ) . to . deep . include ( user ) ;
769+ } ) ;
680770 } ) ;
681771
682772 it ( "should fail to execute a query using the impersonated user's auth.uid" , async ( ) => {
@@ -687,7 +777,7 @@ describe('getDataConnect()', () => {
687777 } ) ;
688778 } ) ;
689779
690- describe ( 'executeMutation ()' , ( ) => {
780+ describe ( 'mutationRef ()' , ( ) => {
691781 function generateEmailId ( ) : string {
692782 return `email_id_${ Math . random ( ) * 1000 } ` ;
693783 }
@@ -702,12 +792,14 @@ describe('getDataConnect()', () => {
702792 const user = { id : 'USER_ID' , name : 'USER_NAME' , address : 'USER_ADDRESS' } ;
703793 const insertResp = await getDataConnect ( connectorConfig )
704794 . executeMutation < InsertUserResponse , InsertUserVariables > ( 'InsertUser' , user ) ;
795+ expect ( insertResp . data . user_insert ) . to . not . be . empty ;
705796 expect ( insertResp . data . user_insert ) . to . deep . equal ( { id : user . id } ) ;
706797
707798 const getResp = await getDataConnect ( connectorConfig ) . executeQuery < GetUserResponse , GetUserVariables > (
708799 'GetUser' ,
709800 { id : { id : user . id } } ,
710801 ) ;
802+ expect ( getResp . data . user ) . to . not . be . empty ;
711803 expect ( getResp . data . user ) . to . deep . equal ( user ) ;
712804 } )
713805
@@ -1002,4 +1094,4 @@ describe('getDataConnect()', () => {
10021094 } ) ;
10031095 } ) ;
10041096 } ) ;
1005- } ) ;
1097+ } ) ;
0 commit comments