Ability to get albums by genre

This commit is contained in:
simojenki
2021-03-20 10:05:31 +11:00
parent 0e3fd9d781
commit 8f5905c16f
2 changed files with 70 additions and 4 deletions

View File

@@ -530,6 +530,17 @@ function bindSmapiSoapServiceToExpress(
total,
});
});
case "genre":
return await musicLibrary.albums({ ...paging, genre: typeId }).then((result) => {
const accessToken = accessTokens.mint(authToken);
return getMetadataResult({
mediaCollection: result.results.map((it) =>
album(webAddress, accessToken, it)
),
index: paging._index,
total: result.total,
});
});
default:
throw `Unsupported id:${id}`;
}

View File

@@ -865,17 +865,24 @@ describe("api", () => {
});
describe("asking for albums", () => {
const pop1 = anAlbum({ genre: POP });
const pop2 = anAlbum({ genre: POP });
const pop3 = anAlbum({ genre: POP });
const pop4 = anAlbum({ genre: POP });
const rock1 = anAlbum({ genre: ROCK });
const rock2 = anAlbum({ genre: ROCK });
const artist1 = anArtist({
albums: [anAlbum(), anAlbum(), anAlbum()],
albums: [pop1, rock1, pop2],
});
const artist2 = anArtist({
albums: [anAlbum(), anAlbum()],
albums: [pop3, rock2],
});
const artist3 = anArtist({
albums: [],
});
const artist4 = anArtist({
albums: [anAlbum()],
albums: [pop4],
});
beforeEach(() => {
@@ -933,6 +940,54 @@ describe("api", () => {
);
});
});
describe("asking for all albums for a genre", () => {
it("should return albums for the genre", async () => {
const result = await ws.getMetadataAsync({
id: `genre:${POP.id}`,
index: 0,
count: 100,
});
expect(result[0]).toEqual(
getMetadataResult({
mediaCollection: [pop1, pop2, pop3, pop4]
.map((it) => ({
itemType: "album",
id: `album:${it.id}`,
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
})),
index: 0,
total: 4,
})
);
});
});
describe("asking for a page of albums for a genre", () => {
it("should return albums for the genre", async () => {
const result = await ws.getMetadataAsync({
id: `genre:${POP.id}`,
index: 0,
count: 2,
});
expect(result[0]).toEqual(
getMetadataResult({
mediaCollection: [pop1, pop2]
.map((it) => ({
itemType: "album",
id: `album:${it.id}`,
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
})),
index: 0,
total: 4,
})
);
});
})
});
describe("asking for tracks", () => {