Skip to content

Commit 0225d96

Browse files
committed
fix: update getSong method to handle song not found scenario correctly
1 parent e48717c commit 0225d96

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,14 @@ describe('SongService', () => {
626626
file: 'somebytes',
627627
allowDownload: false,
628628
uploader: {},
629+
save: jest.fn(),
629630
} as any;
630631

631632
songDocument.save = jest.fn().mockResolvedValue(songDocument);
632633

633634
const mockFindOne = {
634635
populate: jest.fn().mockResolvedValue(songDocument),
636+
...songDocument,
635637
};
636638

637639
jest.spyOn(songModel, 'findOne').mockReturnValue(mockFindOne as any);
@@ -677,15 +679,14 @@ describe('SongService', () => {
677679
const publicId = 'test-id';
678680
const user: UserDocument = null as any;
679681

680-
jest.spyOn(songModel, 'findOne').mockReturnValue({
681-
populate: jest.fn().mockImplementationOnce(() => {
682-
throw new HttpException('Song not found', 404);
683-
}),
684-
} as any);
682+
const songEntity = {
683+
publicId: 'test-public-id',
684+
visibility: 'private',
685+
uploader: 'different-user-id',
686+
};
685687

686-
await expect(service.getSong(publicId, user)).rejects.toThrow(
687-
HttpException,
688-
);
688+
jest.spyOn(songModel, 'findOne').mockReturnValue(songEntity as any);
689+
expect(service.getSong(publicId, user)).rejects.toThrow(HttpException);
689690
});
690691
});
691692

0 commit comments

Comments
 (0)