Handling failure to fetch images explicitly and returning 500

This commit is contained in:
simojenki
2021-04-17 14:00:35 +10:00
parent e2692126f4
commit a81e6c931b
2 changed files with 43 additions and 6 deletions

View File

@@ -553,7 +553,7 @@ describe("server", () => {
describe("when there is a valid access token", () => {
describe("some invalid art type", () => {
it("should return the image and a 200", async () => {
it("should return a 400", async () => {
const res = await request(server)
.get(
`/foo/${albumId}/art/size/180?${BONOB_ACCESS_TOKEN_HEADER}=${accessToken}`
@@ -605,7 +605,23 @@ describe("server", () => {
expect(res.status).toEqual(404);
});
});
});
describe("when there is an error", () => {
it("should return a 500", async () => {
musicService.login.mockResolvedValue(musicLibrary);
musicLibrary.coverArt.mockRejectedValue("Boom")
const res = await request(server)
.get(
`/artist/${albumId}/art/size/180?${BONOB_ACCESS_TOKEN_HEADER}=${accessToken}`
)
.set(BONOB_ACCESS_TOKEN_HEADER, accessToken);
expect(res.status).toEqual(500);
});
});
});
describe("album art", () => {
@@ -648,6 +664,21 @@ describe("server", () => {
expect(res.status).toEqual(404);
});
});
describe("when there is an error", () => {
it("should return a 500", async () => {
musicService.login.mockResolvedValue(musicLibrary);
musicLibrary.coverArt.mockRejectedValue("Boooooom")
const res = await request(server)
.get(
`/album/${albumId}/art/size/180?${BONOB_ACCESS_TOKEN_HEADER}=${accessToken}`
)
.set(BONOB_ACCESS_TOKEN_HEADER, accessToken);
expect(res.status).toEqual(500);
});
});
});
});
});