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