@@ -806,6 +806,91 @@ describe("SlidingSync", () => {
806806 await listPromise ;
807807 slidingSync . stop ( ) ;
808808 } ) ;
809+
810+ // Regression test to make sure things like DELETE 0 INSERT 0 work correctly and we don't
811+ // end up losing room IDs.
812+ it ( "should handle insertions with a spurious DELETE correctly" , async ( ) => {
813+ slidingSync = new SlidingSync ( proxyBaseUrl , [
814+ {
815+ ranges : [ [ 0 , 20 ] ] ,
816+ } ,
817+ ] , { } , client ! , 1 ) ;
818+ // initially start with nothing
819+ httpBackend ! . when ( "POST" , syncUrl ) . respond ( 200 , {
820+ pos : "a" ,
821+ lists : [ {
822+ count : 0 ,
823+ ops : [ ] ,
824+ } ] ,
825+ } ) ;
826+ slidingSync . start ( ) ;
827+ await httpBackend ! . flushAllExpected ( ) ;
828+ expect ( slidingSync . getListData ( 0 ) ! . roomIndexToRoomId ) . toEqual ( { } ) ;
829+
830+ // insert a room
831+ httpBackend ! . when ( "POST" , syncUrl ) . respond ( 200 , {
832+ pos : "b" ,
833+ lists : [ {
834+ count : 1 ,
835+ ops : [
836+ {
837+ op : "DELETE" , index : 0 ,
838+ } ,
839+ {
840+ op : "INSERT" , index : 0 , room_id : roomA ,
841+ } ,
842+ ] ,
843+ } ] ,
844+ } ) ;
845+ await httpBackend ! . flushAllExpected ( ) ;
846+ expect ( slidingSync . getListData ( 0 ) ! . roomIndexToRoomId ) . toEqual ( {
847+ 0 : roomA ,
848+ } ) ;
849+
850+ // insert another room
851+ httpBackend ! . when ( "POST" , syncUrl ) . respond ( 200 , {
852+ pos : "c" ,
853+ lists : [ {
854+ count : 1 ,
855+ ops : [
856+ {
857+ op : "DELETE" , index : 1 ,
858+ } ,
859+ {
860+ op : "INSERT" , index : 0 , room_id : roomB ,
861+ } ,
862+ ] ,
863+ } ] ,
864+ } ) ;
865+ await httpBackend ! . flushAllExpected ( ) ;
866+ expect ( slidingSync . getListData ( 0 ) ! . roomIndexToRoomId ) . toEqual ( {
867+ 0 : roomB ,
868+ 1 : roomA ,
869+ } ) ;
870+
871+ // insert a final room
872+ httpBackend ! . when ( "POST" , syncUrl ) . respond ( 200 , {
873+ pos : "c" ,
874+ lists : [ {
875+ count : 1 ,
876+ ops : [
877+ {
878+ op : "DELETE" , index : 2 ,
879+ } ,
880+ {
881+ op : "INSERT" , index : 0 , room_id : roomC ,
882+ } ,
883+ ] ,
884+ } ] ,
885+ } ) ;
886+ await httpBackend ! . flushAllExpected ( ) ;
887+ expect ( slidingSync . getListData ( 0 ) ! . roomIndexToRoomId ) . toEqual ( {
888+ 0 : roomC ,
889+ 1 : roomB ,
890+ 2 : roomA ,
891+ } ) ;
892+ slidingSync . stop ( ) ;
893+ } ) ;
809894 } ) ;
810895
811896 describe ( "transaction IDs" , ( ) => {
0 commit comments