@@ -3913,6 +3913,112 @@ describe('Query class', () => {
39133913 unsubscribe ( ) ;
39143914 } ) ;
39153915
3916+ it ( 'snapshot listener sorts query by DocumentId same way as server' , async ( ) => {
3917+ const batch = firestore . batch ( ) ;
3918+ batch . set ( randomCol . doc ( 'A' ) , { a : 1 } ) ;
3919+ batch . set ( randomCol . doc ( 'a' ) , { a : 1 } ) ;
3920+ batch . set ( randomCol . doc ( 'Aa' ) , { a : 1 } ) ;
3921+ batch . set ( randomCol . doc ( '7' ) , { a : 1 } ) ;
3922+ batch . set ( randomCol . doc ( '12' ) , { a : 1 } ) ;
3923+ batch . set ( randomCol . doc ( '__id7__' ) , { a : 1 } ) ;
3924+ batch . set ( randomCol . doc ( '__id12__' ) , { a : 1 } ) ;
3925+ batch . set ( randomCol . doc ( '__id-2__' ) , { a : 1 } ) ;
3926+ batch . set ( randomCol . doc ( '__id1_' ) , { a : 1 } ) ;
3927+ batch . set ( randomCol . doc ( '_id1__' ) , { a : 1 } ) ;
3928+ batch . set ( randomCol . doc ( '__id' ) , { a : 1 } ) ;
3929+ // largest long number
3930+ batch . set ( randomCol . doc ( '__id9223372036854775807__' ) , { a : 1 } ) ;
3931+ batch . set ( randomCol . doc ( '__id9223372036854775806__' ) , { a : 1 } ) ;
3932+ // smallest long number
3933+ batch . set ( randomCol . doc ( '__id-9223372036854775808__' ) , { a : 1 } ) ;
3934+ batch . set ( randomCol . doc ( '__id-9223372036854775807__' ) , { a : 1 } ) ;
3935+ await batch . commit ( ) ;
3936+
3937+ const query = randomCol . orderBy ( FieldPath . documentId ( ) ) ;
3938+ const expectedDocs = [
3939+ '__id-9223372036854775808__' ,
3940+ '__id-9223372036854775807__' ,
3941+ '__id-2__' ,
3942+ '__id7__' ,
3943+ '__id12__' ,
3944+ '__id9223372036854775806__' ,
3945+ '__id9223372036854775807__' ,
3946+ '12' ,
3947+ '7' ,
3948+ 'A' ,
3949+ 'Aa' ,
3950+ '__id' ,
3951+ '__id1_' ,
3952+ '_id1__' ,
3953+ 'a' ,
3954+ ] ;
3955+
3956+ const getSnapshot = await query . get ( ) ;
3957+ expect ( getSnapshot . docs . map ( d => d . id ) ) . to . deep . equal ( expectedDocs ) ;
3958+
3959+ const unsubscribe = query . onSnapshot ( snapshot =>
3960+ currentDeferred . resolve ( snapshot )
3961+ ) ;
3962+
3963+ const watchSnapshot = await waitForSnapshot ( ) ;
3964+ // Compare the snapshot (including sort order) of a snapshot
3965+ snapshotsEqual ( watchSnapshot , {
3966+ docs : getSnapshot . docs ,
3967+ docChanges : getSnapshot . docChanges ( ) ,
3968+ } ) ;
3969+ unsubscribe ( ) ;
3970+ } ) ;
3971+
3972+ it ( 'snapshot listener sorts filtered query by DocumentId same way as server' , async ( ) => {
3973+ const batch = firestore . batch ( ) ;
3974+ batch . set ( randomCol . doc ( 'A' ) , { a : 1 } ) ;
3975+ batch . set ( randomCol . doc ( 'a' ) , { a : 1 } ) ;
3976+ batch . set ( randomCol . doc ( 'Aa' ) , { a : 1 } ) ;
3977+ batch . set ( randomCol . doc ( '7' ) , { a : 1 } ) ;
3978+ batch . set ( randomCol . doc ( '12' ) , { a : 1 } ) ;
3979+ batch . set ( randomCol . doc ( '__id7__' ) , { a : 1 } ) ;
3980+ batch . set ( randomCol . doc ( '__id12__' ) , { a : 1 } ) ;
3981+ batch . set ( randomCol . doc ( '__id-2__' ) , { a : 1 } ) ;
3982+ batch . set ( randomCol . doc ( '__id1_' ) , { a : 1 } ) ;
3983+ batch . set ( randomCol . doc ( '_id1__' ) , { a : 1 } ) ;
3984+ batch . set ( randomCol . doc ( '__id' ) , { a : 1 } ) ;
3985+ // largest long number
3986+ batch . set ( randomCol . doc ( '__id9223372036854775807__' ) , { a : 1 } ) ;
3987+ batch . set ( randomCol . doc ( '__id9223372036854775806__' ) , { a : 1 } ) ;
3988+ // smallest long number
3989+ batch . set ( randomCol . doc ( '__id-9223372036854775808__' ) , { a : 1 } ) ;
3990+ batch . set ( randomCol . doc ( '__id-9223372036854775807__' ) , { a : 1 } ) ;
3991+ await batch . commit ( ) ;
3992+
3993+ const query = randomCol
3994+ . where ( FieldPath . documentId ( ) , '>' , '__id7__' )
3995+ . where ( FieldPath . documentId ( ) , '<=' , 'A' )
3996+ . orderBy ( FieldPath . documentId ( ) ) ;
3997+ const expectedDocs = [
3998+ '__id12__' ,
3999+ '__id9223372036854775806__' ,
4000+ '__id9223372036854775807__' ,
4001+ '12' ,
4002+ '7' ,
4003+ 'A' ,
4004+ ] ;
4005+
4006+ const getSnapshot = await query . get ( ) ;
4007+ expect ( getSnapshot . docs . map ( d => d . id ) ) . to . deep . equal ( expectedDocs ) ;
4008+
4009+ const unsubscribe = query . onSnapshot ( snapshot =>
4010+ currentDeferred . resolve ( snapshot )
4011+ ) ;
4012+
4013+ const watchSnapshot = await waitForSnapshot ( ) ;
4014+ // Compare the snapshot (including sort order) of a snapshot
4015+ snapshotsEqual ( watchSnapshot , {
4016+ docs : getSnapshot . docs ,
4017+ docChanges : getSnapshot . docChanges ( ) ,
4018+ } ) ;
4019+ unsubscribe ( ) ;
4020+ } ) ;
4021+
39164022 it ( 'SDK orders vector field same way as backend' , async ( ) => {
39174023 // We validate that the SDK orders the vector field the same way as the backend
39184024 // by comparing the sort order of vector fields from a Query.get() and
0 commit comments