Fix bug where no genres caused error

This commit is contained in:
simojenki
2021-08-29 08:14:23 +10:00
parent 543d352204
commit e2e73209a2
2 changed files with 24 additions and 1 deletions

View File

@@ -537,7 +537,7 @@ export class Navidrome implements MusicService {
.getJSON<GenGenresResponse>(credentials, "/rest/getGenres")
.then((it) =>
pipe(
it.genres.genre,
it.genres.genre || [],
A.map((it) => it.__text),
A.sort(ordString),
A.map((it) => ({ id: it, name: it }))

View File

@@ -453,6 +453,29 @@ describe("Navidrome", () => {
});
describe("getting genres", () => {
describe("when there are none", () => {
beforeEach(() => {
mockGET
.mockImplementationOnce(() => Promise.resolve(ok(PING_OK)))
.mockImplementationOnce(() => Promise.resolve(ok(genresXml([]))));
});
it("should return them alphabetically sorted", async () => {
const result = await navidrome
.generateToken({ username, password })
.then((it) => it as AuthSuccess)
.then((it) => navidrome.login(it.authToken))
.then((it) => it.genres());
expect(result).toEqual([]);
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getGenres`, {
params: asURLSearchParams(authParams),
headers,
});
});
});
describe("when there is only 1", () => {
const genres = ["genre1"];