Catch unhandled io errors in subsonic (#75)

This commit is contained in:
Simon J
2021-11-08 17:20:50 +11:00
committed by GitHub
parent 9851ee46b3
commit c804627a0a
2 changed files with 32 additions and 1 deletions

View File

@@ -2756,11 +2756,15 @@ describe("Subsonic", () => {
});
describe("navidrome returns something other than a 200", () => {
it("should return the content", async () => {
it("should fail", async () => {
const trackId = "track123";
const streamResponse = {
status: 400,
headers: {
'content-type': 'text/html',
'content-length': '33'
}
};
mockGET
@@ -2783,6 +2787,31 @@ describe("Subsonic", () => {
).rejects.toEqual(`Subsonic failed with a 400 status`);
});
});
describe("io exception occurs", () => {
it("should fail", async () => {
const trackId = "track123";
mockGET
.mockImplementationOnce(() => Promise.resolve(ok(PING_OK)))
.mockImplementationOnce(() =>
Promise.resolve(ok(getSongJson(track)))
)
.mockImplementationOnce(() =>
Promise.resolve(ok(getAlbumJson(artist, album, [])))
)
.mockImplementationOnce(() => Promise.reject("IO error occured"));
const musicLibrary = await navidrome
.generateToken({ username, password })
.then((it) => it as AuthSuccess)
.then((it) => navidrome.login(it.authToken));
return expect(
musicLibrary.stream({ trackId, range: undefined })
).rejects.toEqual(`Subsonic failed with: IO error occured`);
});
});
});
describe("with range specified", () => {