@@ -566,6 +566,46 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
566566 ErrorStatusCode . INVALID_SWAP_DUPLICATE_INDEX_FOUND ,
567567 ) ;
568568 } ) ;
569+
570+ test ( `${ permission } key: Swap two indexes with rename` , async ( ) => {
571+ const client = await getClient ( permission ) ;
572+ const originalUid1 = index . uid ;
573+ const originalUid2 = index2 . uid ;
574+
575+ await client
576+ . index ( originalUid1 )
577+ . addDocuments ( [ { id : 1 , title : "index_1" } ] )
578+ . waitTask ( ) ;
579+ await client
580+ . index ( originalUid2 )
581+ . addDocuments ( [ { id : 1 , title : "index_2" } ] )
582+ . waitTask ( ) ;
583+
584+ const swaps : IndexSwap [ ] = [
585+ { indexes : [ originalUid1 , originalUid2 ] , rename : true } ,
586+ ] ;
587+
588+ const resolvedTask = await client . swapIndexes ( swaps ) . waitTask ( ) ;
589+
590+ // Verify the old indexes no longer exist
591+ await expect ( client . getIndex ( originalUid1 ) ) . rejects . toHaveProperty (
592+ "cause.code" ,
593+ ErrorStatusCode . INDEX_NOT_FOUND ,
594+ ) ;
595+ await expect ( client . getIndex ( originalUid2 ) ) . rejects . toHaveProperty (
596+ "cause.code" ,
597+ ErrorStatusCode . INDEX_NOT_FOUND ,
598+ ) ;
599+
600+ // Verify the new indexes exist with swapped content
601+ const docIndex1 = await client . index ( originalUid1 ) . getDocument ( 1 ) ;
602+ const docIndex2 = await client . index ( originalUid2 ) . getDocument ( 1 ) ;
603+
604+ expect ( docIndex1 . title ) . toEqual ( "index_2" ) ;
605+ expect ( docIndex2 . title ) . toEqual ( "index_1" ) ;
606+ expect ( resolvedTask . type ) . toEqual ( "indexSwap" ) ;
607+ expect ( resolvedTask . details ?. swaps ) . toEqual ( swaps ) ;
608+ } ) ;
569609 } ) ;
570610
571611 describe ( "Test on base routes" , ( ) => {
0 commit comments