Linking Album->Artist so that artist name shows on albumLists

This commit is contained in:
simojenki
2021-04-21 14:35:21 +10:00
parent 9f90f54067
commit a06ae2e18e
8 changed files with 151 additions and 76 deletions

View File

@@ -4,6 +4,7 @@ import { Credentials } from "../src/smapi";
import { Service, Device } from "../src/sonos";
import { Album, Artist, Track, albumToAlbumSummary, artistToArtistSummary } from "../src/music_service";
import randomString from "../src/random_string";
const randomInt = (max: number) => Math.floor(Math.random() * Math.floor(max));
const randomIpAddress = () => `127.0.${randomInt(255)}.${randomInt(255)}`;
@@ -70,7 +71,7 @@ export function someCredentials(token: string): Credentials {
export function anArtist(fields: Partial<Artist> = {}): Artist {
const id = uuid();
return {
const artist = {
id,
name: `Artist ${id}`,
albums: [anAlbum(), anAlbum(), anAlbum()],
@@ -85,6 +86,11 @@ export function anArtist(fields: Partial<Artist> = {}): Artist {
],
...fields,
};
artist.albums.forEach(album => {
album.artistId = artist.id;
album.artistName = artist.name;
})
return artist;
}
export const HIP_HOP = { id: "genre_hip_hop", name: "Hip-Hop" };
@@ -123,25 +129,33 @@ export function anAlbum(fields: Partial<Album> = {}): Album {
name: `Album ${id}`,
genre: randomGenre(),
year: `19${randomInt(99)}`,
artistId: `Artist ${uuid()}`,
artistName: `Artist ${randomString()}`,
...fields,
};
}
export const BLONDIE_ID = uuid();
export const BLONDIE_NAME = "Blondie";
export const BLONDIE: Artist = {
id: uuid(),
name: "Blondie",
id: BLONDIE_ID,
name: BLONDIE_NAME,
albums: [
{
id: uuid(),
name: "Blondie",
year: "1976",
genre: NEW_WAVE,
artistId: BLONDIE_ID,
artistName: BLONDIE_NAME
},
{
id: uuid(),
name: "Parallel Lines",
year: "1978",
genre: POP_ROCK,
artistId: BLONDIE_ID,
artistName: BLONDIE_NAME
},
],
image: {
@@ -152,13 +166,15 @@ export const BLONDIE: Artist = {
similarArtists: [],
};
export const BOB_MARLEY_ID = uuid();
export const BOB_MARLEY_NAME = "Bob Marley";
export const BOB_MARLEY: Artist = {
id: uuid(),
name: "Bob Marley",
id: BOB_MARLEY_ID,
name: BOB_MARLEY_NAME,
albums: [
{ id: uuid(), name: "Burin'", year: "1973", genre: REGGAE },
{ id: uuid(), name: "Exodus", year: "1977", genre: REGGAE },
{ id: uuid(), name: "Kaya", year: "1978", genre: SKA },
{ id: uuid(), name: "Burin'", year: "1973", genre: REGGAE, artistId: BOB_MARLEY_ID, artistName: BOB_MARLEY_NAME },
{ id: uuid(), name: "Exodus", year: "1977", genre: REGGAE, artistId: BOB_MARLEY_ID, artistName: BOB_MARLEY_NAME },
{ id: uuid(), name: "Kaya", year: "1978", genre: SKA, artistId: BOB_MARLEY_ID, artistName: BOB_MARLEY_NAME },
],
image: {
small: "http://localhost/BOB_MARLEY/sml",
@@ -168,9 +184,11 @@ export const BOB_MARLEY: Artist = {
similarArtists: [],
};
export const MADONNA_ID = uuid();
export const MADONNA_NAME = "Madonna";
export const MADONNA: Artist = {
id: uuid(),
name: "Madonna",
id: MADONNA_ID,
name: MADONNA_NAME,
albums: [],
image: {
small: "http://localhost/MADONNA/sml",
@@ -180,21 +198,27 @@ export const MADONNA: Artist = {
similarArtists: [],
};
export const METALLICA_ID = uuid();
export const METALLICA_NAME = "Metallica";
export const METALLICA: Artist = {
id: uuid(),
name: "Metallica",
id: METALLICA_ID,
name: METALLICA_NAME,
albums: [
{
id: uuid(),
name: "Ride the Lightening",
year: "1984",
genre: METAL,
artistId: METALLICA_ID,
artistName: METALLICA_NAME,
},
{
id: uuid(),
name: "Master of Puppets",
year: "1986",
genre: METAL,
artistId: METALLICA_ID,
artistName: METALLICA_NAME,
},
],
image: {

View File

@@ -1374,26 +1374,24 @@ describe("Navidrome", () => {
const tripHop = asGenre("Trip-Hop");
const album = anAlbum({ id: "album1", name: "Burnin", genre: hipHop });
const albumSummary = albumToAlbumSummary(album);
const artist = anArtist({
id: "artist1",
name: "Bob Marley",
albums: [album],
});
const artistSummary = artistToArtistSummary(artist);
const tracks = [
aTrack({ artist: artistSummary, album: albumSummary, genre: hipHop }),
aTrack({ artist: artistSummary, album: albumSummary, genre: hipHop }),
aTrack({ artist: artistToArtistSummary(artist), album: albumToAlbumSummary(album), genre: hipHop }),
aTrack({ artist: artistToArtistSummary(artist), album: albumToAlbumSummary(album), genre: hipHop }),
aTrack({
artist: artistSummary,
album: albumSummary,
artist: artistToArtistSummary(artist),
album: albumToAlbumSummary(album),
genre: tripHop,
}),
aTrack({
artist: artistSummary,
album: albumSummary,
artist: artistToArtistSummary(artist),
album: albumToAlbumSummary(album),
genre: tripHop,
}),
];
@@ -1433,19 +1431,17 @@ describe("Navidrome", () => {
name: "Burnin",
genre: flipFlop,
});
const albumSummary = albumToAlbumSummary(album);
const artist = anArtist({
id: "artist1",
name: "Bob Marley",
albums: [album],
});
const artistSummary = artistToArtistSummary(artist);
const tracks = [
aTrack({
artist: artistSummary,
album: albumSummary,
artist: artistToArtistSummary(artist),
album: albumToAlbumSummary(album),
genre: flipFlop,
}),
];
@@ -1520,18 +1516,16 @@ describe("Navidrome", () => {
const pop = asGenre("Pop");
const album = anAlbum({ id: "album1", name: "Burnin", genre: pop });
const albumSummary = albumToAlbumSummary(album);
const artist = anArtist({
id: "artist1",
name: "Bob Marley",
albums: [album],
});
const artistSummary = artistToArtistSummary(artist);
const track = aTrack({
artist: artistSummary,
album: albumSummary,
artist: artistToArtistSummary(artist),
album: albumToAlbumSummary(album),
genre: pop,
});
@@ -2730,11 +2724,11 @@ describe("Navidrome", () => {
describe("searchAlbums", () => {
describe("when there is 1 search results", () => {
it("should return true", async () => {
const artist = anArtist({ name: "#1" });
const album = anAlbum({
name: "foo woo",
genre: { id: "pop", name: "pop" },
});
const artist = anArtist({ name: "#1", albums:[album] });
mockGET
.mockImplementationOnce(() => Promise.resolve(ok(PING_OK)))
@@ -2765,17 +2759,17 @@ describe("Navidrome", () => {
describe("when there are many search results", () => {
it("should return true", async () => {
const artist1 = anArtist({ name: "artist1" });
const album1 = anAlbum({
name: "album1",
genre: { id: "pop", name: "pop" },
});
const artist1 = anArtist({ name: "artist1", albums: [album1] });
const artist2 = anArtist({ name: "artist2" });
const album2 = anAlbum({
name: "album2",
genre: { id: "pop", name: "pop" },
});
const artist2 = anArtist({ name: "artist2", albums: [album2] });
mockGET
.mockImplementationOnce(() => Promise.resolve(ok(PING_OK)))

View File

@@ -241,6 +241,8 @@ describe("album", () => {
title: someAlbum.name,
albumArtURI: defaultAlbumArtURI(webAddress, accessToken, someAlbum),
canPlay: true,
artist: someAlbum.artistName,
artistId: someAlbum.artistId
});
});
});
@@ -633,7 +635,7 @@ describe("api", () => {
musicLibrary.searchTracks.mockResolvedValue([track1, track2]);
});
it.only("should return the tracks", async () => {
it("should return the tracks", async () => {
const term = "whoopie";
const result = await ws.searchAsync({
@@ -642,7 +644,15 @@ describe("api", () => {
});
expect(result[0]).toEqual(
searchResult({
mediaCollection: tracks.map((it) => track(rootUrl, accessToken, it)),
mediaCollection: tracks.map((it) => {
const t = track(rootUrl, accessToken, it) as any;
t.trackMetadata = {
...t.trackMetadata,
duration: `${t.trackMetadata.duration}`,
trackNumber: `${t.trackMetadata.trackNumber}`,
}
return t;
}),
index: 0,
total: 2,
})
@@ -722,30 +732,30 @@ describe("api", () => {
getMetadataResult({
mediaCollection: [
{ itemType: "container", id: "artists", title: "Artists" },
{ itemType: "container", id: "albums", title: "Albums" },
{ itemType: "albumList", id: "albums", title: "Albums" },
{ itemType: "container", id: "genres", title: "Genres" },
{
itemType: "container",
itemType: "albumList",
id: "randomAlbums",
title: "Random",
},
{
itemType: "container",
itemType: "albumList",
id: "starredAlbums",
title: "Starred",
},
{
itemType: "container",
itemType: "albumList",
id: "recentlyAdded",
title: "Recently Added",
},
{
itemType: "container",
itemType: "albumList",
id: "recentlyPlayed",
title: "Recently Played",
},
{
itemType: "container",
itemType: "albumList",
id: "mostPlayed",
title: "Most Played",
},
@@ -853,6 +863,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: artistWithManyAlbums.albums.length,
@@ -884,6 +896,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 2,
total: artistWithManyAlbums.albums.length,
@@ -1137,6 +1151,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: 6,
@@ -1180,6 +1196,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: 6,
@@ -1223,6 +1241,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: 6,
@@ -1266,6 +1286,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: 6,
@@ -1309,6 +1331,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: 6,
@@ -1350,6 +1374,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: 6,
@@ -1391,6 +1417,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 2,
total: 6,
@@ -1430,6 +1458,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: 4,
@@ -1472,6 +1502,8 @@ describe("api", () => {
title: it.name,
albumArtURI: defaultAlbumArtURI(rootUrl, accessToken, it),
canPlay: true,
artistId: it.artistId,
artist: it.artistName
})),
index: 0,
total: 4,