From efe4b4238b501f74fdef49e3583ed277a81a00fd Mon Sep 17 00:00:00 2001 From: simojenki Date: Fri, 9 Apr 2021 10:01:57 +1000 Subject: [PATCH] Add most recently played --- src/smapi.ts | 11 +++++++++- tests/smapi.test.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/smapi.ts b/src/smapi.ts index 82ba81c..4588138 100644 --- a/src/smapi.ts +++ b/src/smapi.ts @@ -427,9 +427,13 @@ function bindSmapiSoapServiceToExpress( id: "recentlyPlayed", title: "Recently Played", }), + container({ + id: "mostPlayed", + title: "Most Played", + }), ], index: 0, - total: 6, + total: 7, }); case "artists": return musicLibrary.artists(paging).then((result) => { @@ -464,6 +468,11 @@ function bindSmapiSoapServiceToExpress( ...paging, }); case "recentlyPlayed": + return albums({ + type: "recent", + ...paging, + }); + case "mostPlayed": return albums({ type: "frequent", ...paging, diff --git a/tests/smapi.test.ts b/tests/smapi.test.ts index 266b0bc..2e73182 100644 --- a/tests/smapi.test.ts +++ b/tests/smapi.test.ts @@ -552,9 +552,14 @@ describe("api", () => { id: "recentlyPlayed", title: "Recently Played", }, + { + itemType: "container", + id: "mostPlayed", + title: "Most Played", + }, ], index: 0, - total: 6, + total: 7, }) ); }); @@ -968,6 +973,49 @@ describe("api", () => { }) ); + expect(musicLibrary.albums).toHaveBeenCalledWith({ + type: "recent", + _index: paging.index, + _count: paging.count, + }); + }); + }); + + describe("asking for most played albums", () => { + const mostPlayed = [rock2, rock1, pop2]; + + beforeEach(() => { + musicLibrary.albums.mockResolvedValue({ + results: mostPlayed, + total: allAlbums.length, + }); + }); + + it("should return some", async () => { + const paging = { + index: 0, + count: 100, + }; + + const result = await ws.getMetadataAsync({ + id: "mostPlayed", + ...paging, + }); + + expect(result[0]).toEqual( + getMetadataResult({ + mediaCollection: mostPlayed.map((it) => ({ + itemType: "album", + id: `album:${it.id}`, + title: it.name, + albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it), + canPlay: true, + })), + index: 0, + total: 6, + }) + ); + expect(musicLibrary.albums).toHaveBeenCalledWith({ type: "frequent", _index: paging.index,