mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
test(share): tests for stream downloads and ShareInfo.Description
This commit is contained in:
parent
68cc46242c
commit
2a9358b4d0
@ -192,3 +192,52 @@ var _ = Describe("handleStream", func() {
|
||||
Expect(w.Code).To(Equal(http.StatusBadRequest))
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("sanitizeName", func() {
|
||||
It("leaves a plain string unchanged", func() {
|
||||
Expect(sanitizeName("Artist Name")).To(Equal("Artist Name"))
|
||||
})
|
||||
|
||||
It("replaces a single slash with an underscore", func() {
|
||||
Expect(sanitizeName("AC/DC")).To(Equal("AC_DC"))
|
||||
})
|
||||
|
||||
It("replaces multiple slashes with underscores", func() {
|
||||
Expect(sanitizeName("a/b/c")).To(Equal("a_b_c"))
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("downloadFilename", func() {
|
||||
var mf *model.MediaFile
|
||||
|
||||
BeforeEach(func() {
|
||||
mf = &model.MediaFile{
|
||||
Artist: "The Beatles",
|
||||
Title: "Hey Jude",
|
||||
Suffix: "flac",
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
})
|
||||
|
||||
It("uses the media file suffix when format is empty", func() {
|
||||
Expect(downloadFilename(mf, "")).To(Equal("The Beatles - Hey Jude.flac"))
|
||||
})
|
||||
|
||||
It("uses the media file suffix when format is 'raw'", func() {
|
||||
Expect(downloadFilename(mf, "raw")).To(Equal("The Beatles - Hey Jude.flac"))
|
||||
})
|
||||
|
||||
It("uses the format as the extension when a real format is given", func() {
|
||||
Expect(downloadFilename(mf, "mp3")).To(Equal("The Beatles - Hey Jude.mp3"))
|
||||
})
|
||||
|
||||
It("sanitizes slashes in the artist name", func() {
|
||||
mf.Artist = "AC/DC"
|
||||
Expect(downloadFilename(mf, "")).To(Equal("AC_DC - Hey Jude.flac"))
|
||||
})
|
||||
|
||||
It("sanitizes slashes in the title", func() {
|
||||
mf.Title = "Love/Hate"
|
||||
Expect(downloadFilename(mf, "")).To(Equal("The Beatles - Love_Hate.flac"))
|
||||
})
|
||||
})
|
||||
|
||||
@ -312,6 +312,13 @@ var _ = Describe("addShareData", func() {
|
||||
addShareData(r, data, shareInfo)
|
||||
Expect(data["ShareDescription"]).To(Equal(shareInfo.Contents))
|
||||
})
|
||||
It("should use shareInfo.Contents as ShareInfo.Description", func() {
|
||||
addShareData(r, data, shareInfo)
|
||||
var sd shareData
|
||||
err := json.Unmarshal([]byte(data["ShareInfo"].(string)), &sd)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(sd.Description).To(Equal(shareInfo.Contents))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { isLastFmURL } from './urls'
|
||||
import { isLastFmURL, toDownloadUrl } from './urls'
|
||||
|
||||
describe('isLastFmURL', () => {
|
||||
it('returns true for valid Last.fm music URLs', () => {
|
||||
@ -23,3 +23,23 @@ describe('isLastFmURL', () => {
|
||||
expect(isLastFmURL('not-a-url')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('toDownloadUrl', () => {
|
||||
it('appends download=true to an absolute URL', () => {
|
||||
const result = toDownloadUrl('https://example.com/share/s/abc123')
|
||||
expect(new URL(result).searchParams.get('download')).toBe('true')
|
||||
})
|
||||
|
||||
it('appends download=true to a relative URL resolved against window.origin', () => {
|
||||
const result = toDownloadUrl('/share/s/abc123')
|
||||
expect(new URL(result).searchParams.get('download')).toBe('true')
|
||||
expect(new URL(result).pathname).toBe('/share/s/abc123')
|
||||
})
|
||||
|
||||
it('preserves existing query parameters', () => {
|
||||
const result = toDownloadUrl('https://example.com/share/s/abc123?format=mp3')
|
||||
const url = new URL(result)
|
||||
expect(url.searchParams.get('format')).toBe('mp3')
|
||||
expect(url.searchParams.get('download')).toBe('true')
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user