@@ -136,4 +136,67 @@ describe("request service", () => {
136136 lidarrAlbumId : 99
137137 } ) ;
138138 } ) ;
139+
140+ it ( "monitors existing unmonitored albums and marks request as SUBMITTED, not ALREADY_EXISTS" , async ( ) => {
141+ prismaRequest . findFirst . mockResolvedValue ( null ) ;
142+ prismaRequest . create . mockResolvedValueOnce ( {
143+ id : "request-2" ,
144+ requestType : RequestType . ALBUM ,
145+ artistName : "U2" ,
146+ albumTitle : "War" ,
147+ status : RequestStatus . APPROVED
148+ } ) ;
149+ prismaRequest . update . mockImplementation ( async ( { data } : { data : Record < string , unknown > } ) => ( {
150+ id : "request-2" ,
151+ requestType : RequestType . ALBUM ,
152+ ...data
153+ } ) ) ;
154+
155+ getRuntimeConfig . mockResolvedValue ( {
156+ lidarrUrl : "http://lidarr" ,
157+ lidarrApiKey : "test-key" ,
158+ requestAutoApprove : true
159+ } ) ;
160+
161+ clientInstance . getExistingArtistByForeignId . mockResolvedValue ( {
162+ id : 41 ,
163+ artistName : "U2" ,
164+ foreignArtistId : "artist-u2"
165+ } ) ;
166+
167+ clientInstance . getEffectiveAddDefaults . mockResolvedValue ( {
168+ rootFolderPath : "/music" ,
169+ qualityProfileId : 7 ,
170+ metadataProfileId : 3
171+ } ) ;
172+
173+ clientInstance . getExistingAlbumByForeignId . mockResolvedValue ( {
174+ id : 99 ,
175+ title : "War" ,
176+ foreignAlbumId : "album-war" ,
177+ monitored : false
178+ } ) ;
179+
180+ clientInstance . setAlbumsMonitored . mockResolvedValue ( undefined ) ;
181+ clientInstance . triggerAlbumSearch . mockResolvedValue ( undefined ) ;
182+
183+ const { createAlbumRequest } = await import ( "../lib/requests/service" ) ;
184+ const result = await createAlbumRequest ( {
185+ requestedById : "user-1" ,
186+ artistName : "U2" ,
187+ albumTitle : "War" ,
188+ foreignArtistId : "artist-u2" ,
189+ foreignAlbumId : "album-war"
190+ } ) ;
191+
192+ // We shouldn't add an artist because getExistingAlbumByForeignId succeeds and returns early
193+ expect ( clientInstance . addArtist ) . not . toHaveBeenCalled ( ) ;
194+ expect ( clientInstance . setAlbumsMonitored ) . toHaveBeenCalledWith ( [ 99 ] , true ) ;
195+ expect ( clientInstance . triggerAlbumSearch ) . toHaveBeenCalledWith ( [ 99 ] ) ;
196+ expect ( result . request ) . toMatchObject ( {
197+ status : RequestStatus . SUBMITTED ,
198+ lidarrArtistId : 41 ,
199+ lidarrAlbumId : 99
200+ } ) ;
201+ } ) ;
139202} ) ;
0 commit comments