|
1 | 1 | import type { UserDocument } from '@nbw/database';
|
2 | 2 | import {
|
| 3 | + FeaturedSongsDto, |
3 | 4 | SongDocument,
|
4 | 5 | Song as SongEntity,
|
5 | 6 | SongPreviewDto,
|
@@ -1052,25 +1053,65 @@ describe('SongService', () => {
|
1052 | 1053 | it('should return featured songs', async () => {
|
1053 | 1054 | const songWithUser: SongWithUser = {
|
1054 | 1055 | title: 'Test Song',
|
| 1056 | + publicId: 'test-id', |
1055 | 1057 | uploader: { username: 'testuser', profileImage: 'testimage' },
|
| 1058 | + description: 'Test Description', |
| 1059 | + originalAuthor: 'Test Author', |
1056 | 1060 | stats: {
|
1057 | 1061 | duration: 100,
|
1058 | 1062 | noteCount: 100,
|
1059 | 1063 | },
|
| 1064 | + thumbnailUrl: 'test-thumbnail-url', |
| 1065 | + createdAt: new Date(), |
| 1066 | + updatedAt: new Date(), |
| 1067 | + playCount: 0, |
| 1068 | + visibility: 'public', |
1060 | 1069 | } as any;
|
1061 | 1070 |
|
1062 | 1071 | jest
|
1063 |
| - .spyOn(songService, 'getSongsForTimespan') |
| 1072 | + .spyOn(service, 'getSongsForTimespan') |
1064 | 1073 | .mockResolvedValue([songWithUser]);
|
1065 | 1074 |
|
1066 | 1075 | jest
|
1067 |
| - .spyOn(songService, 'getSongsBeforeTimespan') |
1068 |
| - .mockResolvedValue([songWithUser]); |
| 1076 | + .spyOn(service, 'getSongsBeforeTimespan') |
| 1077 | + .mockResolvedValue([]); |
| 1078 | + |
| 1079 | + const result = await service.getFeaturedSongs(); |
| 1080 | + |
| 1081 | + expect(service.getSongsForTimespan).toHaveBeenCalledTimes(6); // Called for each timespan |
| 1082 | + expect(result).toBeInstanceOf(Object); |
| 1083 | + expect(result).toHaveProperty('hour'); |
| 1084 | + expect(result).toHaveProperty('day'); |
| 1085 | + expect(result).toHaveProperty('week'); |
| 1086 | + expect(result).toHaveProperty('month'); |
| 1087 | + expect(result).toHaveProperty('year'); |
| 1088 | + expect(result).toHaveProperty('all'); |
| 1089 | + expect(Array.isArray(result.hour)).toBe(true); |
| 1090 | + expect(Array.isArray(result.day)).toBe(true); |
| 1091 | + expect(Array.isArray(result.week)).toBe(true); |
| 1092 | + expect(Array.isArray(result.month)).toBe(true); |
| 1093 | + expect(Array.isArray(result.year)).toBe(true); |
| 1094 | + expect(Array.isArray(result.all)).toBe(true); |
| 1095 | + }); |
1069 | 1096 |
|
1070 |
| - await service.getFeaturedSongs(); |
| 1097 | + it('should handle empty results gracefully', async () => { |
| 1098 | + jest |
| 1099 | + .spyOn(service, 'getSongsForTimespan') |
| 1100 | + .mockResolvedValue([]); |
1071 | 1101 |
|
1072 |
| - expect(songService.getSongsForTimespan).toHaveBeenCalled(); |
1073 |
| - expect(songService.getSongsBeforeTimespan).toHaveBeenCalled(); |
| 1102 | + jest |
| 1103 | + .spyOn(service, 'getSongsBeforeTimespan') |
| 1104 | + .mockResolvedValue([]); |
| 1105 | + |
| 1106 | + const result = await service.getFeaturedSongs(); |
| 1107 | + |
| 1108 | + expect(result).toBeInstanceOf(Object); |
| 1109 | + expect(result.hour).toEqual([]); |
| 1110 | + expect(result.day).toEqual([]); |
| 1111 | + expect(result.week).toEqual([]); |
| 1112 | + expect(result.month).toEqual([]); |
| 1113 | + expect(result.year).toEqual([]); |
| 1114 | + expect(result.all).toEqual([]); |
1074 | 1115 | });
|
1075 | 1116 | });
|
1076 | 1117 | });
|
0 commit comments