@@ -597,6 +597,12 @@ describe('Query watch', () => {
597597 parent : `projects/${ PROJECT_ID } /databases/(default)/documents` ,
598598 structuredQuery : {
599599 from : [ { collectionId : 'col' } ] ,
600+ orderBy : [
601+ {
602+ direction : 'ASCENDING' as api . StructuredQuery . Direction ,
603+ field : { fieldPath : '__name__' } ,
604+ } ,
605+ ] ,
600606 } ,
601607 } ,
602608 targetId,
@@ -628,6 +634,12 @@ describe('Query watch', () => {
628634 } ,
629635 } ,
630636 } ,
637+ orderBy : [
638+ {
639+ direction : 'ASCENDING' as api . StructuredQuery . Direction ,
640+ field : { fieldPath : '__name__' } ,
641+ } ,
642+ ] ,
631643 } ,
632644 } ,
633645 targetId,
@@ -667,7 +679,16 @@ describe('Query watch', () => {
667679 parent : `projects/${ PROJECT_ID } /databases/(default)/documents` ,
668680 structuredQuery : {
669681 from : [ { collectionId : 'col' } ] ,
670- orderBy : [ { direction : 'DESCENDING' , field : { fieldPath : 'foo' } } ] ,
682+ orderBy : [
683+ {
684+ direction : 'DESCENDING' as api . StructuredQuery . Direction ,
685+ field : { fieldPath : 'foo' } ,
686+ } ,
687+ {
688+ direction : 'DESCENDING' as api . StructuredQuery . Direction ,
689+ field : { fieldPath : '__name__' } ,
690+ } ,
691+ ] ,
671692 } ,
672693 } ,
673694 targetId,
@@ -786,6 +807,60 @@ describe('Query watch', () => {
786807 ) ;
787808 } ) ;
788809
810+ it ( 'supports alwaysUseImplicitOrderBy' , async ( ) => {
811+ // Re-initialize with alwaysUseImplicitOrderBy: true
812+ firestore = await createInstance (
813+ { listen : ( ) => listenCallback ( ) } ,
814+ { alwaysUseImplicitOrderBy : true } as any ,
815+ ) ;
816+ const query = firestore . collection ( 'col' ) . where ( 'foo' , '>' , 'bar' ) ;
817+ watchHelper = new WatchHelper (
818+ streamHelper ,
819+ query ,
820+ targetId ,
821+ ) ;
822+
823+ const expectedQueryJSON = {
824+ database : `projects/${ PROJECT_ID } /databases/(default)` ,
825+ addTarget : {
826+ query : {
827+ parent : `projects/${ PROJECT_ID } /databases/(default)/documents` ,
828+ structuredQuery : {
829+ from : [ { collectionId : 'col' } ] ,
830+ where : {
831+ fieldFilter : {
832+ field : { fieldPath : 'foo' } ,
833+ op : 'GREATER_THAN' as api . StructuredQuery . FieldFilter . Operator ,
834+ value : { stringValue : 'bar' } ,
835+ } ,
836+ } ,
837+ orderBy : [
838+ {
839+ direction : 'ASCENDING' as api . StructuredQuery . Direction ,
840+ field : { fieldPath : 'foo' } ,
841+ } ,
842+ {
843+ direction : 'ASCENDING' as api . StructuredQuery . Direction ,
844+ field : { fieldPath : '__name__' } ,
845+ } ,
846+ ] ,
847+ } ,
848+ } ,
849+ targetId,
850+ } ,
851+ } ;
852+
853+ return watchHelper . runTest (
854+ expectedQueryJSON ,
855+ ( ) => {
856+ watchHelper . sendAddTarget ( targetId ) ;
857+ watchHelper . sendCurrent ( ) ;
858+ watchHelper . sendSnapshot ( 1 ) ;
859+ return watchHelper . await ( 'snapshot' ) ;
860+ } ,
861+ ) ;
862+ } ) ;
863+
789864 it ( 'rejects an unknown target' , ( ) => {
790865 return watchHelper . runFailedTest (
791866 collQueryJSON ( ) ,
0 commit comments