@@ -31,7 +31,6 @@ const mockSongService = {
3131 getSongEdit : jest . fn ( ) ,
3232 patchSong : jest . fn ( ) ,
3333 getSongDownloadUrl : jest . fn ( ) ,
34- getSongFileBuffer : jest . fn ( ) ,
3534 deleteSong : jest . fn ( ) ,
3635 uploadSong : jest . fn ( ) ,
3736 getRandomSongs : jest . fn ( ) ,
@@ -803,40 +802,31 @@ describe('SongController', () => {
803802 } ) ;
804803
805804 describe ( 'getSongFile' , ( ) => {
806- it ( 'should get song .nbs file ' , async ( ) => {
805+ it ( 'should redirect to download URL ' , async ( ) => {
807806 const id = 'test-id' ;
808807 const src = 'test-src' ;
809808 const user : UserDocument = {
810809 _id : 'test-user-id' ,
811810 } as unknown as UserDocument ;
811+ const downloadUrl = 'https://example.com/download/song.nbs' ;
812812
813813 const res = {
814814 set : jest . fn ( ) ,
815- send : jest . fn ( ) ,
815+ redirect : jest . fn ( ) ,
816816 } as unknown as Response ;
817817
818- const buffer = Buffer . from ( 'test-song-data' ) ;
819- const filename = 'test-song.nbs' ;
820-
821- mockSongService . getSongFileBuffer . mockResolvedValueOnce ( {
822- buffer,
823- filename,
824- } ) ;
818+ mockSongService . getSongDownloadUrl . mockResolvedValueOnce ( downloadUrl ) ;
825819
826820 await songController . getSongFile ( id , src , user , res ) ;
827821
828822 expect ( res . set ) . toHaveBeenCalledWith ( {
829- 'Content-Type' : 'application/octet-stream' ,
830- 'Content-Disposition' : `attachment; filename="${ filename . replace (
831- / [ / " ] / g,
832- '_' ,
833- ) } "`,
823+ 'Content-Disposition' : 'attachment; filename="song.nbs"' ,
834824 'Access-Control-Expose-Headers' : 'Content-Disposition' ,
835825 } ) ;
836826
837- expect ( res . send ) . toHaveBeenCalledWith ( Buffer . from ( buffer ) ) ;
827+ expect ( res . redirect ) . toHaveBeenCalledWith ( HttpStatus . FOUND , downloadUrl ) ;
838828
839- expect ( songService . getSongFileBuffer ) . toHaveBeenCalledWith (
829+ expect ( songService . getSongDownloadUrl ) . toHaveBeenCalledWith (
840830 id ,
841831 user ,
842832 src ,
@@ -853,16 +843,16 @@ describe('SongController', () => {
853843
854844 const res = {
855845 set : jest . fn ( ) ,
856- send : jest . fn ( ) ,
846+ redirect : jest . fn ( ) ,
857847 } as unknown as Response ;
858848
859- mockSongService . getSongFileBuffer . mockRejectedValueOnce (
849+ mockSongService . getSongDownloadUrl . mockRejectedValueOnce (
860850 new Error ( 'Error' ) ,
861851 ) ;
862852
863853 await expect (
864854 songController . getSongFile ( id , src , user , res ) ,
865- ) . rejects . toThrow ( 'An error occurred while retrieving the song file ' ) ;
855+ ) . rejects . toThrow ( 'Error ' ) ;
866856 } ) ;
867857 } ) ;
868858
0 commit comments