Skip to content

Commit b605aba

Browse files
committed
refactor: update FileService and SongService tests to use bun:test and improve error handling
1 parent 080285c commit b605aba

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

server/src/song/song.service.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,14 +829,16 @@ describe('SongService', () => {
829829

830830
jest
831831
.spyOn(fileService, 'getSongDownloadUrl')
832-
.mockRejectedValue(new Error());
832+
.mockImplementationOnce(() => {
833+
throw new Error('Internal error');
834+
});
833835

834836
await expect(service.getSongDownloadUrl(publicId, user)).rejects.toThrow(
835837
HttpException,
836838
);
837839
});
838840

839-
it('should throw an error in case of an internal error on saveing the song', async () => {
841+
it('should throw an error in case of an internal error on saving the song', async () => {
840842
const publicId = 'test-id';
841843
const user: UserDocument = { _id: 'test-user-id' } as UserDocument;
842844

@@ -863,7 +865,9 @@ describe('SongService', () => {
863865
packedSongUrl: 'http://test.com/packed-file.nbs',
864866
nbsFileUrl: 'http://test.com/file.nbs',
865867
thumbnailUrl: 'http://test.com/thumbnail.nbs',
866-
save: jest.fn().mockRejectedValue(new Error()), // Simulate error on save
868+
save: jest.fn().mockImplementationOnce(() => {
869+
throw new Error('Error saving song');
870+
}),
867871
};
868872

869873
jest.spyOn(songModel, 'findOne').mockResolvedValue(songEntity);

0 commit comments

Comments
 (0)