mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Add remove semicolons to .vscode settings, update BookFinder.test formatting
This commit is contained in:
parent
ecba67da6d
commit
80e061115f
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -16,5 +16,6 @@
|
||||
},
|
||||
"editor.formatOnSave": true,
|
||||
"editor.detectIndentation": true,
|
||||
"editor.tabSize": 2
|
||||
"editor.tabSize": 2,
|
||||
"javascript.format.semicolons": "remove"
|
||||
}
|
@ -1,23 +1,23 @@
|
||||
const sinon = require('sinon');
|
||||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
const bookFinder = require('../../../server/finders/BookFinder');
|
||||
const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
const expect = chai.expect
|
||||
const bookFinder = require('../../../server/finders/BookFinder')
|
||||
const { LogLevel } = require('../../../server/utils/constants')
|
||||
const Logger = require('../../../server/Logger')
|
||||
Logger.setLogLevel(LogLevel.INFO)
|
||||
|
||||
describe('TitleCandidates', () => {
|
||||
describe('cleanAuthor non-empty', () => {
|
||||
let titleCandidates;
|
||||
const cleanAuthor = 'leo tolstoy';
|
||||
let titleCandidates
|
||||
const cleanAuthor = 'leo tolstoy'
|
||||
|
||||
beforeEach(() => {
|
||||
titleCandidates = new bookFinder.constructor.TitleCandidates(cleanAuthor);
|
||||
});
|
||||
titleCandidates = new bookFinder.constructor.TitleCandidates(cleanAuthor)
|
||||
})
|
||||
|
||||
describe('no adds', () => {
|
||||
it('returns no candidates', () => {
|
||||
expect(titleCandidates.getCandidates()).to.deep.equal([]);
|
||||
expect(titleCandidates.getCandidates()).to.deep.equal([])
|
||||
})
|
||||
})
|
||||
|
||||
@ -40,9 +40,9 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
['does not add spaces-only candidate', ' ', []],
|
||||
['does not add empty variant', '1984', ['1984']],
|
||||
].forEach(([name, title, expected]) => it(name, () => {
|
||||
titleCandidates.add(title);
|
||||
expect(titleCandidates.getCandidates()).to.deep.equal(expected);
|
||||
}));
|
||||
titleCandidates.add(title)
|
||||
expect(titleCandidates.getCandidates()).to.deep.equal(expected)
|
||||
}))
|
||||
})
|
||||
|
||||
describe('multiple adds', () => {
|
||||
@ -53,8 +53,8 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
['dedupes candidates', ['title1', 'title1'], ['title1']],
|
||||
].forEach(([name, titles, expected]) => it(name, () => {
|
||||
for (const title of titles) titleCandidates.add(title)
|
||||
expect(titleCandidates.getCandidates()).to.deep.equal(expected);
|
||||
}));
|
||||
expect(titleCandidates.getCandidates()).to.deep.equal(expected)
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
@ -71,26 +71,26 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
['adds a candidate', 'leo tolstoy', ['leo tolstoy']],
|
||||
].forEach(([name, title, expected]) => it(name, () => {
|
||||
titleCandidates.add(title)
|
||||
expect(titleCandidates.getCandidates()).to.deep.equal(expected);
|
||||
expect(titleCandidates.getCandidates()).to.deep.equal(expected)
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('AuthorCandidates', () => {
|
||||
let authorCandidates;
|
||||
let authorCandidates
|
||||
const audnexus = {
|
||||
authorASINsRequest: sinon.stub().resolves([
|
||||
{ name: 'Leo Tolstoy' },
|
||||
{ name: 'Nikolai Gogol' },
|
||||
{ name: 'J. K. Rowling' },
|
||||
]),
|
||||
};
|
||||
}
|
||||
|
||||
describe('cleanAuthor is null', () => {
|
||||
beforeEach(() => {
|
||||
authorCandidates = new bookFinder.constructor.AuthorCandidates(null, audnexus);
|
||||
});
|
||||
authorCandidates = new bookFinder.constructor.AuthorCandidates(null, audnexus)
|
||||
})
|
||||
|
||||
describe('no adds', () => {
|
||||
[
|
||||
@ -98,7 +98,7 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
].forEach(([name, expected]) => it(name, async () => {
|
||||
expect(await authorCandidates.getCandidates()).to.deep.equal([...expected, ''])
|
||||
}))
|
||||
});
|
||||
})
|
||||
|
||||
describe('single add', () => {
|
||||
[
|
||||
@ -113,7 +113,7 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
].forEach(([name, author, expected]) => it(name, async () => {
|
||||
authorCandidates.add(author)
|
||||
expect(await authorCandidates.getCandidates()).to.deep.equal([...expected, ''])
|
||||
}));
|
||||
}))
|
||||
})
|
||||
|
||||
describe('multi add', () => {
|
||||
@ -125,14 +125,14 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
expect(await authorCandidates.getCandidates()).to.deep.equal([...expected, ''])
|
||||
}))
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
describe('cleanAuthor is a recognized author', () => {
|
||||
const cleanAuthor = 'leo tolstoy';
|
||||
const cleanAuthor = 'leo tolstoy'
|
||||
|
||||
beforeEach(() => {
|
||||
authorCandidates = new bookFinder.constructor.AuthorCandidates(cleanAuthor, audnexus);
|
||||
});
|
||||
authorCandidates = new bookFinder.constructor.AuthorCandidates(cleanAuthor, audnexus)
|
||||
})
|
||||
|
||||
describe('no adds', () => {
|
||||
[
|
||||
@ -151,14 +151,14 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
expect(await authorCandidates.getCandidates()).to.deep.equal([...expected, ''])
|
||||
}))
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
describe('cleanAuthor is an unrecognized author', () => {
|
||||
const cleanAuthor = 'Fyodor Dostoevsky';
|
||||
const cleanAuthor = 'Fyodor Dostoevsky'
|
||||
|
||||
beforeEach(() => {
|
||||
authorCandidates = new bookFinder.constructor.AuthorCandidates(cleanAuthor, audnexus);
|
||||
});
|
||||
authorCandidates = new bookFinder.constructor.AuthorCandidates(cleanAuthor, audnexus)
|
||||
})
|
||||
|
||||
describe('no adds', () => {
|
||||
[
|
||||
@ -177,7 +177,7 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
expect(await authorCandidates.getCandidates()).to.deep.equal([...expected, ''])
|
||||
}))
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
describe('cleanAuthor is unrecognized and dirty', () => {
|
||||
describe('no adds', () => {
|
||||
@ -199,40 +199,40 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
expect(await authorCandidates.getCandidates()).to.deep.equal([...expected, ''])
|
||||
}))
|
||||
})
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
describe('search', () => {
|
||||
const t = 'title';
|
||||
const a = 'author';
|
||||
const u = 'unrecognized';
|
||||
const r = ['book'];
|
||||
const t = 'title'
|
||||
const a = 'author'
|
||||
const u = 'unrecognized'
|
||||
const r = ['book']
|
||||
|
||||
const runSearchStub = sinon.stub(bookFinder, 'runSearch')
|
||||
runSearchStub.resolves([])
|
||||
runSearchStub.withArgs(t, a).resolves(r);
|
||||
runSearchStub.withArgs(t, u).resolves(r);
|
||||
runSearchStub.withArgs(t, a).resolves(r)
|
||||
runSearchStub.withArgs(t, u).resolves(r)
|
||||
|
||||
const audnexusStub = sinon.stub(bookFinder.audnexus, 'authorASINsRequest')
|
||||
audnexusStub.resolves([{ name: a }])
|
||||
|
||||
beforeEach(() => {
|
||||
bookFinder.runSearch.resetHistory();
|
||||
});
|
||||
bookFinder.runSearch.resetHistory()
|
||||
})
|
||||
|
||||
describe('search title is empty', () => {
|
||||
it('returns empty result', async () => {
|
||||
expect(await bookFinder.search('', '', a)).to.deep.equal([]);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 0);
|
||||
});
|
||||
});
|
||||
expect(await bookFinder.search('', '', a)).to.deep.equal([])
|
||||
sinon.assert.callCount(bookFinder.runSearch, 0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('search title is a recognized title and search author is a recognized author', () => {
|
||||
it('returns non-empty result (no fuzzy searches)', async () => {
|
||||
expect(await bookFinder.search('', t, a)).to.deep.equal(r);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 1);
|
||||
});
|
||||
});
|
||||
expect(await bookFinder.search('', t, a)).to.deep.equal(r)
|
||||
sinon.assert.callCount(bookFinder.runSearch, 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('search title contains recognized title and search author is a recognized author', () => {
|
||||
[
|
||||
@ -251,9 +251,9 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
[`2022_${t}_HQ`],
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '${a}') returns non-empty result (with 1 fuzzy search)`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, a)).to.deep.equal(r);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 2);
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, a)).to.deep.equal(r)
|
||||
sinon.assert.callCount(bookFinder.runSearch, 2)
|
||||
})
|
||||
});
|
||||
|
||||
[
|
||||
@ -261,9 +261,9 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
[`${a} - series 01 - ${t}`],
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '${a}') returns non-empty result (with 2 fuzzy searches)`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, a)).to.deep.equal(r);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 3);
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, a)).to.deep.equal(r)
|
||||
sinon.assert.callCount(bookFinder.runSearch, 3)
|
||||
})
|
||||
});
|
||||
|
||||
[
|
||||
@ -271,20 +271,20 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
[`${t} junk`],
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '${a}') returns an empty result`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, a)).to.deep.equal([]);
|
||||
});
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, a)).to.deep.equal([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('maxFuzzySearches = 0', () => {
|
||||
[
|
||||
[`${t} - ${a}`],
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '${a}') returns an empty result (with no fuzzy searches)`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, a, null, null, { maxFuzzySearches: 0 })).to.deep.equal([]);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, a, null, null, { maxFuzzySearches: 0 })).to.deep.equal([])
|
||||
sinon.assert.callCount(bookFinder.runSearch, 1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('maxFuzzySearches = 1', () => {
|
||||
[
|
||||
@ -292,12 +292,12 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
[`${a} - series 01 - ${t}`],
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '${a}') returns an empty result (1 fuzzy search)`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, a, null, null, { maxFuzzySearches: 1 })).to.deep.equal([]);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, a, null, null, { maxFuzzySearches: 1 })).to.deep.equal([])
|
||||
sinon.assert.callCount(bookFinder.runSearch, 2)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('search title contains recognized title and search author is empty', () => {
|
||||
[
|
||||
@ -305,9 +305,9 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
[`${a} - ${t}`],
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '') returns a non-empty result (1 fuzzy search)`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, '')).to.deep.equal(r);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 2);
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, '')).to.deep.equal(r)
|
||||
sinon.assert.callCount(bookFinder.runSearch, 2)
|
||||
})
|
||||
});
|
||||
|
||||
[
|
||||
@ -316,10 +316,10 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
[`${u} - ${t}`]
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '') returns an empty result`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, '')).to.deep.equal([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, '')).to.deep.equal([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('search title contains recognized title and search author is an unrecognized author', () => {
|
||||
[
|
||||
@ -327,18 +327,18 @@ Logger.setLogLevel(LogLevel.INFO)
|
||||
[`${u} - ${t}`]
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '${u}') returns a non-empty result (1 fuzzy search)`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, u)).to.deep.equal(r);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 2);
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, u)).to.deep.equal(r)
|
||||
sinon.assert.callCount(bookFinder.runSearch, 2)
|
||||
})
|
||||
});
|
||||
|
||||
[
|
||||
[`${t}`]
|
||||
].forEach(([searchTitle]) => {
|
||||
it(`search('${searchTitle}', '${u}') returns a non-empty result (no fuzzy search)`, async () => {
|
||||
expect(await bookFinder.search('', searchTitle, u)).to.deep.equal(r);
|
||||
sinon.assert.callCount(bookFinder.runSearch, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(await bookFinder.search('', searchTitle, u)).to.deep.equal(r)
|
||||
sinon.assert.callCount(bookFinder.runSearch, 1)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user