diff --git a/server/routes/request.test.ts b/server/routes/request.test.ts index f41ed710e..2c88e8420 100644 --- a/server/routes/request.test.ts +++ b/server/routes/request.test.ts @@ -339,6 +339,75 @@ describe('PUT /request/:requestId (movie)', () => { }); }); +describe('PUT /request/:requestId (tv)', () => { + it('does not add a season held by another request', async () => { + const userRepo = getRepository(User); + const mediaRepo = getRepository(Media); + const requestRepo = getRepository(MediaRequest); + + const owner = await userRepo.findOneOrFail({ + where: { email: 'admin@seerr.dev' }, + }); + const otherUser = await userRepo.findOneOrFail({ + where: { email: 'friend@seerr.dev' }, + }); + + const media = await mediaRepo.save( + new Media({ + mediaType: MediaType.TV, + tmdbId: 67890, + status: MediaStatus.PENDING, + status4k: MediaStatus.UNKNOWN, + }) + ); + + const seedTvRequest = (requestedBy: User, seasons: number[]) => + requestRepo.save( + new MediaRequest({ + type: MediaType.TV, + status: MediaRequestStatus.PENDING, + media, + requestedBy, + is4k: false, + seasons: seasons.map( + (seasonNumber) => + new SeasonRequest({ + seasonNumber, + status: MediaRequestStatus.PENDING, + }) + ), + }) + ); + + const mediaRequest = await seedTvRequest(owner, [1, 2]); + const otherRequest = await seedTvRequest(otherUser, [3]); + + const agent = await loginAs('admin@seerr.dev', 'test1234'); + const res = await agent.put(`/request/${mediaRequest.id}`).send({ + mediaType: MediaType.TV, + seasons: [1, 2, 3], + }); + + assert.strictEqual(res.status, 200); + + const saved = await requestRepo.findOneOrFail({ + where: { id: mediaRequest.id }, + }); + assert.deepStrictEqual( + saved.seasons.map((s) => s.seasonNumber).sort((a, b) => a - b), + [1, 2] + ); + + const otherSaved = await requestRepo.findOneOrFail({ + where: { id: otherRequest.id }, + }); + assert.deepStrictEqual( + otherSaved.seasons.map((s) => s.seasonNumber), + [3] + ); + }); +}); + describe('POST /request/:requestId/:status', () => { const cases = [ { action: 'approve', expected: MediaRequestStatus.APPROVED }, diff --git a/server/routes/request.ts b/server/routes/request.ts index 871f23181..9ee569739 100644 --- a/server/routes/request.ts +++ b/server/routes/request.ts @@ -571,7 +571,7 @@ requestRoutes.put<{ requestId: string }>( }); } - const newSeasons = requestedSeasons.filter( + const newSeasons = filteredSeasons.filter( (sn) => !request.seasons.map((s) => s.seasonNumber).includes(sn) );