diff --git a/src/music_service.ts b/src/music_service.ts index 6c33dcb..09416f2 100644 --- a/src/music_service.ts +++ b/src/music_service.ts @@ -99,7 +99,7 @@ export const asResult = ([results, total]: [T[], number]) => ({ export type ArtistQuery = Paging; -export type AlbumQueryType = 'alphabeticalByArtist' | 'byGenre' | 'random' | 'recent' | 'frequent' | 'newest' | 'starred'; +export type AlbumQueryType = 'alphabeticalByArtist' | 'alphabeticalByName' | 'byGenre' | 'random' | 'recent' | 'frequent' | 'newest' | 'starred'; export type AlbumQuery = Paging & { type: AlbumQueryType; diff --git a/src/smapi.ts b/src/smapi.ts index f13182b..e39399e 100644 --- a/src/smapi.ts +++ b/src/smapi.ts @@ -632,7 +632,7 @@ function bindSmapiSoapServiceToExpress( }); case "albums": { return albums({ - type: "alphabeticalByArtist", + type: "alphabeticalByName", ...paging, }); } diff --git a/tests/in_memory_music_service.test.ts b/tests/in_memory_music_service.test.ts index 64221af..ad90c08 100644 --- a/tests/in_memory_music_service.test.ts +++ b/tests/in_memory_music_service.test.ts @@ -16,6 +16,7 @@ import { HIP_HOP, SKA, } from "./builders"; +import _ from "underscore"; describe("InMemoryMusicService", () => { const service = new InMemoryMusicService(); @@ -210,6 +211,7 @@ describe("InMemoryMusicService", () => { const artist3_album2 = anAlbum({ genre: POP }); const artist1 = anArtist({ + name: "artist1", albums: [ artist1_album1, artist1_album2, @@ -218,8 +220,8 @@ describe("InMemoryMusicService", () => { artist1_album5, ], }); - const artist2 = anArtist({ albums: [artist2_album1] }); - const artist3 = anArtist({ albums: [artist3_album1, artist3_album2] }); + const artist2 = anArtist({ name: "artist2", albums: [artist2_album1] }); + const artist3 = anArtist({ name: "artist3", albums: [artist3_album1, artist3_album2] }); const artistWithNoAlbums = anArtist({ albums: [] }); const allAlbums = [artist1, artist2, artist3, artistWithNoAlbums].flatMap( @@ -265,29 +267,48 @@ describe("InMemoryMusicService", () => { describe("fetching multiple albums", () => { describe("with no filtering", () => { describe("fetching all on one page", () => { - it("should return all the albums for all the artists", async () => { - expect( - await musicLibrary.albums({ - _index: 0, - _count: 100, - type: "alphabeticalByArtist", - }) - ).toEqual({ - results: [ - albumToAlbumSummary(artist1_album1), - albumToAlbumSummary(artist1_album2), - albumToAlbumSummary(artist1_album3), - albumToAlbumSummary(artist1_album4), - albumToAlbumSummary(artist1_album5), - - albumToAlbumSummary(artist2_album1), - - albumToAlbumSummary(artist3_album1), - albumToAlbumSummary(artist3_album2), - ], - total: totalAlbumCount, + describe("alphabeticalByArtist", () => { + it("should return all the albums for all the artists", async () => { + expect( + await musicLibrary.albums({ + _index: 0, + _count: 100, + type: "alphabeticalByArtist", + }) + ).toEqual({ + results: [ + albumToAlbumSummary(artist1_album1), + albumToAlbumSummary(artist1_album2), + albumToAlbumSummary(artist1_album3), + albumToAlbumSummary(artist1_album4), + albumToAlbumSummary(artist1_album5), + + albumToAlbumSummary(artist2_album1), + + albumToAlbumSummary(artist3_album1), + albumToAlbumSummary(artist3_album2), + ], + total: totalAlbumCount, + }); }); }); + + describe("alphabeticalByName", () => { + it("should return all the albums for all the artists", async () => { + expect( + await musicLibrary.albums({ + _index: 0, + _count: 100, + type: "alphabeticalByName", + }) + ).toEqual({ + results: + _.sortBy(allAlbums, 'name').map(albumToAlbumSummary), + total: totalAlbumCount, + }); + }); + }); + }); describe("fetching a page", () => { diff --git a/tests/in_memory_music_service.ts b/tests/in_memory_music_service.ts index 5039790..3bab52d 100644 --- a/tests/in_memory_music_service.ts +++ b/tests/in_memory_music_service.ts @@ -77,7 +77,9 @@ export class InMemoryMusicService implements MusicService { switch (q.type) { case "alphabeticalByArtist": return artist2Album; - case "byGenre": + case "alphabeticalByName": + return artist2Album.sort((a, b) => a.album.name.localeCompare(b.album.name)); + case "byGenre": return artist2Album.filter( (it) => it.album.genre?.id === q.genre ); diff --git a/tests/scenarios.test.ts b/tests/scenarios.test.ts index 81e6697..cc2fc0f 100644 --- a/tests/scenarios.test.ts +++ b/tests/scenarios.test.ts @@ -245,7 +245,7 @@ describe("scenarios", () => { ...BLONDIE.albums, ...BOB_MARLEY.albums, ...MADONNA.albums, - ].map((it) => it.name) + ].map((it) => it.name).sort() ) ); }); diff --git a/tests/smapi.test.ts b/tests/smapi.test.ts index ad1e17a..de65763 100644 --- a/tests/smapi.test.ts +++ b/tests/smapi.test.ts @@ -1576,7 +1576,7 @@ describe("api", () => { ); expect(musicLibrary.albums).toHaveBeenCalledWith({ - type: "alphabeticalByArtist", + type: "alphabeticalByName", _index: paging.index, _count: paging.count, }); @@ -1622,7 +1622,7 @@ describe("api", () => { ); expect(musicLibrary.albums).toHaveBeenCalledWith({ - type: "alphabeticalByArtist", + type: "alphabeticalByName", _index: paging.index, _count: paging.count, });