-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1548 from sferra/fix/bandcamp-search-pagination
Fix Bandcamp plugin search aborting after the first page
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { BandcampPlugin } from '.'; | ||
import { Bandcamp } from '../../rest'; | ||
import spyOn = jest.spyOn; | ||
import { BandcampSearchResult } from '../../rest/Bandcamp'; | ||
|
||
describe('Bandcamp plugin tests', () => { | ||
let plugin: BandcampPlugin; | ||
|
||
beforeEach(() => { | ||
plugin = new BandcampPlugin(); | ||
}); | ||
|
||
describe('find track URLs', () => { | ||
const streamQuery = { | ||
artist: 'Artist Name', | ||
track: 'Track Name' | ||
}; | ||
const trackQuery = 'Track Name'; | ||
const bandcampSearch = spyOn(Bandcamp, 'search'); | ||
|
||
afterEach(() => { | ||
bandcampSearch.mockReset(); | ||
}); | ||
|
||
test('finds track', async () => { | ||
const matchingSearchResult: BandcampSearchResult = { | ||
type: 'track', | ||
artist: 'Artist Name', | ||
name: 'Track Name', | ||
url: 'URL', | ||
imageUrl: 'image URL', | ||
tags: [] | ||
}; | ||
bandcampSearch.mockResolvedValueOnce([]) | ||
.mockResolvedValueOnce([]) | ||
.mockResolvedValueOnce([]) | ||
.mockResolvedValueOnce([]) | ||
.mockResolvedValueOnce([matchingSearchResult]); | ||
|
||
await expect(plugin.findTrackUrls(streamQuery)) | ||
.resolves.toEqual([matchingSearchResult]); | ||
|
||
expect(bandcampSearch).toHaveBeenCalledTimes(5); | ||
expect(bandcampSearch).toHaveBeenNthCalledWith(1, trackQuery, 0); | ||
expect(bandcampSearch).toHaveBeenNthCalledWith(2, trackQuery, 1); | ||
expect(bandcampSearch).toHaveBeenNthCalledWith(3, trackQuery, 2); | ||
expect(bandcampSearch).toHaveBeenNthCalledWith(4, trackQuery, 3); | ||
expect(bandcampSearch).toHaveBeenNthCalledWith(5, trackQuery, 4); | ||
}); | ||
|
||
test('doesn\'t find tracks', async () => { | ||
bandcampSearch.mockResolvedValue([]); | ||
|
||
await expect(plugin.findTrackUrls(streamQuery)) | ||
.resolves.toEqual([]); | ||
|
||
expect(bandcampSearch).toHaveBeenCalledTimes(5); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters