1
0

feat: subsonic getAlbum/getRecentAlbums and stream url builder

This commit is contained in:
2026-09-03 20:53:49 +02:00
parent 3bdbd8315c
commit 9d1291b58f
2 changed files with 106 additions and 0 deletions

View File

@@ -118,4 +118,76 @@ describe('SubsonicClient', () => {
{ id: '2', title: 'Album 2', artist: 'Artist 0' },
])
})
it('url() builds a raw endpoint URL with auth params', () => {
const c = new SubsonicClient({
url: 'http://navidrome.local',
username: 'sam',
password: 'pass',
fetchImpl: (async () => subsonicResponse({})) as typeof fetch,
})
const u = new URL(c.url('stream', { id: 'song-9' }))
expect(u.pathname).toBe('/rest/stream')
expect(u.searchParams.get('id')).toBe('song-9')
expect(u.searchParams.get('u')).toBe('sam')
expect(u.searchParams.get('f')).toBe('json')
})
it('getAlbum returns ordered tracks', async () => {
const c = new SubsonicClient({
url: 'http://x',
username: 'sam',
password: 'pass',
fetchImpl: (async () =>
subsonicResponse({
'subsonic-response': {
status: 'ok',
album: {
id: 'alb-1',
name: 'Motion',
artist: 'The Cinematic Orchestra',
song: [
{ id: 's2', title: 'Theme de Yoyo', duration: 300, track: 2 },
{ id: 's1', title: 'Overture', duration: 200, track: 1 },
],
},
},
})) as typeof fetch,
})
const album = await c.getAlbum('alb-1')
expect(album).toEqual({
id: 'alb-1',
title: 'Motion',
artist: 'The Cinematic Orchestra',
tracks: [
{ id: 's1', title: 'Overture', duration: 200, track: 1 },
{ id: 's2', title: 'Theme de Yoyo', duration: 300, track: 2 },
],
})
})
it('getRecentAlbums returns the recent list raw', async () => {
const c = new SubsonicClient({
url: 'http://x',
username: 'sam',
password: 'pass',
fetchImpl: (async () =>
subsonicResponse({
'subsonic-response': {
status: 'ok',
albumList2: {
album: [
{ id: 'a1', name: 'Motion', artist: 'TCO', played: '2026-09-01T10:00:00Z' },
{ id: 'a2', name: 'Blue Lines', artist: 'Massive Attack' },
],
},
},
})) as typeof fetch,
})
const recent = await c.getRecentAlbums(500)
expect(recent).toEqual([
{ id: 'a1', title: 'Motion', artist: 'TCO', playedAt: '2026-09-01T10:00:00Z' },
{ id: 'a2', title: 'Blue Lines', artist: 'Massive Attack', playedAt: null },
])
})
})