Fix LibraryItemController unit test

This commit is contained in:
advplyr 2025-01-02 15:51:21 -06:00
parent 4787e7fdb5
commit eb853d9f09
2 changed files with 9 additions and 5 deletions

View File

@ -1144,7 +1144,7 @@ class LibraryItemController {
*/ */
async middleware(req, res, next) { async middleware(req, res, next) {
req.libraryItem = await Database.libraryItemModel.getExpandedById(req.params.id) 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) if (!req.libraryItem?.media) return res.sendStatus(404)
// Check user can access this library item // Check user can access this library item

View File

@ -82,11 +82,13 @@ describe('LibraryItemController', () => {
}) })
it('should remove authors and series with no books on library item delete', async () => { 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 = { const fakeReq = {
query: {}, query: {},
libraryItem: oldLibraryItem libraryItem,
oldLibraryItem
} }
const fakeRes = { const fakeRes = {
sendStatus: sinon.spy() sendStatus: sinon.spy()
@ -156,7 +158,8 @@ describe('LibraryItemController', () => {
}) })
it('should remove authors and series with no books on library item update media', async () => { 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 // Update library item 1 remove all authors and series
const fakeReq = { const fakeReq = {
@ -167,7 +170,8 @@ describe('LibraryItemController', () => {
series: [] series: []
} }
}, },
libraryItem: oldLibraryItem libraryItem,
oldLibraryItem
} }
const fakeRes = { const fakeRes = {
json: sinon.spy() json: sinon.spy()