2022-06-10 10:47:46 +00:00
|
|
|
import { favoriteStore } from '@/stores'
|
2022-05-13 17:58:38 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { downloadService } from './downloadService'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
2024-06-02 17:15:31 +00:00
|
|
|
it('downloads playables', () => {
|
2022-05-13 17:58:38 +00:00
|
|
|
const mock = this.mock(downloadService, 'trigger')
|
2024-06-01 18:02:27 +00:00
|
|
|
downloadService.fromPlayables([factory('song', { id: 'bar' })])
|
2022-05-13 17:58:38 +00:00
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
expect(mock).toHaveBeenCalledWith('songs?songs[]=bar&')
|
2022-05-13 17:58:38 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('downloads all by artist', () => {
|
|
|
|
const mock = this.mock(downloadService, 'trigger')
|
2024-06-01 18:02:27 +00:00
|
|
|
downloadService.fromArtist(factory('artist', { id: 42 }))
|
2022-05-13 17:58:38 +00:00
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith('artist/42')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('downloads all in album', () => {
|
|
|
|
const mock = this.mock(downloadService, 'trigger')
|
2024-06-01 18:02:27 +00:00
|
|
|
downloadService.fromAlbum(factory('album', { id: 42 }))
|
2022-05-13 17:58:38 +00:00
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith('album/42')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('downloads a playlist', () => {
|
|
|
|
const mock = this.mock(downloadService, 'trigger')
|
2024-06-01 18:02:27 +00:00
|
|
|
const playlist = factory('playlist')
|
2022-05-13 17:58:38 +00:00
|
|
|
|
|
|
|
downloadService.fromPlaylist(playlist)
|
|
|
|
|
2024-02-25 09:38:55 +00:00
|
|
|
expect(mock).toHaveBeenCalledWith(`playlist/${playlist.id}`)
|
2022-05-13 17:58:38 +00:00
|
|
|
})
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
it.each<[Playable[], boolean]>([[[], false], [factory('song', 5), true]])(
|
2022-05-13 17:58:38 +00:00
|
|
|
'downloads favorites if available',
|
|
|
|
(songs, triggered) => {
|
|
|
|
const mock = this.mock(downloadService, 'trigger')
|
2024-06-02 17:15:31 +00:00
|
|
|
favoriteStore.state.playables = songs
|
2022-05-13 17:58:38 +00:00
|
|
|
|
|
|
|
downloadService.fromFavorites()
|
|
|
|
|
|
|
|
triggered ? expect(mock).toHaveBeenCalledWith('favorites') : expect(mock).not.toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|