mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Remove tracks function, replace with just getting album
This commit is contained in:
@@ -55,7 +55,6 @@ import {
|
||||
ROCK,
|
||||
aRadioStation,
|
||||
anAlbumSummary,
|
||||
anArtistSummary
|
||||
} from "./builders";
|
||||
import { b64Encode } from "../src/b64";
|
||||
import { BUrn } from "../src/burn";
|
||||
@@ -2592,332 +2591,7 @@ describe("SubsonicMusicLibrary", () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("getting tracks", () => {
|
||||
describe("for an album", () => {
|
||||
describe("when there are no custom players", () => {
|
||||
beforeEach(() => {
|
||||
customPlayers.encodingFor.mockReturnValue(O.none);
|
||||
});
|
||||
|
||||
describe("when the album has multiple tracks, some of which are rated", () => {
|
||||
const hipHop = asGenre("Hip-Hop");
|
||||
const tripHop = asGenre("Trip-Hop");
|
||||
|
||||
const albumSummary = anAlbumSummary({
|
||||
id: "album1",
|
||||
name: "Burnin",
|
||||
genre: hipHop,
|
||||
});
|
||||
|
||||
const artistSummary = anArtistSummary({
|
||||
id: "artist1",
|
||||
name: "Bob Marley"
|
||||
});
|
||||
|
||||
const track1 = aTrack({
|
||||
artist: artistSummary,
|
||||
album: albumSummary,
|
||||
genre: hipHop,
|
||||
rating: {
|
||||
love: true,
|
||||
stars: 3,
|
||||
},
|
||||
});
|
||||
const track2 = aTrack({
|
||||
artist: artistSummary,
|
||||
album: albumSummary,
|
||||
genre: hipHop,
|
||||
rating: {
|
||||
love: false,
|
||||
stars: 0,
|
||||
},
|
||||
});
|
||||
const track3 = aTrack({
|
||||
artist: artistSummary,
|
||||
album: albumSummary,
|
||||
genre: tripHop,
|
||||
rating: {
|
||||
love: true,
|
||||
stars: 5,
|
||||
},
|
||||
});
|
||||
const track4 = aTrack({
|
||||
artist: artistSummary,
|
||||
album: albumSummary,
|
||||
genre: tripHop,
|
||||
rating: {
|
||||
love: false,
|
||||
stars: 1,
|
||||
},
|
||||
});
|
||||
|
||||
const album = anAlbum({
|
||||
...albumSummary,
|
||||
tracks: [track1, track2, track3, track4]
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
mockGET.mockImplementationOnce(() =>
|
||||
Promise.resolve(ok(getAlbumJson(album)))
|
||||
);
|
||||
});
|
||||
|
||||
it("should return the album", async () => {
|
||||
const result = await subsonic.tracks(album.id);
|
||||
|
||||
// todo: not this
|
||||
const blatRating = (t: Track) => ({
|
||||
...t,
|
||||
rating: {
|
||||
love: false,
|
||||
stars: 0
|
||||
}
|
||||
})
|
||||
|
||||
expect(result).toEqual([
|
||||
blatRating(track1),
|
||||
blatRating(track2),
|
||||
blatRating(track3),
|
||||
blatRating(track4),
|
||||
]);
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith(
|
||||
url.append({ pathname: "/rest/getAlbum" }).href(),
|
||||
{
|
||||
params: asURLSearchParams({
|
||||
...authParamsPlusJson,
|
||||
id: album.id,
|
||||
}),
|
||||
headers,
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the album has only 1 track", () => {
|
||||
// todo: why do i care about the genre in here?
|
||||
const flipFlop = asGenre("Flip-Flop");
|
||||
|
||||
const albumSummary = anAlbumSummary({
|
||||
id: "album1",
|
||||
name: "Burnin",
|
||||
genre: flipFlop,
|
||||
});
|
||||
|
||||
const artistSummary = anArtistSummary({
|
||||
id: "artist1",
|
||||
name: "Bob Marley"
|
||||
});
|
||||
|
||||
const track = aTrack({
|
||||
artist: artistSummary,
|
||||
album: albumSummary,
|
||||
genre: flipFlop,
|
||||
});
|
||||
|
||||
const album = anAlbum({
|
||||
...albumSummary,
|
||||
tracks: [track]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
mockGET.mockImplementationOnce(() =>
|
||||
Promise.resolve(ok(getAlbumJson(album)))
|
||||
);
|
||||
});
|
||||
|
||||
it("should return the album", async () => {
|
||||
const result = await subsonic.tracks(album.id);
|
||||
|
||||
expect(result).toEqual([{
|
||||
...track,
|
||||
// todo: not sure about this
|
||||
rating: {
|
||||
love: false,
|
||||
stars: 0
|
||||
}
|
||||
}]);
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith(
|
||||
url.append({ pathname: "/rest/getAlbum" }).href(),
|
||||
{
|
||||
params: asURLSearchParams({
|
||||
...authParamsPlusJson,
|
||||
id: album.id,
|
||||
}),
|
||||
headers,
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the album has no tracks", () => {
|
||||
const album = anAlbum({
|
||||
tracks: []
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
mockGET.mockImplementationOnce(() =>
|
||||
Promise.resolve(ok(getAlbumJson(album)))
|
||||
);
|
||||
});
|
||||
|
||||
it("should empty array", async () => {
|
||||
const result = await subsonic.tracks(album.id);
|
||||
|
||||
expect(result).toEqual([]);
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith(
|
||||
url.append({ pathname: "/rest/getAlbum" }).href(),
|
||||
{
|
||||
params: asURLSearchParams({
|
||||
...authParamsPlusJson,
|
||||
id: album.id,
|
||||
}),
|
||||
headers,
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when a custom player is configured for the mime type", () => {
|
||||
const hipHop = asGenre("Hip-Hop");
|
||||
const tripHop = asGenre("Trip-Hop");
|
||||
|
||||
const albumSummary = anAlbumSummary({ id: "album1", name: "Burnin", genre: hipHop });
|
||||
|
||||
const artistSummary = anArtistSummary({
|
||||
id: "artist1",
|
||||
name: "Bob Marley"
|
||||
});
|
||||
|
||||
const alac = aTrack({
|
||||
artist: artistSummary,
|
||||
album: albumSummary,
|
||||
encoding: {
|
||||
player: "bonob",
|
||||
mimeType: "audio/alac",
|
||||
},
|
||||
genre: hipHop,
|
||||
rating: {
|
||||
love: true,
|
||||
stars: 3,
|
||||
},
|
||||
});
|
||||
const m4a = aTrack({
|
||||
artist: artistSummary,
|
||||
album: albumSummary,
|
||||
encoding: {
|
||||
player: "bonob",
|
||||
mimeType: "audio/m4a",
|
||||
},
|
||||
genre: hipHop,
|
||||
rating: {
|
||||
love: false,
|
||||
stars: 0,
|
||||
},
|
||||
});
|
||||
const mp3 = aTrack({
|
||||
artist: artistSummary,
|
||||
album: albumSummary,
|
||||
encoding: {
|
||||
player: "bonob",
|
||||
mimeType: "audio/mp3",
|
||||
},
|
||||
genre: tripHop,
|
||||
rating: {
|
||||
love: true,
|
||||
stars: 5,
|
||||
},
|
||||
});
|
||||
|
||||
const album = anAlbum({
|
||||
...albumSummary,
|
||||
tracks: [alac, m4a, mp3]
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
customPlayers.encodingFor
|
||||
.mockReturnValueOnce(
|
||||
O.of({ player: "bonob+audio/alac", mimeType: "audio/flac" })
|
||||
)
|
||||
.mockReturnValueOnce(
|
||||
O.of({ player: "bonob+audio/m4a", mimeType: "audio/opus" })
|
||||
)
|
||||
.mockReturnValueOnce(O.none);
|
||||
|
||||
mockGET.mockImplementationOnce(() =>
|
||||
Promise.resolve(ok(getAlbumJson(album)))
|
||||
);
|
||||
});
|
||||
|
||||
it("should return the album with custom players applied", async () => {
|
||||
const result = await subsonic.tracks(album.id);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
...alac,
|
||||
encoding: {
|
||||
player: "bonob+audio/alac",
|
||||
mimeType: "audio/flac",
|
||||
},
|
||||
// todo: this doesnt seem right? why dont the ratings come back?
|
||||
rating: {
|
||||
love: false,
|
||||
stars: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
...m4a,
|
||||
encoding: {
|
||||
player: "bonob+audio/m4a",
|
||||
mimeType: "audio/opus",
|
||||
},
|
||||
rating: {
|
||||
love: false,
|
||||
stars: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
...mp3,
|
||||
encoding: {
|
||||
player: "bonob",
|
||||
mimeType: "audio/mp3",
|
||||
},
|
||||
rating: {
|
||||
love: false,
|
||||
stars: 0
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith(
|
||||
url.append({ pathname: "/rest/getAlbum" }).href(),
|
||||
{
|
||||
params: asURLSearchParams({
|
||||
...authParamsPlusJson,
|
||||
id: album.id,
|
||||
}),
|
||||
headers,
|
||||
}
|
||||
);
|
||||
|
||||
expect(customPlayers.encodingFor).toHaveBeenCalledTimes(3);
|
||||
expect(customPlayers.encodingFor).toHaveBeenNthCalledWith(1, {
|
||||
mimeType: "audio/alac",
|
||||
});
|
||||
expect(customPlayers.encodingFor).toHaveBeenNthCalledWith(2, {
|
||||
mimeType: "audio/m4a",
|
||||
});
|
||||
expect(customPlayers.encodingFor).toHaveBeenNthCalledWith(3, {
|
||||
mimeType: "audio/mp3",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("a single track", () => {
|
||||
const pop = asGenre("Pop");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user