mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Ability to see TopRated/starred albums (#63)
This commit is contained in:
@@ -977,6 +977,12 @@ describe("api", () => {
|
||||
albumArtURI: iconArtURI(bonobUrl, "heart").href(),
|
||||
itemType: "albumList",
|
||||
},
|
||||
{
|
||||
id: "starredAlbums",
|
||||
title: "Top Rated",
|
||||
albumArtURI: iconArtURI(bonobUrl, "star").href(),
|
||||
itemType: "albumList",
|
||||
},
|
||||
{
|
||||
id: "playlists",
|
||||
title: "Playlists",
|
||||
@@ -1064,6 +1070,12 @@ describe("api", () => {
|
||||
albumArtURI: iconArtURI(bonobUrl, "heart").href(),
|
||||
itemType: "albumList",
|
||||
},
|
||||
{
|
||||
id: "starredAlbums",
|
||||
title: "Best beoordeeld",
|
||||
albumArtURI: iconArtURI(bonobUrl, "star").href(),
|
||||
itemType: "albumList",
|
||||
},
|
||||
{
|
||||
id: "playlists",
|
||||
title: "Afspeellijsten",
|
||||
@@ -1705,6 +1717,54 @@ describe("api", () => {
|
||||
})
|
||||
);
|
||||
|
||||
expect(musicLibrary.albums).toHaveBeenCalledWith({
|
||||
type: "favourited",
|
||||
_index: paging.index,
|
||||
_count: paging.count,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("asking for starred albums", () => {
|
||||
const albums = [rock2, rock1, pop2];
|
||||
|
||||
beforeEach(() => {
|
||||
musicLibrary.albums.mockResolvedValue({
|
||||
results: albums,
|
||||
total: allAlbums.length,
|
||||
});
|
||||
});
|
||||
|
||||
it("should return some", async () => {
|
||||
const paging = {
|
||||
index: 0,
|
||||
count: 100,
|
||||
};
|
||||
|
||||
const result = await ws.getMetadataAsync({
|
||||
id: "starredAlbums",
|
||||
...paging,
|
||||
});
|
||||
|
||||
expect(result[0]).toEqual(
|
||||
getMetadataResult({
|
||||
mediaCollection: albums.map((it) => ({
|
||||
itemType: "album",
|
||||
id: `album:${it.id}`,
|
||||
title: it.name,
|
||||
albumArtURI: defaultAlbumArtURI(
|
||||
bonobUrlWithAccessToken,
|
||||
it
|
||||
).href(),
|
||||
canPlay: true,
|
||||
artistId: `artist:${it.artistId}`,
|
||||
artist: it.artistName,
|
||||
})),
|
||||
index: 0,
|
||||
total: 6,
|
||||
})
|
||||
);
|
||||
|
||||
expect(musicLibrary.albums).toHaveBeenCalledWith({
|
||||
type: "starred",
|
||||
_index: paging.index,
|
||||
@@ -1754,7 +1814,7 @@ describe("api", () => {
|
||||
);
|
||||
|
||||
expect(musicLibrary.albums).toHaveBeenCalledWith({
|
||||
type: "recent",
|
||||
type: "recentlyPlayed",
|
||||
_index: paging.index,
|
||||
_count: paging.count,
|
||||
});
|
||||
@@ -1802,7 +1862,7 @@ describe("api", () => {
|
||||
);
|
||||
|
||||
expect(musicLibrary.albums).toHaveBeenCalledWith({
|
||||
type: "frequent",
|
||||
type: "mostPlayed",
|
||||
_index: paging.index,
|
||||
_count: paging.count,
|
||||
});
|
||||
@@ -1850,7 +1910,7 @@ describe("api", () => {
|
||||
);
|
||||
|
||||
expect(musicLibrary.albums).toHaveBeenCalledWith({
|
||||
type: "newest",
|
||||
type: "recentlyAdded",
|
||||
_index: paging.index,
|
||||
_count: paging.count,
|
||||
});
|
||||
|
||||
@@ -266,7 +266,7 @@ const maybeIdFromCoverArtId = (coverArt: string | undefined) =>
|
||||
coverArt ? splitCoverArtId(coverArt)[1] : "";
|
||||
|
||||
const asAlbumJson = (
|
||||
artist: Artist,
|
||||
artist: { id: string | undefined, name: string | undefined },
|
||||
album: AlbumSummary,
|
||||
tracks: Track[] = []
|
||||
) => ({
|
||||
@@ -353,9 +353,9 @@ const getAlbumJson = (artist: Artist, album: Album, tracks: Track[]) =>
|
||||
|
||||
const getSongJson = (track: Track) => subsonicOK({ song: asSongJson(track) });
|
||||
|
||||
// const getStarredJson = ({ songIds }: { songIds: string[] }) => subsonicOK({starred2: {
|
||||
// album: [],
|
||||
// song: songIds.map((id) => ({ id })),
|
||||
// const getStarredJson = ({ albums }: { albums: Album[] }) => subsonicOK({starred2: {
|
||||
// album: albums.map(it => asAlbumJson({ id: it.artistId, name: it.artistName }, it, [])),
|
||||
// song: [],
|
||||
// }})
|
||||
|
||||
const subsonicOK = (body: any = {}) => ({
|
||||
@@ -1389,11 +1389,13 @@ describe("Subsonic", () => {
|
||||
|
||||
describe("getting albums", () => {
|
||||
describe("filtering", () => {
|
||||
const album1 = anAlbum({ genre: asGenre("Pop") });
|
||||
const album2 = anAlbum({ genre: asGenre("Rock") });
|
||||
const album3 = anAlbum({ genre: asGenre("Pop") });
|
||||
const album1 = anAlbum({ id: "album1", genre: asGenre("Pop") });
|
||||
const album2 = anAlbum({ id: "album2", genre: asGenre("Rock") });
|
||||
const album3 = anAlbum({ id: "album3", genre: asGenre("Pop") });
|
||||
const album4 = anAlbum({ id: "album4", genre: asGenre("Pop") });
|
||||
const album5 = anAlbum({ id: "album5", genre: asGenre("Pop") });
|
||||
|
||||
const artist = anArtist({ albums: [album1, album2, album3] });
|
||||
const artist = anArtist({ albums: [album1, album2, album3, album4, album5] });
|
||||
|
||||
describe("by genre", () => {
|
||||
beforeEach(() => {
|
||||
@@ -1472,7 +1474,7 @@ describe("Subsonic", () => {
|
||||
});
|
||||
|
||||
it("should pass the filter to navidrome", async () => {
|
||||
const q: AlbumQuery = { _index: 0, _count: 100, type: "newest" };
|
||||
const q: AlbumQuery = { _index: 0, _count: 100, type: "recentlyAdded" };
|
||||
const result = await navidrome
|
||||
.generateToken({ username, password })
|
||||
.then((it) => it as AuthSuccess)
|
||||
@@ -1522,7 +1524,7 @@ describe("Subsonic", () => {
|
||||
});
|
||||
|
||||
it("should pass the filter to navidrome", async () => {
|
||||
const q: AlbumQuery = { _index: 0, _count: 100, type: "recent" };
|
||||
const q: AlbumQuery = { _index: 0, _count: 100, type: "recentlyPlayed" };
|
||||
const result = await navidrome
|
||||
.generateToken({ username, password })
|
||||
.then((it) => it as AuthSuccess)
|
||||
@@ -1567,7 +1569,7 @@ describe("Subsonic", () => {
|
||||
});
|
||||
|
||||
it("should pass the filter to navidrome", async () => {
|
||||
const q: AlbumQuery = { _index: 0, _count: 100, type: "frequent" };
|
||||
const q: AlbumQuery = { _index: 0, _count: 100, type: "mostPlayed" };
|
||||
const result = await navidrome
|
||||
.generateToken({ username, password })
|
||||
.then((it) => it as AuthSuccess)
|
||||
@@ -1595,6 +1597,51 @@ describe("Subsonic", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("by starred", () => {
|
||||
beforeEach(() => {
|
||||
mockGET
|
||||
.mockImplementationOnce(() => Promise.resolve(ok(PING_OK)))
|
||||
.mockImplementationOnce(() =>
|
||||
Promise.resolve(ok(asArtistsJson([artist])))
|
||||
)
|
||||
.mockImplementationOnce(
|
||||
() =>
|
||||
// album1 never played
|
||||
Promise.resolve(ok(getAlbumListJson([[artist, album2]])))
|
||||
// album3 never played
|
||||
);
|
||||
});
|
||||
|
||||
it("should pass the filter to navidrome", async () => {
|
||||
const q: AlbumQuery = { _index: 0, _count: 100, type: "starred" };
|
||||
const result = await navidrome
|
||||
.generateToken({ username, password })
|
||||
.then((it) => it as AuthSuccess)
|
||||
.then((it) => navidrome.login(it.authToken))
|
||||
.then((it) => it.albums(q));
|
||||
|
||||
expect(result).toEqual({
|
||||
results: [album2].map(albumToAlbumSummary),
|
||||
total: 1,
|
||||
});
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtists`, {
|
||||
params: asURLSearchParams(authParamsPlusJson),
|
||||
headers,
|
||||
});
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
|
||||
params: asURLSearchParams({
|
||||
...authParamsPlusJson,
|
||||
type: "highest",
|
||||
size: 500,
|
||||
offset: 0,
|
||||
}),
|
||||
headers,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the artist has only 1 album", () => {
|
||||
|
||||
Reference in New Issue
Block a user