From eb853d9f0919735c9c0f23663e9b1b195801480c Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 2 Jan 2025 15:51:21 -0600 Subject: [PATCH] Fix LibraryItemController unit test --- server/controllers/LibraryItemController.js | 2 +- .../server/controllers/LibraryItemController.test.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index f1d11c15..b187d2b6 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -1144,7 +1144,7 @@ class LibraryItemController { */ async middleware(req, res, next) { req.libraryItem = await Database.libraryItemModel.getExpandedById(req.params.id) - req.oldLibraryItem = await Database.libraryItemModel.getOldLibraryItem(req.libraryItem) + req.oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(req.libraryItem) if (!req.libraryItem?.media) return res.sendStatus(404) // Check user can access this library item diff --git a/test/server/controllers/LibraryItemController.test.js b/test/server/controllers/LibraryItemController.test.js index 3fcd1cf8..846dd891 100644 --- a/test/server/controllers/LibraryItemController.test.js +++ b/test/server/controllers/LibraryItemController.test.js @@ -82,11 +82,13 @@ describe('LibraryItemController', () => { }) it('should remove authors and series with no books on library item delete', async () => { - const oldLibraryItem = await Database.libraryItemModel.getOldById(libraryItem1Id) + const libraryItem = await Database.libraryItemModel.getExpandedById(libraryItem1Id) + const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem) const fakeReq = { query: {}, - libraryItem: oldLibraryItem + libraryItem, + oldLibraryItem } const fakeRes = { sendStatus: sinon.spy() @@ -156,7 +158,8 @@ describe('LibraryItemController', () => { }) it('should remove authors and series with no books on library item update media', async () => { - const oldLibraryItem = await Database.libraryItemModel.getOldById(libraryItem1Id) + const libraryItem = await Database.libraryItemModel.getExpandedById(libraryItem1Id) + const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem) // Update library item 1 remove all authors and series const fakeReq = { @@ -167,7 +170,8 @@ describe('LibraryItemController', () => { series: [] } }, - libraryItem: oldLibraryItem + libraryItem, + oldLibraryItem } const fakeRes = { json: sinon.spy()