@@ -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,52 @@ describe('Query watch', () => {
786807 ) ;
787808 } ) ;
788809
810+ it ( 'supports alwaysUseImplicitOrderBy' , async ( ) => {
811+ // Re-initialize with alwaysUseImplicitOrderBy: true
812+ firestore = await createInstance ( { listen : ( ) => listenCallback ( ) } , {
813+ alwaysUseImplicitOrderBy : true ,
814+ } ) ;
815+ const query = firestore . collection ( 'col' ) . where ( 'foo' , '>' , 'bar' ) ;
816+ watchHelper = new WatchHelper ( streamHelper , query , targetId ) ;
817+
818+ const expectedQueryJSON = {
819+ database : `projects/${ PROJECT_ID } /databases/(default)` ,
820+ addTarget : {
821+ query : {
822+ parent : `projects/${ PROJECT_ID } /databases/(default)/documents` ,
823+ structuredQuery : {
824+ from : [ { collectionId : 'col' } ] ,
825+ where : {
826+ fieldFilter : {
827+ field : { fieldPath : 'foo' } ,
828+ op : 'GREATER_THAN' as api . StructuredQuery . FieldFilter . Operator ,
829+ value : { stringValue : 'bar' } ,
830+ } ,
831+ } ,
832+ orderBy : [
833+ {
834+ direction : 'ASCENDING' as api . StructuredQuery . Direction ,
835+ field : { fieldPath : 'foo' } ,
836+ } ,
837+ {
838+ direction : 'ASCENDING' as api . StructuredQuery . Direction ,
839+ field : { fieldPath : '__name__' } ,
840+ } ,
841+ ] ,
842+ } ,
843+ } ,
844+ targetId,
845+ } ,
846+ } ;
847+
848+ return watchHelper . runTest ( expectedQueryJSON , ( ) => {
849+ watchHelper . sendAddTarget ( targetId ) ;
850+ watchHelper . sendCurrent ( ) ;
851+ watchHelper . sendSnapshot ( 1 ) ;
852+ return watchHelper . await ( 'snapshot' ) ;
853+ } ) ;
854+ } ) ;
855+
789856 it ( 'rejects an unknown target' , ( ) => {
790857 return watchHelper . runFailedTest (
791858 collQueryJSON ( ) ,
0 commit comments