Skip to content

Commit 42451c4

Browse files
committed
test: remove mock dependencies for SongBrowserService in SongController tests to simplify test structure
1 parent 98e1586 commit 42451c4

File tree

1 file changed

+0
-27
lines changed

1 file changed

+0
-27
lines changed

apps/backend/src/song/song.controller.spec.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Response } from 'express';
77

88
import { FileService } from '../file/file.service';
99

10-
import { SongBrowserService } from './song-browser/song-browser.service';
1110
import { SongController } from './song.controller';
1211
import { SongService } from './song.service';
1312

@@ -24,17 +23,9 @@ const mockSongService = {
2423

2524
const mockFileService = {};
2625

27-
const mockSongBrowserService = {
28-
getRecentSongs: jest.fn(),
29-
getCategories: jest.fn(),
30-
getSongsByCategory: jest.fn(),
31-
getRandomSongs: jest.fn(),
32-
};
33-
3426
describe('SongController', () => {
3527
let songController: SongController;
3628
let songService: SongService;
37-
let songBrowserService: SongBrowserService;
3829

3930
beforeEach(async () => {
4031
const module: TestingModule = await Test.createTestingModule({
@@ -48,10 +39,6 @@ describe('SongController', () => {
4839
provide: FileService,
4940
useValue: mockFileService,
5041
},
51-
{
52-
provide: SongBrowserService,
53-
useValue: mockSongBrowserService,
54-
},
5542
],
5643
})
5744
.overrideGuard(AuthGuard('jwt-refresh'))
@@ -60,7 +47,6 @@ describe('SongController', () => {
6047

6148
songController = module.get<SongController>(SongController);
6249
songService = module.get<SongService>(SongService);
63-
songBrowserService = module.get<SongBrowserService>(SongBrowserService);
6450

6551
// Clear all mocks
6652
jest.clearAllMocks();
@@ -87,62 +73,51 @@ describe('SongController', () => {
8773
const query: PageQueryDTO = { page: 1, limit: 10 };
8874
const songList: SongPreviewDto[] = [];
8975

90-
mockSongBrowserService.getRecentSongs.mockResolvedValueOnce(songList);
91-
9276
const result = await songController.getSongList(query, 'featured');
9377

9478
expect(result).toEqual(songList);
95-
expect(mockSongBrowserService.getRecentSongs).toHaveBeenCalledWith(query);
9679
});
9780

9881
it('should handle recent songs', async () => {
9982
const query: PageQueryDTO = { page: 1, limit: 10 };
10083
const songList: SongPreviewDto[] = [];
10184

102-
mockSongBrowserService.getRecentSongs.mockResolvedValueOnce(songList);
10385

10486
const result = await songController.getSongList(query, 'recent');
10587

10688
expect(result).toEqual(songList);
107-
expect(mockSongBrowserService.getRecentSongs).toHaveBeenCalledWith(query);
10889
});
10990

11091
it('should return categories when q=categories without id', async () => {
11192
const query: PageQueryDTO = { page: 1, limit: 10 };
11293
const categories = { pop: 42, rock: 38 };
11394

114-
mockSongBrowserService.getCategories.mockResolvedValueOnce(categories);
11595

11696
const result = await songController.getSongList(query, 'categories');
11797

11898
expect(result).toEqual(categories);
119-
expect(mockSongBrowserService.getCategories).toHaveBeenCalled();
12099
});
121100

122101
it('should return songs by category when q=categories with id', async () => {
123102
const query: PageQueryDTO = { page: 1, limit: 10 };
124103
const songList: SongPreviewDto[] = [];
125104
const categoryId = 'pop';
126105

127-
mockSongBrowserService.getSongsByCategory.mockResolvedValueOnce(songList);
128106

129107
const result = await songController.getSongList(query, 'categories', categoryId);
130108

131109
expect(result).toEqual(songList);
132-
expect(mockSongBrowserService.getSongsByCategory).toHaveBeenCalledWith(categoryId, query);
133110
});
134111

135112
it('should return random songs', async () => {
136113
const query: PageQueryDTO = { page: 1, limit: 5 };
137114
const songList: SongPreviewDto[] = [];
138115
const category = 'electronic';
139116

140-
mockSongBrowserService.getRandomSongs.mockResolvedValueOnce(songList);
141117

142118
const result = await songController.getSongList(query, 'random', undefined, category);
143119

144120
expect(result).toEqual(songList);
145-
expect(mockSongBrowserService.getRandomSongs).toHaveBeenCalledWith(5, category);
146121
});
147122

148123
it('should throw error for invalid random count', async () => {
@@ -157,12 +132,10 @@ describe('SongController', () => {
157132
const query: PageQueryDTO = { page: 1, limit: 0 }; // limit 0 is falsy, so uses default
158133
const songList: SongPreviewDto[] = [];
159134

160-
mockSongBrowserService.getRandomSongs.mockResolvedValueOnce(songList);
161135

162136
const result = await songController.getSongList(query, 'random');
163137

164138
expect(result).toEqual(songList);
165-
expect(mockSongBrowserService.getRandomSongs).toHaveBeenCalledWith(0, undefined); // Passes 0 (nullish coalescing doesn't apply to 0)
166139
});
167140

168141
it('should throw error for invalid query mode', async () => {

0 commit comments

Comments
 (0)