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) {
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

View File

@ -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()