|
| 1 | +const Path = require('path') |
| 2 | +const chai = require('chai') |
| 3 | +const expect = chai.expect |
| 4 | +const scanUtils = require('../../../server/utils/scandir') |
| 5 | + |
| 6 | +describe('scanUtils', async () => { |
| 7 | + it('should properly group files into potential book library items', async () => { |
| 8 | + global.isWin = process.platform === 'win32' |
| 9 | + global.ServerSettings = { |
| 10 | + scannerParseSubtitle: true |
| 11 | + } |
| 12 | + |
| 13 | + const filePaths = [ |
| 14 | + 'randomfile.txt', // Should be ignored because it's not a book media file |
| 15 | + 'Book1.m4b', // Root single file audiobook |
| 16 | + 'Book2/audiofile.m4b', |
| 17 | + 'Book2/disk 001/audiofile.m4b', |
| 18 | + 'Book2/disk 002/audiofile.m4b', |
| 19 | + 'Author/Book3/audiofile.mp3', |
| 20 | + 'Author/Book3/Disc 1/audiofile.mp3', |
| 21 | + 'Author/Book3/Disc 2/audiofile.mp3', |
| 22 | + 'Author/Series/Book4/cover.jpg', |
| 23 | + 'Author/Series/Book4/CD1/audiofile.mp3', |
| 24 | + 'Author/Series/Book4/CD2/audiofile.mp3', |
| 25 | + 'Author/Series2/Book5/deeply/nested/cd 01/audiofile.mp3', |
| 26 | + 'Author/Series2/Book5/deeply/nested/cd 02/audiofile.mp3', |
| 27 | + 'Author/Series2/Book5/randomfile.js' // Should be ignored because it's not a book media file |
| 28 | + ] |
| 29 | + |
| 30 | + // Create fileItems to match the format of fileUtils.recurseFiles |
| 31 | + const fileItems = [] |
| 32 | + for (const filePath of filePaths) { |
| 33 | + const dirname = Path.dirname(filePath) |
| 34 | + fileItems.push({ |
| 35 | + name: Path.basename(filePath), |
| 36 | + reldirpath: dirname === '.' ? '' : dirname, |
| 37 | + extension: Path.extname(filePath), |
| 38 | + deep: filePath.split('/').length - 1 |
| 39 | + }) |
| 40 | + } |
| 41 | + |
| 42 | + const libraryItemGrouping = scanUtils.groupFileItemsIntoLibraryItemDirs('book', fileItems, false) |
| 43 | + |
| 44 | + expect(libraryItemGrouping).to.deep.equal({ |
| 45 | + 'Book1.m4b': 'Book1.m4b', |
| 46 | + Book2: ['audiofile.m4b', 'disk 001/audiofile.m4b', 'disk 002/audiofile.m4b'], |
| 47 | + 'Author/Book3': ['audiofile.mp3', 'Disc 1/audiofile.mp3', 'Disc 2/audiofile.mp3'], |
| 48 | + 'Author/Series/Book4': ['CD1/audiofile.mp3', 'CD2/audiofile.mp3', 'cover.jpg'], |
| 49 | + 'Author/Series2/Book5/deeply/nested': ['cd 01/audiofile.mp3', 'cd 02/audiofile.mp3'] |
| 50 | + }) |
| 51 | + }) |
| 52 | +}) |
0 commit comments