@@ -7,7 +7,6 @@ import { Response } from 'express';
7
7
8
8
import { FileService } from '../file/file.service' ;
9
9
10
- import { SongBrowserService } from './song-browser/song-browser.service' ;
11
10
import { SongController } from './song.controller' ;
12
11
import { SongService } from './song.service' ;
13
12
@@ -24,17 +23,9 @@ const mockSongService = {
24
23
25
24
const mockFileService = { } ;
26
25
27
- const mockSongBrowserService = {
28
- getRecentSongs : jest . fn ( ) ,
29
- getCategories : jest . fn ( ) ,
30
- getSongsByCategory : jest . fn ( ) ,
31
- getRandomSongs : jest . fn ( ) ,
32
- } ;
33
-
34
26
describe ( 'SongController' , ( ) => {
35
27
let songController : SongController ;
36
28
let songService : SongService ;
37
- let songBrowserService : SongBrowserService ;
38
29
39
30
beforeEach ( async ( ) => {
40
31
const module : TestingModule = await Test . createTestingModule ( {
@@ -48,10 +39,6 @@ describe('SongController', () => {
48
39
provide : FileService ,
49
40
useValue : mockFileService ,
50
41
} ,
51
- {
52
- provide : SongBrowserService ,
53
- useValue : mockSongBrowserService ,
54
- } ,
55
42
] ,
56
43
} )
57
44
. overrideGuard ( AuthGuard ( 'jwt-refresh' ) )
@@ -60,7 +47,6 @@ describe('SongController', () => {
60
47
61
48
songController = module . get < SongController > ( SongController ) ;
62
49
songService = module . get < SongService > ( SongService ) ;
63
- songBrowserService = module . get < SongBrowserService > ( SongBrowserService ) ;
64
50
65
51
// Clear all mocks
66
52
jest . clearAllMocks ( ) ;
@@ -87,62 +73,51 @@ describe('SongController', () => {
87
73
const query : PageQueryDTO = { page : 1 , limit : 10 } ;
88
74
const songList : SongPreviewDto [ ] = [ ] ;
89
75
90
- mockSongBrowserService . getRecentSongs . mockResolvedValueOnce ( songList ) ;
91
-
92
76
const result = await songController . getSongList ( query , 'featured' ) ;
93
77
94
78
expect ( result ) . toEqual ( songList ) ;
95
- expect ( mockSongBrowserService . getRecentSongs ) . toHaveBeenCalledWith ( query ) ;
96
79
} ) ;
97
80
98
81
it ( 'should handle recent songs' , async ( ) => {
99
82
const query : PageQueryDTO = { page : 1 , limit : 10 } ;
100
83
const songList : SongPreviewDto [ ] = [ ] ;
101
84
102
- mockSongBrowserService . getRecentSongs . mockResolvedValueOnce ( songList ) ;
103
85
104
86
const result = await songController . getSongList ( query , 'recent' ) ;
105
87
106
88
expect ( result ) . toEqual ( songList ) ;
107
- expect ( mockSongBrowserService . getRecentSongs ) . toHaveBeenCalledWith ( query ) ;
108
89
} ) ;
109
90
110
91
it ( 'should return categories when q=categories without id' , async ( ) => {
111
92
const query : PageQueryDTO = { page : 1 , limit : 10 } ;
112
93
const categories = { pop : 42 , rock : 38 } ;
113
94
114
- mockSongBrowserService . getCategories . mockResolvedValueOnce ( categories ) ;
115
95
116
96
const result = await songController . getSongList ( query , 'categories' ) ;
117
97
118
98
expect ( result ) . toEqual ( categories ) ;
119
- expect ( mockSongBrowserService . getCategories ) . toHaveBeenCalled ( ) ;
120
99
} ) ;
121
100
122
101
it ( 'should return songs by category when q=categories with id' , async ( ) => {
123
102
const query : PageQueryDTO = { page : 1 , limit : 10 } ;
124
103
const songList : SongPreviewDto [ ] = [ ] ;
125
104
const categoryId = 'pop' ;
126
105
127
- mockSongBrowserService . getSongsByCategory . mockResolvedValueOnce ( songList ) ;
128
106
129
107
const result = await songController . getSongList ( query , 'categories' , categoryId ) ;
130
108
131
109
expect ( result ) . toEqual ( songList ) ;
132
- expect ( mockSongBrowserService . getSongsByCategory ) . toHaveBeenCalledWith ( categoryId , query ) ;
133
110
} ) ;
134
111
135
112
it ( 'should return random songs' , async ( ) => {
136
113
const query : PageQueryDTO = { page : 1 , limit : 5 } ;
137
114
const songList : SongPreviewDto [ ] = [ ] ;
138
115
const category = 'electronic' ;
139
116
140
- mockSongBrowserService . getRandomSongs . mockResolvedValueOnce ( songList ) ;
141
117
142
118
const result = await songController . getSongList ( query , 'random' , undefined , category ) ;
143
119
144
120
expect ( result ) . toEqual ( songList ) ;
145
- expect ( mockSongBrowserService . getRandomSongs ) . toHaveBeenCalledWith ( 5 , category ) ;
146
121
} ) ;
147
122
148
123
it ( 'should throw error for invalid random count' , async ( ) => {
@@ -157,12 +132,10 @@ describe('SongController', () => {
157
132
const query : PageQueryDTO = { page : 1 , limit : 0 } ; // limit 0 is falsy, so uses default
158
133
const songList : SongPreviewDto [ ] = [ ] ;
159
134
160
- mockSongBrowserService . getRandomSongs . mockResolvedValueOnce ( songList ) ;
161
135
162
136
const result = await songController . getSongList ( query , 'random' ) ;
163
137
164
138
expect ( result ) . toEqual ( songList ) ;
165
- expect ( mockSongBrowserService . getRandomSongs ) . toHaveBeenCalledWith ( 0 , undefined ) ; // Passes 0 (nullish coalescing doesn't apply to 0)
166
139
} ) ;
167
140
168
141
it ( 'should throw error for invalid query mode' , async ( ) => {
0 commit comments